public function __construct() { parent::__construct(); $this->prependSiteTitle(lang('Recover log in')); if ($this->isPostBack()) { $this->post->email->addValidation(new ValidateInputNotNullOrEmpty()); if (!$this->hasErrors()) { $user = ModelUser::getByUsername($this->input('email')); if (!$user->hasRow()) { $this->setMessage('No user found', 'warning'); response()->refresh(); } if (!$this->hasErrors()) { $reset = new UserReset($user->id); $reset->save(); // TODO: Move this shit to seperate html template $text = "Dear customer!\n\nYou are receiving this mail, because you (or someone else) has requested a password reset for your user on NinjaImg.com.\n\nTo continue with the password reset, please click the link below to confirm the reset:\n\n" . sprintf('https://%s/reset/%s', $_SERVER['HTTP_HOST'], $reset->key) . "\n\nIf you have any questions, feel free to contact us any time.\n\nKind regards,\nThe NinjaImg Team"; $transport = \Swift_SendmailTransport::newInstance(env('MAIL_TRANSPORT') . ' -bs'); $swift = \Swift_Mailer::newInstance($transport); $message = new \Swift_Message(lang('Confirm password reset on NinjaImg')); $message->setFrom(env('MAIL_FROM')); $message->setSender(env('MAIL_FROM')); $message->setReplyTo(env('MAIL_FROM')); $message->setBody($text, 'text/plain'); $message->setTo($user->username); $swift->send($message); $this->setMessage('A password reset link has been sent to your e-mail', 'success'); // Send mail to user confirming reset... // Maybe show message with text that are active even when session disappear response()->refresh(); } } } }
public function __construct($key) { parent::__construct(); $newPassword = uniqid(); $reset = \Pecee\Model\User\UserReset::confirm($key, $newPassword); if ($reset) { $user = ModelUser::getById($reset); if ($user->hasRow()) { // Send mail with new password // TODO: Move this shit to separate html template $user->setEmailConfirmed(true); $user->update(); $text = "Dear customer!\n\nWe've reset your password - you can login with your e-mail and the new password provided below:\nNew password: "******"\n\nIf you have any questions, feel free to contact us any time.\n\nKind regards,\nThe NinjaImg Team"; $transport = \Swift_SendmailTransport::newInstance(env('MAIL_TRANSPORT') . ' -bs'); $swift = \Swift_Mailer::newInstance($transport); $message = new \Swift_Message(lang('New password for NinjaImg')); $message->setFrom(env('MAIL_FROM')); $message->setSender(env('MAIL_FROM')); $message->setReplyTo(env('MAIL_FROM')); $message->setBody($text, 'text/plain'); $message->setTo($user->username); $swift->send($message); $this->setMessage('A new password has been sent to your e-mail.', 'success'); redirect(url('user.login')); } redirect(url('home')); } }