Пример #1
0
 /**
  * Creates a new User model.
  * If creation is successful, the browser will be redirected to the 'index' page.
  * @return mixed
  */
 public function actionCreate()
 {
     /** @var User $user */
     $user = \Yii::createObject(['class' => User::className(), 'scenario' => 'create']);
     $this->performAjaxValidation($user);
     if ($user->load(\Yii::$app->request->post()) && $user->create()) {
         \Yii::$app->getSession()->setFlash('success', \Yii::t('user', 'User has been created'));
         return $this->redirect(['index']);
     }
     return $this->render('create', ['user' => $user]);
 }
Пример #2
0
 /**
  * This command creates new user account. If password is not set, this command will generate new 8-char password.
  * After saving user to database, this command uses mailer component to send credentials (username and password) to
  * user via email.
  *
  * @param string      $email    Email address
  * @param string      $username Username
  * @param null|string $password Password (if null it will be generated automatically)
  */
 public function actionIndex($email, $username, $password = null)
 {
     $user = \Yii::createObject(['class' => User::className(), 'scenario' => 'create', 'email' => $email, 'username' => $username, 'password' => $password]);
     if ($user->create()) {
         $this->stdout(\Yii::t('user', 'User has been created') . "!\n", Console::FG_GREEN);
     } else {
         $this->stdout(\Yii::t('user', 'Please fix following errors:') . "\n", Console::FG_RED);
         foreach ($user->errors as $errors) {
             foreach ($errors as $error) {
                 $this->stdout(" - " . $error . "\n", Console::FG_RED);
             }
         }
     }
 }
Пример #3
0
 /**
  * Displays page where user can create new account that will be connected to social account.
  * @param  integer $account_id
  * @return string
  * @throws NotFoundHttpException
  */
 public function actionConnect($account_id)
 {
     $account = $this->finder->findAccountById($account_id);
     if ($account === null || $account->getIsConnected()) {
         throw new NotFoundHttpException();
     }
     /** @var User $user */
     $user = \Yii::createObject(['class' => User::className(), 'scenario' => 'connect']);
     if ($user->load(\Yii::$app->request->post()) && $user->create()) {
         $account->user_id = $user->id;
         $account->save(false);
         \Yii::$app->user->login($user, $this->module->rememberFor);
         return $this->goBack();
     }
     return $this->render('connect', ['model' => $user, 'account' => $account]);
 }
Пример #4
0
$user = $I->grabRecord(User::className(), ['id' => $user->id]);
$token = $I->grabRecord(Token::className(), ['user_id' => $user->id, 'type' => Token::TYPE_CONFIRM_NEW_EMAIL]);
$I->seeInEmail(Html::encode($token->getUrl()));
$I->seeInEmailRecipients($user->unconfirmed_email);
Yii::$app->user->logout();
$I->amGoingTo('log in using new email address before clicking the confirmation link');
$page = LoginPage::openBy($I);
$page->login('*****@*****.**', 'qwerty');
$I->see('Invalid login or password');
$I->amGoingTo('log in using new email address after clicking the confirmation link');
$user->attemptEmailChange($token->code);
$page->login('*****@*****.**', 'qwerty');
$I->see('Logout');
$I->seeRecord(User::className(), ['id' => 1, 'email' => '*****@*****.**', 'unconfirmed_email' => null]);
$I->amGoingTo('reset email changing process');
$page = SettingsPage::openBy($I);
$page->update('*****@*****.**', $user->username, 'qwerty');
$I->see('A confirmation message has been sent to your new email address');
$I->seeRecord(User::className(), ['id' => 1, 'email' => '*****@*****.**', 'unconfirmed_email' => '*****@*****.**']);
$page->update('*****@*****.**', $user->username, 'qwerty');
$I->see('Your account details have been updated');
$I->seeRecord(User::className(), ['id' => 1, 'email' => '*****@*****.**', 'unconfirmed_email' => null]);
$I->amGoingTo('change username and password');
$page->update('*****@*****.**', 'nickname', 'qwerty', '123654');
$I->see('Your account details have been updated');
$I->seeRecord(User::className(), ['username' => 'nickname', 'email' => '*****@*****.**']);
Yii::$app->user->logout();
$I->amGoingTo('login with new credentials');
$page = LoginPage::openBy($I);
$page->login('nickname', '123654');
$I->see('Logout');
Пример #5
0
 /** @inheritdoc */
 public function init()
 {
     $this->user = \Yii::createObject(['class' => User::className(), 'scenario' => 'register']);
     $this->module = \Yii::$app->getModule('user');
 }
