<?php
class RemindersController extends Controller {
/**
* Display the password reminder view.
*
* @return Response
*/
public function getRemind()
{
return View::make('password.remind');
}
/**
* Handle a POST request to remind a user of their password.
*
* @return Response
*/
public function postRemind()
{
//validate email entered here
$rules = array(
'email' => 'required|email',
);
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails())
{
return Redirect::to('password/remind')
->withErrors($validator)
->withInput(Input::except('password'));
}else
{
$response = Password::remind(Input::only('email'), function($message)
{
$message->subject('Mentconnect - Password Reminder!');
});
switch ($response)
{
case Password::INVALID_USER:
\Session::flash('message', 'The email you entered does not exist. Try a different email.');
return Redirect::back()->withInput(\Input::except('password'));
case Password::REMINDER_SENT:
\Session::flash('message', 'Please check your email for instructions on how to reset your password');
return Redirect::to('password/remind');
}
}
}
/**
* Display the password reset view for the given token.
*
* @param string $token
* @return Response
*/
public function getReset($token = null)
{
if (is_null($token)) App::abort(404);
return View::make('password.reset')->with('token', $token);
}
/**
* Handle a POST request to reset a user's password.
*
* @return Response
*/
public function postReset()
{
//validate input here
$rules = array(
'email' => 'required|email',
'password' => 'required|confirmed',
'token' => 'required',
);
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails())
{
return Redirect::back()
->withErrors($validator)
->withInput(Input::except('password', 'password_confirmation'));
}
$credentials = Input::only(
'email', 'password', 'password_confirmation', 'token'
);
$response = Password::reset($credentials, function($user, $password)
{
$user->password = Hash::make($password);
$user->save();
});
switch ($response)
{
case Password::INVALID_PASSWORD:
case Password::INVALID_TOKEN:
case Password::INVALID_USER:
\Session::flash('message', 'You have to enter the correct information to proceed');
return Redirect::back()->with('error', Lang::get($response));
case Password::PASSWORD_RESET:
\Session::flash('message', 'You can now login with your new credentials.');
return Redirect::to('login');
}
}
}