Skip to content

Instantly share code, notes, and snippets.

@sineld
Created August 30, 2012 07:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sineld/3523742 to your computer and use it in GitHub Desktop.
Save sineld/3523742 to your computer and use it in GitHub Desktop.
Sentry Bundle Reset Password
<?php
// Forked from: http://paste.laravel.com/4iV
public function get_reset_password()
{
// render the reset password view
return View::make('auth.reset-password');
}
public function post_reset_password()
{
// data posted from login form
$input = Input::all();
// validate the data
$rules = array(
'email' => 'required|email',
'new-password' => 'required|min:6',
);
$validation = Validator::make($input, $rules);
if ($validation->fails()) {
return Redirect::back()->with_input()->with_errors($validation);
} else {
// reset the user password
try {
// reset the password
$reset = Sentry::reset_password(Input::get('email'), Input::get('new-password'));
if ($reset) {
$email = $reset['email'];
$link = URL::to('auth/reset_password_confirm/').$reset['link']; // adjust path as needed
$name = Sentry::user($email)->get('metadata.first_name');
// email $link to $email
$message = Message::to($email)
->from('info@kencell.com', 'Kencell')
->subject('Kencell - reset your password')
->body("Hi $name,\n\nYou have requested to reset your password. Your password won't change until you click on the link below.\n\n$link\n\nOnce your new password is confirmed, you can log in at www.kencell.com/auth/login using your email address $email and the new password.\n\nIf you didn't make this password reset request, please ignore this email.\n\nBest Regards,\n\nKencell Team\nwww.kencell.com")
->send();
if ($message->was_sent())
{
return 'Your password has been reset. Please check your email to confirm your new password.';
}
} else {
// password was not reset
return "There was a problem resetting your password. Please try again.";
}
} catch (Sentry\SentryException $e) {
// issue activating the user
// store/set and display caught exceptions such as a user not existing or user is disabled
$errors = $e->getMessage();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment