当前位置: 首页>>代码示例>>PHP>>正文


PHP models\User类代码示例

本文整理汇总了PHP中app\modules\user\models\User的典型用法代码示例。如果您正苦于以下问题:PHP User类的具体用法?PHP User怎么用?PHP User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: signup

 /**
  * 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;
 }
开发者ID:nicovicz,项目名称:portalctv,代码行数:30,代码来源:SignupForm.php

示例2: create

 /**
  * @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();
 }
开发者ID:vetoni,项目名称:toko,代码行数:33,代码来源:DemoData.php

示例3: actionCreate

 /**
  * 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]);
     }
 }
开发者ID:obedkin,项目名称:atlant,代码行数:14,代码来源:DefaultController.php

示例4: testSave

 public function testSave()
 {
     $model = new User(['username' => 'test_user', 'email' => 'other@example.com', '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();
 }
开发者ID:oke11o,项目名称:seokeys,代码行数:10,代码来源:UserTest.php

示例5: signup

 /**
  * 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;
 }
开发者ID:alexshadie,项目名称:wallet,代码行数:19,代码来源:SignupForm.php

示例6: signup

 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;
 }
开发者ID:knyazushka,项目名称:z34lot.new,代码行数:28,代码来源:SignupForm.php

示例7: getUser

 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 protected function getUser()
 {
     if ($this->_user === null) {
         $this->_user = User::findByUsername($this->username);
     }
     return $this->_user;
 }
开发者ID:head26,项目名称:parsek,代码行数:12,代码来源:LoginForm.php

示例8: testSignup

 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' => 'tester.email@example.com', 'password' => 'tester_password', 'verifyCode' => 'testme']);
     $I->expectTo('see that user is created');
     $I->seeRecord(User::className(), ['username' => 'tester', 'email' => 'tester.email@example.com', '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' => 'tester.email@example.com', 'status' => User::STATUS_ACTIVE, 'email_confirm_token' => null]);
 }
开发者ID:manakao,项目名称:melby,代码行数:35,代码来源:SignupCest.php

示例9: login

 /**
  * @return bool
  */
 public function login()
 {
     if ($this->validate()) {
         return User::login($this->email, $this->remember_me);
     }
     return false;
 }
开发者ID:vetoni,项目名称:toko,代码行数:10,代码来源:LoginForm.php

示例10: testPasswordReset

 /**
  * @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('reset@example.com');
     $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' => 'reset@example.com']);
     $resetPage = PasswordResetPage::openBy($I, ['token' => $user->password_reset_token]);
     $I->expectTo('see change password form');
     $I->see('Please choose your new password:');
     $I->amGoingTo('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');
 }
开发者ID:manakao,项目名称:melby,代码行数:35,代码来源:PasswordResetCest.php

示例11: actionListByAgent

 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]);
 }
开发者ID:kvaxminsk,项目名称:belpharma2,代码行数:7,代码来源:OrdersController.php

示例12: getUser

 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findByEmail($this->email);
     }
     return $this->_user;
 }
开发者ID:akula22,项目名称:fifa,代码行数:12,代码来源:LoginByEmail.php

示例13: getUser

 /**
  * 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;
 }
开发者ID:artkost,项目名称:yii2-starter-kit,代码行数:12,代码来源:Password.php

示例14: getUser

 /**
  * Finds user by [[email]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findOne(['email' => $this->email]);
     }
     return $this->_user;
 }
开发者ID:bariew,项目名称:sitown,代码行数:12,代码来源:LoginForm.php

示例15: getUser

 /**
  * 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;
 }
开发者ID:Dominus77,项目名称:blog,代码行数:12,代码来源:PasswordResetRequestForm.php


注:本文中的app\modules\user\models\User类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。