示例#1
0
 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     $auth = Yii::$app->authManager;
     $role = $auth->getRole($this->jabatan);
     if ($this->validate() && !empty($role)) {
         $user = new User();
         $user->username = $this->username;
         $user->email = $this->email;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         if ($user->validate() && $user->save()) {
             $person = new Person();
             $person->first_name = $this->first_name;
             $person->last_name = $this->last_name;
             $person->gender = $this->gender;
             $person->birth_date = $this->birth_date;
             $person->user_id = $user->id;
             if ($person->validate() && $person->save()) {
                 $auth->assign($role, $user->id);
                 return true;
             }
         }
     }
     return false;
 }
示例#2
0
文件: DemoData.php 项目: vetoni/toko
 /**
  * @param Configuration $config
  * @throws \yii\base\Exception
  * @throws \yii\base\InvalidConfigException
  */
 public static function create($config)
 {
     $language = substr(Yii::$app->language, 0, 2);
     $db = Yii::$app->getDb();
     // Settings
     $db->createCommand()->batchInsert('{{%settings}}', ['group', 'name', 'value'], [['stock', 'outofstock', 0], ['stock', 'lowstock', 10], ['general', 'shopEmail', $config->shopEmail], ['general', 'adminEmail', $config->adminEmail]])->execute();
     // Currencies
     $db->createCommand()->batchInsert('{{%currency}}', ['code', 'name', 'is_default', 'rate', 'symbol'], [['EUR', 'Euro', 0, 0.0145, '€'], ['UAH', 'Hryvnia', 0, 0.3601, '₴'], ['RUB', 'Ruble', 1, 1, '₽'], ['USD', 'US Dollar', 0, 0.0158, '$']])->execute();
     // Countries
     static::callLocalized('countries', $language);
     // Users
     $root_auth_key = Yii::$app->security->generateRandomString();
     $root_password = Yii::$app->security->generatePasswordHash($config->adminPassword);
     $user = new User(['email' => $config->adminEmail, 'name' => 'admin', 'country_id' => 'us', 'address' => '7805 Southcrest Parkway, Southaven, MS(Mississippi) 38671', 'phone' => '(662) 349-7500', 'password_hash' => $root_password, 'auth_key' => $root_auth_key, 'role' => User::USER_ROLE_ADMIN]);
     $user->save();
     // Categories
     static::callLocalized('categories', $language);
     // Products
     static::callLocalized('products', $language);
     // Comments
     static::callLocalized('comments', $language);
     // Pages
     static::callLocalized('pages', $language);
     // News
     static::callLocalized('news', $language);
     // Relations
     $db->createCommand()->batchInsert('{{%relation}}', ['item_id', 'related_id', 'model'], [[1, 2, 'Product'], [1, 3, 'Product'], [3, 1, 'Product'], [3, 2, 'Product']])->execute();
 }
示例#3
0
 /**
  * @param string $attribute
  * @param array $params
  */
 public function validatePassword($attribute, $params)
 {
     if (!$this->hasErrors()) {
         if (!$this->_user->validatePassword($this->{$attribute})) {
             $this->addError($attribute, 'Неправильный текущий пароль');
         }
     }
 }
 /**
  * @param string $attribute
  * @param array $params
  */
 public function validatePassword($attribute, $params)
 {
     if (!$this->hasErrors()) {
         if (!$this->_user->validatePassword($this->{$attribute})) {
             $this->addError($attribute, Yii::t('user/password', 'Wrong current password'));
         }
     }
 }
示例#5
0
 /**
  * @param string $attribute
  * @param array $params
  */
 public function validatePassword($attribute, $params)
 {
     if (!$this->hasErrors()) {
         if (!$this->_user->validatePassword($this->{$attribute})) {
             $this->addError($attribute, Module::t('module', 'ERROR_WRONG_CURRENT_PASSWORD'));
         }
     }
 }
 /**
  * @param string $attribute
  * @param array $params
  */
 public function validatePassword($attribute, $params)
 {
     if (!$this->hasErrors()) {
         if (!$this->_user->validatePassword($this->{$attribute})) {
             $this->addError($attribute, \Yii::$app->session->setFlash('error', 'Неверный текщий пароль'));
         }
     }
 }
 /**
  * @param string $attribute
  * @param array $params
  */
 public function currentPassword($attribute, $params)
 {
     if (!$this->hasErrors()) {
         if (!$this->_user->validatePassword($this->{$attribute})) {
             $this->addError($attribute, Yii::t('app', 'ERROR_WRONG_CURRENT_PASSWORD'));
         }
     }
 }
