本文整理汇总了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;
}
示例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();
}
示例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]);
}
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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]);
}
示例9: login
/**
* @return bool
*/
public function login()
{
if ($this->validate()) {
return User::login($this->email, $this->remember_me);
}
return false;
}
示例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');
}
示例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]);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}