/** * Signs user up. * * @return BaseUserModel|null the saved model or null if saving fails */ public function signup() { if (!$this->validate()) { return null; } $user = new BaseUserModel(); $user->username = $this->username; $user->email = $this->email; $user->setPassword($this->password); $user->generateAuthKey(); $user->lastLogin = time(); return $user->save() ? $user : null; }
/** * Finds user by [[email]] * * @return BaseUserModel|null */ public function getUser() { if ($this->_user === false) { $this->_user = BaseUserModel::findByEmail($this->email); } return $this->_user; }
/** * Signs user up. * * @return BaseUserModel|null the saved model or null if saving fails */ public function signup() { if ($this->validate()) { $user = new BaseUserModel(); $user->username = $this->username; $user->email = $this->email; $user->setPassword($this->password); $user->generateAuthKey(); $user->lastLogin = time(); if ($user->save()) { $userDetailsModels = new BaseUserDetailsModel(); $userDetailsModels->userId = $user->primaryKey; $userDetailsModels->save(); } return $user; } return null; }
/** * 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 = []) { if (empty($token) || !is_string($token)) { throw new InvalidParamException('Password reset token cannot be blank.'); } $this->_user = BaseUserModel::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 bool whether the email was send */ public function sendEmail() { $user = BaseUserModel::findOne(['status' => BaseUserModel::STATUS_ACTIVE, 'email' => $this->email]); if (!empty($user)) { $user->generatePasswordResetToken(); if ($user->save()) { return Yii::$app->mailer->compose('passwordResetToken', ['user' => $user])->setFrom(Yii::$app->params['adminEmail'])->setTo($this->email)->setSubject(Yii::t('yii2mod.user', 'Password reset for {0}', Yii::$app->name))->send(); } } return false; }
/** * {@inheritdoc} */ public function attributeLabels() { return ArrayHelper::merge(['username' => Yii::t('user', 'Username'), 'email' => Yii::t('user', 'Email'), 'createdAt' => Yii::t('user', 'Created date'), 'newPassword' => $this->isNewRecord ? Yii::t('user', 'Password') : Yii::t('user', 'New Password')], parent::attributeLabels()); }