Skip to content

Instantly share code, notes, and snippets.

@herusdianto
Created November 1, 2014 03:07
Show Gist options
  • Save herusdianto/cae33fb47d68b3afdc00 to your computer and use it in GitHub Desktop.
Save herusdianto/cae33fb47d68b3afdc00 to your computer and use it in GitHub Desktop.
Laravel email password reminder dengan subject
<?php
// app/controllers/RemindersController.php
/**
* Class RemindersController
*/
class RemindersController extends SiteController {
/**
* Display the password reminder view.
*
* @return \Illuminate\Http\RedirectResponse
*/
public function getRemind()
{
return View::make('password.remind')
->withTitle('Lupa Password');
}
/**
* Handle a POST request to remind a user of their password.
*
* @return \Illuminate\Http\RedirectResponse
*/
public function postRemind()
{
$response = Password::remind(Input::only('email'), function($message)
{
$message->subject('Reset Password');
});
switch ($response)
{
case Password::INVALID_USER:
Flash::error(Lang::get($response));
return Redirect::back();
case Password::REMINDER_SENT:
Flash::success(Lang::get($response));
return Redirect::back();
}
}
/**
* Display the password reset view for the given token.
*
* @param string $token
*
* @return \Illuminate\Http\RedirectResponse
*/
public function getReset($token = null)
{
if (is_null($token)) App::abort(404);
return View::make('password.reset')
->with('token', $token)
->withTitle('Reset Password');
}
/**
* Handle a POST request to reset a user's password.
*
* @return \Illuminate\Http\RedirectResponse
*/
public function postReset()
{
$credentials = Input::only('email', 'password', 'password_confirmation', 'token');
$response = Password::reset($credentials, function ($user, $password)
{
$user->password = $password;
$user->save();
});
switch ($response)
{
case Password::INVALID_PASSWORD:
case Password::INVALID_TOKEN:
case Password::INVALID_USER:
Flash::error(Lang::get($response));
return Redirect::back();
case Password::PASSWORD_RESET:
Flash::success('Reset password sukses.');
return Redirect::home();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment