Browse Source
- Unified way to use Alert - Added link to restore password to login form - Refactored restore passwordtags/2.0.0-beta
Alexander Makarov
11 years ago
9 changed files with 129 additions and 114 deletions
@ -1,59 +0,0 @@
|
||||
<?php |
||||
|
||||
namespace frontend\models; |
||||
use yii\base\Model; |
||||
use common\models\User; |
||||
use yii\base\View; |
||||
use yii\helpers\Security; |
||||
|
||||
/** |
||||
* SendPasswordResetTokenForm is the model behind requesting password reset token form. |
||||
*/ |
||||
class SendPasswordResetTokenForm extends Model |
||||
{ |
||||
public $email; |
||||
|
||||
/** |
||||
* @return array the validation rules. |
||||
*/ |
||||
public function rules() |
||||
{ |
||||
return array( |
||||
array('email', 'required'), |
||||
array('email', 'email'), |
||||
); |
||||
} |
||||
|
||||
public function sendEmail() |
||||
{ |
||||
if($this->validate()) { |
||||
/** @var User $user */ |
||||
$user = User::find(array( |
||||
'email' => $this->email, |
||||
'status' => User::STATUS_ACTIVE, |
||||
)); |
||||
if ($user) { |
||||
$user->password_reset_token = Security::generateRandomKey(); |
||||
if ($user->save(false)) { |
||||
$view = new View(array( |
||||
'context' => \Yii::$app->controller, |
||||
)); |
||||
|
||||
$fromEmail = \Yii::$app->params['supportEmail']; |
||||
$name = '=?UTF-8?B?' . base64_encode(\Yii::$app->name . ' robot') . '?='; |
||||
$subject = '=?UTF-8?B?' . base64_encode('Password reset for ' . \Yii::$app->name) . '?='; |
||||
$body = $view->render('/emails/passwordResetToken', array( |
||||
'user' => $user, |
||||
)); |
||||
$headers = "From: $name <{$fromEmail}>\r\n" . |
||||
"MIME-Version: 1.0\r\n" . |
||||
"Content-type: text/plain; charset=UTF-8"; |
||||
mail($fromEmail, $subject, $body, $headers); |
||||
return true; |
||||
} |
||||
} |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
} |
@ -0,0 +1,40 @@
|
||||
<?php |
||||
/** |
||||
* @link http://www.yiiframework.com/ |
||||
* @copyright Copyright (c) 2008 Yii Software LLC |
||||
* @license http://www.yiiframework.com/license/ |
||||
*/ |
||||
|
||||
namespace frontend\widgets; |
||||
|
||||
use yii\helpers\Html; |
||||
|
||||
/** |
||||
* Alert widget renders a message from session flash. You can set message as following: |
||||
* |
||||
* - \Yii::$app->getSession()->setFlash('error', 'This is the message'); |
||||
* - \Yii::$app->getSession()->setFlash('success', 'This is the message'); |
||||
* - \Yii::$app->getSession()->setFlash('info', 'This is the message'); |
||||
* |
||||
* @author Alexander Makarov <sam@rmcerative.ru> |
||||
*/ |
||||
class Alert extends \yii\bootstrap\Alert |
||||
{ |
||||
public function init() |
||||
{ |
||||
if ($this->body = \Yii::$app->getSession()->getFlash('error')) { |
||||
Html::addCssClass($this->options, 'alert-error'); |
||||
} elseif ($this->body = \Yii::$app->getSession()->getFlash('success')) { |
||||
Html::addCssClass($this->options, 'alert-success'); |
||||
} elseif ($this->body = \Yii::$app->getSession()->getFlash('info')) { |
||||
Html::addCssClass($this->options, 'alert-info'); |
||||
} elseif ($this->body = \Yii::$app->getSession()->getFlash('warning')) { |
||||
|
||||
} else { |
||||
// no message passed, no need to render widget |
||||
return; |
||||
} |
||||
|
||||
parent::init(); |
||||
} |
||||
} |
Loading…
Reference in new issue