/** * Finds user by [[username]] * * @return User|null */ public function getUser() { if ($this->_user === false) { /** @var User $userClass */ $userClass = Kiwi::getUserClass(); $this->_user = $userClass::findByUsername($this->username); } return $this->_user; }
/** * Creates a form model given a token. * * @param string $token * @param array $config name-value pairs that will be used to initialize the object properties * @throws \yii\base\InvalidParamException if token is empty or not valid */ public function __construct($token, $config = []) { $userClass = Kiwi::getUserClass(); if (empty($token) || !is_string($token)) { throw new InvalidParamException('Password reset token cannot be blank.'); } $this->_user = $userClass::findByPasswordResetToken($token); if (!$this->_user) { throw new InvalidParamException('Wrong password reset token.'); } parent::__construct($config); }
/** * Sends an email with a link, for resetting the password. * * @return boolean whether the email was send */ public function sendEmail() { $userClass = Kiwi::getUserClass(); /* @var $user User */ $user = $userClass::findOne(['status' => $userClass::STATUS_ACTIVE, 'email' => $this->email]); if ($user) { if (!$userClass::isPasswordResetTokenValid($user->password_reset_token)) { $user->generatePasswordResetToken(); } if ($user->save()) { return \Yii::$app->mailer->compose('passwordResetToken', ['user' => $user])->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot'])->setTo($this->email)->setSubject('Password reset for ' . \Yii::$app->name)->send(); } } return false; }
/** * @inheritdoc */ public function rules() { return [['username', 'filter', 'filter' => 'trim'], ['username', 'required'], ['username', 'unique', 'targetClass' => Kiwi::getUserClass(), 'message' => 'This username has already been taken.'], ['username', 'string', 'min' => 2, 'max' => 255], ['email', 'filter', 'filter' => 'trim'], ['email', 'required'], ['email', 'email'], ['email', 'unique', 'targetClass' => Kiwi::getUserClass(), 'message' => 'This email address has already been taken.'], ['password', 'required'], ['password', 'string', 'min' => 6]]; }