示例#8
0
 /**
  * Creates a new User model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new User();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
示例#9
0
 public function testSave()
 {
     $model = new User(['username' => 'test_user', 'email' => '*****@*****.**', 'status' => 1]);
     $model->setPassword('new-password');
     expect('model is saved', $model->save())->true();
     expect('password is correct', $model->validatePassword('new-password'))->true();
     expect('auth key is correct', $model->auth_key)->notEmpty();
     expect('created_at is correct', $model->created_at)->notEmpty();
     expect('updated_at is correct', $model->updated_at)->notEmpty();
 }
示例#10
0
 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $user->username = $this->username;
         $user->email = $this->email;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         if ($user->save()) {
             return $user;
         }
     }
     return null;
 }
示例#11
0
 public function signup()
 {
     if ($this->validate()) {
         $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()) {
             $auth = Yii::$app->authManager;
             $userRoleDefault = $auth->getRole('user');
             $auth->assign($userRoleDefault, $user->getId());
             $userProfile = new Profile();
             $userProfile->user_id = $user->getId();
             $userProfile->user_agent = Yii::$app->request->getUserAgent();
             $userProfile->user_ip = Yii::$app->request->getUserIP();
             $userProfile->name = $user->username;
             $userProfile->avatar_id = 1;
             //default.png (id = 1)
             $userProfile->save(false);
             Yii::$app->mailer->compose(['text' => '@app/modules/user/mails/emailConfirm'], ['user' => $user])->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name . ' robot'])->setTo($this->email)->setSubject(Module::t('app', 'EMAIL_SIGNUP_SUBJECT') . Yii::$app->name)->send();
         }
         return $user;
     }
     return null;
 }
示例#12
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 protected function getUser()
 {
     if ($this->_user === null) {
         $this->_user = User::findByUsername($this->username);
     }
     return $this->_user;
 }
示例#13
0
 public function testSignup(FunctionalTester $I)
 {
     $I->wantTo('ensure that signup works');
     $signupPage = SignupPage::openBy($I);
     $I->seeInTitle('Signup');
     $I->see('Please fill out the following fields to signup:');
     $I->amGoingTo('submit signup form with no data');
     $signupPage->submit([]);
     $I->expectTo('see validation errors');
     $I->see('Username cannot be blank.', '.help-block');
     $I->see('Email cannot be blank.', '.help-block');
     $I->see('Password cannot be blank.', '.help-block');
     $I->see('The verification code is incorrect.', '.help-block');
     $I->amGoingTo('submit signup form with not correct data');
     $signupPage->submit(['username' => 'tester', 'email' => 'tester.email', 'password' => 'tester_password', 'verifyCode' => 'wrong']);
     $I->expectTo('see that email address is wrong');
     $I->dontSee('Username cannot be blank.', '.help-block');
     $I->dontSee('Password cannot be blank.', '.help-block');
     $I->see('Email is not a valid email address.', '.help-block');
     $I->see('The verification code is incorrect.', '.help-block');
     $I->amGoingTo('submit signup form with correct data');
     $signupPage->submit(['username' => 'tester', 'email' => '*****@*****.**', 'password' => 'tester_password', 'verifyCode' => 'testme']);
     $I->expectTo('see that user is created');
     $I->seeRecord(User::className(), ['username' => 'tester', 'email' => '*****@*****.**', 'status' => User::STATUS_WAIT]);
     $I->expectTo('see that user signed in');
     $I->see('Please confirm your Email.', '.alert-success');
     $I->amGoingTo('confirm user email by token');
     /** @var User $user */
     $user = $I->grabRecord(User::className(), ['username' => 'tester']);
     EmailConfirmPage::openBy($I, ['token' => $user->email_confirm_token]);
     $I->expectTo('see that email is confirmed');
     $I->see('Thanks! Your Email is confirmed.', '.alert-success');
     $I->expectTo('see that user status is confirmed');
     $I->seeRecord(User::className(), ['username' => 'tester', 'email' => '*****@*****.**', 'status' => User::STATUS_ACTIVE, 'email_confirm_token' => null]);
 }
示例#14
0
文件: LoginForm.php 项目: vetoni/toko
 /**
  * @return bool
  */
 public function login()
 {
     if ($this->validate()) {
         return User::login($this->email, $this->remember_me);
     }
     return false;
 }