Пример #6
0
use yii\helpers\Html;
use yii\helpers\Url;
use chd7well\user\models\User;
use chd7well\user\models\Token;
$I = new FunctionalTester($scenario);
$I->wantTo('ensure that password recovery works');
$page = RecoveryPage::openBy($I);
$I->amGoingTo('try to request recovery token for unconfirmed account');
$user = $I->getFixture('user')->getModel('unconfirmed');
$page->recover($user->email);
$I->see('You need to confirm your email address');
$I->amGoingTo('try to request recovery token');
$user = $I->getFixture('user')->getModel('user');
$page->recover($user->email);
$I->see('An email has been sent with instructions for resetting your password');
$user = $I->grabRecord(User::className(), ['email' => $user->email]);
$token = $I->grabRecord(Token::className(), ['user_id' => $user->id, 'type' => Token::TYPE_RECOVERY]);
$I->seeInEmail(Html::encode($token->getUrl()));
$I->seeInEmailRecipients($user->email);
$I->amGoingTo('reset password with invalid token');
$user = $I->getFixture('user')->getModel('user_with_expired_recovery_token');
$token = $I->grabRecord(Token::className(), ['user_id' => $user->id, 'type' => Token::TYPE_RECOVERY]);
$I->amOnPage(Url::toRoute(['/user/recovery/reset', 'id' => $user->id, 'code' => $token->code]));
$I->see('Recovery link is invalid or expired. Please try requesting a new one.');
$I->amGoingTo('reset password');
$user = $I->getFixture('user')->getModel('user_with_recovery_token');
$token = $I->grabRecord(Token::className(), ['user_id' => $user->id, 'type' => Token::TYPE_RECOVERY]);
$I->amOnPage(Url::toRoute(['/user/recovery/reset', 'id' => $user->id, 'code' => $token->code]));
$I->fillField('#recovery-form-password', 'newpass');
$I->click('Finish');
$I->see('Your password has been changed successfully.');
Пример #7
0
<?php

use chd7well\user\models\Token;
use chd7well\user\models\User;
use tests\codeception\_pages\RegistrationPage;
use yii\helpers\Html;
$I = new FunctionalTester($scenario);
$I->wantTo('ensure that registration works');
$page = RegistrationPage::openBy($I);
$I->amGoingTo('try to register with empty credentials');
$page->register('', '', '');
$I->see('Username cannot be blank');
$I->see('Email cannot be blank');
$I->see('Password cannot be blank');
$I->amGoingTo('try to register with already used email and username');
$user = $I->getFixture('user')->getModel('user');
$page->register($user->username, $user->email, 'qwerty');
$I->see(Html::encode('This username has already been taken'));
$I->see(Html::encode('This email address has already been taken'));
$I->amGoingTo('try to register');
$page->register('tester', '*****@*****.**', 'tester');
$I->see('A message has been sent to your email address. It contains a confirmation link that you must click to complete registration.');
$user = $I->grabRecord(User::className(), ['email' => '*****@*****.**']);
$token = $I->grabRecord(Token::className(), ['user_id' => $user->id, 'type' => Token::TYPE_CONFIRMATION]);
$I->seeInEmail(Html::encode($token->url));