2016-02-29 15:59:36 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Contracts\Auth\Guard;
|
|
|
|
|
use Illuminate\Contracts\Auth\PasswordBroker;
|
2016-03-05 00:18:10 +00:00
|
|
|
use Illuminate\Http\Request;
|
2016-02-29 15:59:36 +00:00
|
|
|
|
2016-03-05 00:18:10 +00:00
|
|
|
class RemindersController extends Controller
|
|
|
|
|
{
|
2016-02-29 15:59:36 +00:00
|
|
|
/**
|
|
|
|
|
* The Guard implementation.
|
|
|
|
|
*
|
|
|
|
|
* @var Guard
|
|
|
|
|
*/
|
|
|
|
|
protected $auth;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The password broker implementation.
|
|
|
|
|
*
|
|
|
|
|
* @var PasswordBroker
|
|
|
|
|
*/
|
|
|
|
|
protected $passwords;
|
|
|
|
|
|
2016-03-05 00:18:10 +00:00
|
|
|
public function __construct(Guard $auth, PasswordBroker $passwords)
|
|
|
|
|
{
|
2016-02-29 15:59:36 +00:00
|
|
|
$this->auth = $auth;
|
|
|
|
|
$this->passwords = $passwords;
|
|
|
|
|
|
|
|
|
|
$this->middleware('guest');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2016-03-05 00:18:10 +00:00
|
|
|
* Get the e-mail subject line to be used for the reset link email.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
protected function getEmailSubject()
|
|
|
|
|
{
|
|
|
|
|
return isset($this->subject) ? $this->subject : 'Your Password Reset Link';
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-29 15:59:36 +00:00
|
|
|
/**
|
|
|
|
|
* Display the password reminder view.
|
|
|
|
|
*
|
|
|
|
|
* @return Response
|
|
|
|
|
*/
|
2016-03-05 00:18:10 +00:00
|
|
|
public function getRemind()
|
|
|
|
|
{
|
2016-02-29 15:59:36 +00:00
|
|
|
return \View::make('Public.LoginAndRegister.ForgotPassword');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handle a POST request to remind a user of their password.
|
|
|
|
|
*
|
|
|
|
|
* @return Response
|
|
|
|
|
*/
|
2016-03-05 00:18:10 +00:00
|
|
|
public function postRemind(Request $request)
|
|
|
|
|
{
|
2016-02-29 15:59:36 +00:00
|
|
|
$this->validate($request, ['email' => 'required']);
|
|
|
|
|
|
2016-03-05 00:18:10 +00:00
|
|
|
$response = $this->passwords->sendResetLink($request->only('email'), function ($m) {
|
2016-02-29 15:59:36 +00:00
|
|
|
$m->subject($this->getEmailSubject());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
switch ($response) {
|
|
|
|
|
case PasswordBroker::RESET_LINK_SENT:
|
|
|
|
|
return redirect()->back()->with('status', trans($response));
|
|
|
|
|
|
|
|
|
|
case PasswordBroker::INVALID_USER:
|
|
|
|
|
return redirect()->back()->withErrors(['email' => trans($response)]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Display the password reset view for the given token.
|
|
|
|
|
*
|
2016-03-05 00:18:10 +00:00
|
|
|
* @param string $token
|
|
|
|
|
*
|
2016-02-29 15:59:36 +00:00
|
|
|
* @return Response
|
|
|
|
|
*/
|
2016-03-05 00:18:10 +00:00
|
|
|
public function getReset($token = null)
|
|
|
|
|
{
|
|
|
|
|
if (is_null($token)) {
|
2016-02-29 15:59:36 +00:00
|
|
|
\App::abort(404);
|
2016-03-05 00:18:10 +00:00
|
|
|
}
|
2016-02-29 15:59:36 +00:00
|
|
|
|
|
|
|
|
return \View::make('Public.LoginAndRegister.ResetPassword')->with('token', $token);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handle a POST request to reset a user's password.
|
|
|
|
|
*
|
|
|
|
|
* @return Response
|
|
|
|
|
*/
|
2016-03-05 00:18:10 +00:00
|
|
|
public function postReset(Request $request)
|
|
|
|
|
{
|
2016-02-29 15:59:36 +00:00
|
|
|
$this->validate($request, [
|
2016-03-05 00:18:10 +00:00
|
|
|
'token' => 'required',
|
|
|
|
|
'email' => 'required',
|
2016-02-29 15:59:36 +00:00
|
|
|
'password' => 'required|confirmed',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$credentials = $request->only(
|
2016-06-15 02:31:24 +00:00
|
|
|
'email', 'password', 'password_confirmation', 'token'
|
2016-02-29 15:59:36 +00:00
|
|
|
);
|
|
|
|
|
|
2016-03-05 00:18:10 +00:00
|
|
|
$response = $this->passwords->reset($credentials, function ($user, $password) {
|
2016-02-29 15:59:36 +00:00
|
|
|
$user->password = bcrypt($password);
|
|
|
|
|
|
|
|
|
|
$user->save();
|
|
|
|
|
|
|
|
|
|
$this->auth->login($user);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
switch ($response) {
|
|
|
|
|
case PasswordBroker::PASSWORD_RESET:
|
|
|
|
|
\Session::flash('message', 'Password Successfully Reset');
|
2016-03-05 00:18:10 +00:00
|
|
|
|
2016-02-29 15:59:36 +00:00
|
|
|
return redirect(route('login'));
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return redirect()->back()
|
2016-09-06 20:39:27 +00:00
|
|
|
->withInput($request->only('email'))
|
|
|
|
|
->withErrors(['email' => trans($response)]);
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|