示例#15
0
 /**
  * @after logout
  */
 public function testPasswordReset(FunctionalTester $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('');
     $I->expectTo('see validations errors');
     $I->see('Email cannot be blank.');
     $I->amGoingTo('try to request with wrong credentials');
     $requestPage->send('reset-example.com');
     $I->expectTo('see validations errors');
     $I->see('Email is not a valid email address.');
     $I->amGoingTo('try to request with correct credentials');
     $requestPage->send('*****@*****.**');
     $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 = $I->grabRecord(User::className(), ['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');
     $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');
 }
示例#16
0
 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]);
 }
示例#17
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findByEmail($this->email);
     }
     return $this->_user;
 }
示例#18
0
 /**
  * Finds user by id.
  *
  * @return User|null User instance
  */
 protected function getUser()
 {
     if ($this->_user === null) {
         $this->_user = User::find()->where(['id' => Yii::$app->user->identity->id])->active()->one();
     }
     return $this->_user;
 }
示例#19
0
 /**
  * Finds user by [[email]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findOne(['email' => $this->email]);
     }
     return $this->_user;
 }
示例#20
0
 /**
  * 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;
 }
示例#21
0
 public function actionResult()
 {
     // $Shp_id= $user->PID;
     if (!Yii::$app->request->post()) {
         return $this->goBack();
     }
     $request = Yii::$app->request;
     $out_summ = $request->post('OutSum');
     $inv_id = $request->post('InvId');
     $shp_item = $request->post('Shp_item');
     $crc = $request->post('SignatureValue');
     $crc = strtoupper($crc);
     $my_crc = strtoupper(md5("{$out_summ}:{$inv_id}:{$this->mrh_pass2}:Shp_item={$shp_item}"));
     if ($my_crc != $crc) {
         throw new NotFoundHttpException('bad signature');
     }
     $user = User::findByPid($shp_item);
     $today = $user->date;
     if (date("Y-m-d") > $user->date) {
         $today = date("Y-m-d H:i:s");
     }
     $user->date = date('Y-m-d', strtotime($today . '+ 1 month'));
     $user->save();
     return "OK{$inv_id}\n";
 }
 /**
  * Check if token is valid.
  *
  * @return boolean true if token is valid
  */
 public function isValidToken()
 {
     if (SecurityHelper::isValidToken($this->token, Module::param('recoveryWithin', false)) === true) {
         return ($this->_user = User::findByToken($this->token, 'active')) !== null;
     }
     return false;
 }
示例#23
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 private function getUser()
 {
     if ($this->user === false) {
         $this->user = User::findByUsername($this->username);
     }
     return $this->user;
 }
示例#24
0
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findOne(['id' => Yii::$app->user->id]);
     }
     return $this->_user;
 }
示例#25
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findByLogin($this->login);
     }
     return $this->_user;
 }
 public function up()
 {
     $table = \app\modules\poll\models\Comment::tableName();
     $this->createTable($table, ['id' => $this->primaryKey(), 'user_id' => $this->integer(), 'question_id' => $this->integer(), 'created_at' => $this->integer(), 'message' => $this->text()]);
     MigrationHelper::addForeignKey($table, 'user_id', \app\modules\user\models\User::tableName(), 'id', 'SET NULL', 'CASCADE');
     MigrationHelper::addForeignKey($table, 'question_id', \app\modules\poll\models\Question::tableName(), 'id', 'CASCADE', 'CASCADE');
 }
示例#27
0
 /**
  * @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;
 }
示例#28
0
 public function up()
 {
     $table = Vote::tableName();
     $this->createTable($table, ['answer_id' => $this->integer(), 'user_id' => $this->integer(), 'created_at' => $this->integer()]);
     MigrationHelper::addForeignKey($table, 'answer_id', Answer::tableName(), 'id', 'CASCADE', 'CASCADE');
     MigrationHelper::addForeignKey($table, 'user_id', User::tableName(), 'id', 'SET NULL', 'CASCADE');
 }
示例#29
0
 /**
  * user register.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function register()
 {
     if ($this->validate()) {
         return User::create($this->attributes);
     }
     return null;
 }
示例#30
0
 /**
  * @inheritdoc
  */
 public function scenarios()
 {
     $scenarios = parent::scenarios();
     $scenarios['admin-create'] = ['username', 'email', 'password', 'repassword'];
     $scenarios['admin-update'] = ['username', 'email', 'password', 'repassword'];
     return $scenarios;
 }