/** * Finds user by [[email]] * * @return User|null */ public function getUser() { if ($this->_user === false) { $this->_user = User::findOne(['email' => $this->email]); } return $this->_user; }
/** * Finds user by [[username]] * * @return User|null */ public function getUser() { if ($this->_user === false) { $this->_user = User::findOne(['email' => $this->email, 'status' => User::STATUS_ACTIVE]); } return $this->_user; }
public function getUser() { if ($this->_user === false) { $this->_user = User::findOne(['id' => Yii::$app->user->id]); } return $this->_user; }
public function actionListByAgent($id) { $searchModel = new OrdersSearch(); $dataProvider = $searchModel->searchListByAgent(Yii::$app->request->queryParams, $id); $user = User::findOne($id); return $this->render('listByAgent', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'user' => $user]); }
/** * @param $username * @return null|static * @throws Exception */ private function findModel($username) { if (!($model = User::findOne(['username' => $username]))) { throw new Exception('User not found'); } return $model; }
/** * Finds the User model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return \app\modules\user\models\User the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = User::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
protected function findModel($id) { if (($model = Yii::$app->user->id == $id ? Yii::$app->user->identity : User::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function testChangeCorrect() { /** @var User $user */ $user = User::findOne($this->users[0]['id']); $form = new PasswordChangeForm($user); $form->setAttributes(['currentPassword' => 'adminpass', 'newPassword' => 'new-password', 'newPasswordRepeat' => 'new-password']); expect('password is changed', $form->changePassword())->true(); expect('password is correct', $user->validatePassword('new-password'))->true(); }
public function testUpdateCorrect() { /** @var User $user */ $user = User::findOne($this->users[0]['id']); $form = new ProfileUpdateForm($user); $form->setAttributes(['email' => '*****@*****.**']); expect('user is updated', $form->update())->true(); expect('email is new', $user->email)->equals('*****@*****.**'); }
/** * Finds the User model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @param bool $search * @return User|UserSearch the loaded model * @throws NotFoundHttpException */ protected function findModel($id, $search = false) { if ($search) { $model = new UserSearch(); } elseif (!$id) { $model = new User(); } elseif (!($model = User::findOne($id))) { throw new NotFoundHttpException(\Yii::t('modules/user', 'User not found')); } return $model; }
public function resetPasword() { if ($user = User::findOne(['email' => $this->email])) { $new_password = substr(Yii::$app->security->generateRandomString(), 0, 6); $user->setPassword($new_password); if ($user->save()) { return \Yii::$app->mailer->compose(['html' => '@app/modules/user/mails/passwordReset'], ['username' => $user->username, 'password' => $new_password])->setFrom([\Yii::$app->params['adminEmail'] => \Yii::$app->name . ' robot'])->setTo($this->email)->setSubject('Password reset for ' . \Yii::$app->name)->send(); } } return false; }
/** * Sends an email with a link, for resetting the password. * * @return boolean whether the email was send */ public function sendEmail() { /* @var $user User */ $user = User::findOne(['status' => User::STATUS_ACTIVE, 'email' => $this->email]); if ($user) { $user->generatePasswordResetToken(); if ($user->save()) { return \Yii::$app->mailer->compose('recover', ['user' => $user])->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot'])->setTo($this->email)->setSubject('Востановление пароля на сайте ' . \Yii::$app->name)->send(); } } return false; }
/** * Sends an email with a link, for resetting the password. * * @return boolean whether the email was send */ public function sendEmail() { /* @var $user User */ $user = User::findOne(['status' => User::S_ACTIVE, 'email' => $this->email]); if ($user) { $user->generatePasswordResetToken(); if ($user->save()) { Yii::$app->mailer->compose('@app/modules/user/mails/passwordReset', ['user' => $user])->setFrom([Yii::$app->params['adminEmail'] => Yii::$app->name])->setTo($this->email)->setSubject(Yii::t('frontend', 'Password reset for {name}', ['name' => Yii::$app->name]))->send(); } } return false; }
public function change() { if ($this->validate()) { $id = Yii::$app->user->id; $model = User::findOne(['id' => $id]); if (!empty($model)) { $model->setPassword($this->new_password); return $model->save(false); } } return false; }
public function testSendEmailCorrectUser() { $model = new PasswordResetRequestForm(3600); $model->email = $this->users[0]['email']; /** @var User $user */ $user = User::findOne(['password_reset_token' => $this->users[0]['password_reset_token']]); expect('email sent', $model->sendEmail())->true(); expect('user has valid token', $user->password_reset_token)->notNull(); expect('message file exists', file_exists($this->getMessageFile()))->true(); $message = file_get_contents($this->getMessageFile()); expect('message file "from" is correct', $message)->contains(Yii::$app->params['supportEmail']); expect('message file "to" is correct', $message)->contains($model->email); }
/** * Finds the User model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return User the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (is_numeric($id)) { $model = User::findOne($id); } else { $model = User::find()->where(['username' => $id])->one(); } if ($model !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function init() { if (!strcmp(Yii::$app->user->identity->roleName, 'manager')) { $user = models\User::findOne(['id' => Yii::$app->user->getId()]); } if (!strcmp(Yii::$app->user->identity->roleName, 'client')) { $user = models\User::findOne(['id' => Yii::$app->user->getId()]); } if (empty($user)) { $this->nameImg = '1'; } else { $this->nameImg = $user->avatar; } }
/** * Sends an email with a link, for resetting the password. * * @return boolean whether the email was send */ public function sendEmail() { /* @var $user User */ $user = User::findOne(['status' => User::STATUS_ACTIVE, 'email' => $this->email]); if ($user) { if (!User::isPasswordResetTokenValid($user->password_reset_token)) { $user->generatePasswordResetToken(); } if ($user->save()) { return \Yii::$app->mailer->compose(['html' => 'passwordResetToken-html', 'text' => 'passwordResetToken-text'], ['user' => $user])->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot'])->setTo($this->email)->setSubject('Password reset for ' . \Yii::$app->name)->send(); } } return false; }
/** * Sends an email with a link, for resetting the password. * * @return boolean whether the email was send */ public function sendEmail() { /* @var $user \app\modules\user\models\User */ $user = \app\modules\user\models\User::findOne(['status' => \app\modules\user\models\User::STATUS_ACTIVE, 'email' => $this->email]); if ($user) { if (!\app\modules\user\models\User::isPasswordResetTokenValid($user->password_reset_token)) { $user->generatePasswordResetToken(); } if ($user->save()) { return \Yii::$app->mailer->compose('@app/modules/user/mails/passwordReset', ['user' => $user])->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot'])->setTo($this->email)->setSubject('Password reset for ' . \Yii::$app->name)->send(); } } return false; }
/** * Sends an email with a link, for resetting the password. * * @return boolean whether the email was send */ public function sendEmail() { /* @var $user User */ $user = User::findOne(['status' => User::STATUS_ACTIVE, 'email' => $this->email]); if ($user) { if (!User::isPasswordResetTokenValid($user->password_reset_token)) { $user->generatePasswordResetToken(); } $user->scenario = 'passwordResetToken'; if ($user->save(true, ['password_reset_token'])) { return Yii::$app->mail->compose('password-reset-token', ['user' => $user])->setFrom(Yii::$app->getModule('core')->emailConfig['mailFrom'])->setTo($this->email)->setSubject(Yii::t('app', 'Password reset for {appName}', ['appName' => Yii::$app->getModule('DefaultTheme')->siteName]))->send(); } } return false; }
public function testPasswordReset(AcceptanceTester $I) { $I->wantTo('ensure that login works'); $requestPage = PasswordResetRequestPage::openBy($I); $I->seeInTitle('Reset password'); $I->amGoingTo('try to request with empty credentials'); $requestPage->send(''); if (method_exists($I, 'wait')) { $I->wait(1); // only for selenium } $I->expectTo('see validations errors'); $I->see('Email cannot be blank.'); $I->amGoingTo('try to request with wrong credentials'); $requestPage->send('reset-example.com'); if (method_exists($I, 'wait')) { $I->wait(1); // only for selenium } $I->expectTo('see validations errors'); $I->see('Email is not a valid email address.'); $I->amGoingTo('try to request with correct credentials'); $requestPage->send('*****@*****.**'); if (method_exists($I, 'wait')) { $I->wait(2); // only for selenium } $I->expectTo('see user info'); $I->see('Follow the link on mail to reset your password.', '.alert-success'); $I->amGoingTo('open change password page by token'); /** @var User $user */ $user = User::findOne(['email' => '*****@*****.**']); $resetPage = PasswordResetPage::openBy($I, ['token' => $user->password_reset_token]); $I->expectTo('see change password form'); $I->see('Please choose your new password:'******'set new password'); $resetPage->send('new-password'); if (method_exists($I, 'wait')) { $I->wait(2); // only for selenium } $I->expectTo('see password change success message'); $I->see('Thanks! Your passwords is changed.'); $I->amGoingTo('try to login with new credentials'); $this->login($I, 'reset', 'new-password'); $I->expectTo('see user info'); $I->see('Profile'); }
/** * @return string|\yii\web\Response * @throws \yii\web\ServerErrorHttpException */ public function actionCreate($user = null) { $user = User::USER_GUEST !== intval($user) ? User::findOne(['id' => intval($user)]) : null; $customer = Customer::createEmptyCustomer(null === $user ? 0 : $user->id); if (true === \Yii::$app->request->isPost) { $data = \Yii::$app->request->post(); if ($customer->load($data) && $customer->save()) { if (!empty($customer->getPropertyGroup())) { $customer->getPropertyGroup()->appendToObjectModel($customer); $data[$customer->getAbstractModel()->formName()] = isset($data['CustomerNew']) ? $data['CustomerNew'] : []; } $customer->saveModelWithProperties($data); $customer->refresh(); return $this->redirect(Url::toRoute(['edit', 'id' => $customer->id])); } } return $this->render('create', ['model' => $customer]); }
/** * @return bool */ public function generatePasswordResetToken() { if (!$this->validate()) { return false; } $new_password = \Yii::$app->security->generateRandomString(8); /** @var User $user */ $user = User::findOne(['email' => $this->email]); $user->password_reset_token = User::generatePasswordResetToken(); $user->password_hash = User::hashPassword($new_password); $user->status = User::USER_STATUS_INACTIVE; $user->save(); $isSend = \Yii::$app->mailer->compose('user/forgot_password', ['user_name' => $user->name, 'token' => $user->password_reset_token, 'new_password' => $new_password])->setFrom(Settings::value('general', 'shopEmail'))->setTo($this->email)->setSubject(\Yii::t('mail', 'New password activation'))->send(); if (!$isSend) { $this->addError(\Yii::t('mail', 'Oops, can\'t deliver letter to such email address.')); } return $isSend; }
/** * Signs user up. * * @return User|null the saved model or null if saving fails */ public function signup() { if ($this->validate()) { if (!($user = User::findOne(['email' => $this->email, 'status' => USER::STATUS_WAIT]))) { $user = new User(); } $user->username = $this->username; $user->email = $this->email; $user->setPassword($this->password); $user->status = User::STATUS_WAIT; $user->generateAuthKey(); $user->generateEmailConfirmToken(); if ($user->save()) { Yii::$app->mailer->compose('@app/modules/user/mail/emailConfirm', ['user' => $user])->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name])->setTo($this->email)->setSubject('Email confirmation for ' . Yii::$app->name)->send(); } return $user; } return null; }
public function actionView($id) { $model = new Pm(); # получаем юзера который принимает сообщения $acceptorUser = User::findOne($id); # читаем переписку с этим пользователем // $messages = Pm::find(['user_id' => $id, 'sender_id' => $id])->all(); $messages = Pm::getMessages($id); if (Yii::$app->user->id == $id) { throw new HttpException(400); } $model->user_id = $id; if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $id]); } // else // \Yii::$app->VarDumper->dump($model->getErrors()); return $this->render('view', ['model' => $model, 'pages' => $messages['pages'], 'messages' => $messages['models'], 'acceptorUser' => $acceptorUser]); }
/** * Sends an email with a link, for resetting the password. * * @return boolean whether the email was send */ public function sendEmail() { /* @var $user User */ $user = User::findOne(['status' => User::STATUS_ACTIVE, 'email' => $this->email]); if ($user) { if (!User::isPasswordResetTokenValid($user->password_reset_token)) { $user->generatePasswordResetToken(); } if ($user->save()) { $confirmLink = Yii::$app->urlManager->createAbsoluteUrl(['user/default/confirm-email', 'token' => $user->email_confirm_token]); $message = "Здравствуйте, " . Html::encode($user->username) . "!"; $message .= "Пройдите по ссылке, чтобы сменить пароль:"; $message .= $resetLink; $message .= "Если Вы не регистрировались у на нашем сайте, то просто удалите это письмо."; /* \Yii::$app->mailer->compose(['html' => '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; }
public function _after() { User::findOne(['username' => 'admin'])->updateAttributes(['password_hash' => '$2y$13$D8areN6YSJh.fmR.Ww/sWOJ8EXRxNS9c7u7ubIrVozomTR8MY0PbO']); }
protected function findUserModel() { return User::findOne(Yii::$app->user->id); }
public function _after() { User::findOne(['username' => 'admin'])->updateAttributes(['email' => '*****@*****.**']); }
/** * Finds the User model based on its primary key value. * @return User the loaded model */ protected function findModel() { $id = Yii::$app->user->identity->id; return User::findOne($id); }