Created
July 23, 2012 09:52
-
-
Save anonymous/3162873 to your computer and use it in GitHub Desktop.
Method from Class Forgot_password
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function action_proceed() | |
{ | |
$email = $this->request->post('email'); | |
if (!Security::check($this->request->post('token'))) { | |
throw new Exception("Bad token!"); | |
} | |
if ($email !== Model_User::email_exists($email)) { | |
throw new Exception("This is not a correct email address"); | |
} | |
$user = new Model_User(); | |
$user_id = $user->get_id($email); | |
$unique_id = new Model_Unique_Id(); | |
$unique_token = $unique_id->set_unique_id(sha1(Pass::salt().Security::token()), $user_id); | |
$unique_id_to_view = $unique_id->get_unique_id($user_id); | |
if (!$unique_id) { | |
$this->request->redirect('login'); | |
} | |
$to = array($email); | |
$from = array('noreply@friends.com', 'Friends.com'); | |
$subject = "Password's recovery"; | |
$view = View::factory('forgot_password/email'); | |
$view->user_id = $user_id; | |
$view->unique_id = $unique_id_to_view; | |
$message = $view->render(); | |
Email::connect(); | |
$send_email = Email::send($to, $from, $subject, $message, $html = true); | |
if (!$send_email) { | |
throw new Exception(" $send_email Email does not sends!"); | |
} | |
$this->request->redirect('forgot_password/ok'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment