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


PHP User::setPassword方法代码示例

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


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

示例1: signup

 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $profile = new Profile();
         $user->username = $this->username;
         $user->email = $this->email;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         $user->role = 'user';
         $user->status = 1;
         $profile->firstname = $this->firstname;
         $profile->lastname = $this->lastname;
         $profile->avatar = $this->avatar;
         // $profile->gender = 0;
         $transaction = Yii::$app->db->beginTransaction();
         if ($user->save()) {
             $profile->user_id = $user->getId();
             if ($profile->save()) {
                 $transaction->commit();
                 return $user;
             }
         } else {
             $transaction->rollback();
             print_r($user->getErrors());
             return false;
         }
     }
     return null;
 }
开发者ID:akula22,项目名称:fifa,代码行数:35,代码来源:SignupForm.php

示例2: 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

示例3: 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

示例4: 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->last_name = $this->last_name;
         $user->first_name = $this->first_name;
         $user->patronymic = $this->patronymic;
         $user->email_work = $this->email_work;
         $user->post_id = $this->post_id;
         $user->department_id = $this->department_id;
         $user->status_id = User::STATUS_WAIT;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         $user->generateEmailConfirmToken();
         if ($user->save()) {
             // Присваиваем роль по умолчанию
             //$auth = Yii::$app->authManager;
             //$authorRole = $auth->getRole('user');
             //$auth->assign($authorRole, $user->getId());
             //Отправляем письмо с подтверждением
             /*Yii::$app->mailer->compose('confirmEmail', ['user' => $user])
                               ->setFrom([Yii::$app->params['app']['supportEmail'] => Yii::$app->params['app']['title']])
                               ->setTo($this->email_work)
                               ->setSubject('Email confirmation for ' . Yii::$app->name)
                               ->send();
             */
             Yii::$app->mailer->compose('confirmEmail', ['user' => $user])->setFrom([Yii::$app->params['app']['email'] => Yii::$app->params['app']['title']])->setTo($this->email_work)->setSubject('Email confirmation for ')->send();
         }
         return $user;
     }
     return null;
 }
开发者ID:obedkin,项目名称:atlant,代码行数:37,代码来源:SignupForm.php

示例5: 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

示例6: 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->status = User::STATUS_WAIT;
         $user->generateAuthKey();
         $user->generateEmailConfirmToken();
         //
         if ($user->save()) {
             $auth = Yii::$app->authManager;
             $role = $auth->getRole('client');
             $auth->assign($role, $user->getId());
             $confirmLink = Yii::$app->urlManager->createAbsoluteUrl(['user/default/confirm-email', 'token' => $user->email_confirm_token]);
             $message = "Здравствуйте, " . Html::encode($user->username) . "!";
             $message .= "Для подтверждения адреса пройдите по ссылке:";
             //$message .= Html::a(Html::encode($confirmLink), $confirmLink) ;
             $message .= $confirmLink;
             $message .= " Если Вы не регистрировались у на нашем сайте, то просто удалите это письмо.";
             // Отправляем
             mail($user->email, 'Регистрация на сайте', $message);
             //                $mailer =Yii::$app->get('mailsmtp');
             //
             //                $message =$mailer->compose('confirmEmail', ['user' => $user])
             //
             //                    ->setTo($this->email)
             //                    ->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name])
             //                    ->setSubject('Email confirmation for ' . Yii::$app->name);
             //
             //                $message->getSwiftMessage()->getHeaders()->addTextHeader('name', 'value');
             //                $failures =null;
             //                try {
             //
             //                    if(!$mailer->send($message, $failures)) $errorCode=$failures; //отправляем
             //
             //                }catch (\Swift_TransportException $e) { //проверяем на ошибки
             //                    $pattern = '|got code "(.+?)", with|is';
             //                    preg_match($pattern, $e->getMessage(), $out);
             //                    $errorCode=$out[1];
             //                }
             /*Yii::$app->mailer->compose('confirmEmail', ['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;
 }
开发者ID:kvaxminsk,项目名称:evo8,代码行数:57,代码来源:SignupForm.php

示例7: 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

示例8: signup

 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate() === true) {
         $user = new User();
         $user->setScenario('signup');
         $user->username = $this->username;
         $user->email = $this->email;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         if ($user->save() === false) {
             return null;
         }
         return $user;
     }
     return null;
 }
开发者ID:heartshare,项目名称:dotplant2,代码行数:21,代码来源:RegistrationForm.php

示例9: 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->status = User::STATUS_WAIT;
         $user->generateAuthKey();
         $user->generateEmailConfirmToken();
         if ($user->save()) {
             Yii::$app->mailer->compose('confirmEmail', ['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;
 }
开发者ID:Robot72,项目名称:yii2-base-template,代码行数:22,代码来源:SignupForm.php

示例10: 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->status = User::STATUS_WAIT;
         $user->generateAuthKey();
         $user->generateEmailConfirmToken();
         if ($user->save()) {
             Yii::$app->mailer->compose(['text' => '@app/modules/user/mails/emailConfirm'], ['user' => $user])->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name])->setTo($this->email)->setSubject(Module::t('module', 'EMAIL_CONFIRMATION_FOR {appName}', ['appName' => Yii::$app->name]))->send();
         }
         return $user;
     }
     return null;
 }
开发者ID:Dominus77,项目名称:blog,代码行数:22,代码来源:SignupForm.php

示例11: 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->status = User::STATUS_ACTIVE;
         // заглушка (должно быть STATUS_WAIT): из-за неполадок с отправкой e-mail на сервере
         $user->generateAuthKey();
         $user->generateEmailConfirmToken();
         if ($user->save()) {
             Yii::$app->mailer->compose('confirmEmail', ['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;
 }
开发者ID:aversilov,项目名称:singree-bboard,代码行数:23,代码来源:SignupForm.php

示例12: 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->status = User::STATUS_NOT_CONFIRMED;
         $user->generateAuthKey();
         $user->generateEmailConfirmToken();
         if ($user->save()) {
             $profile = new Profile();
             $profile->link('user', $user);
             Yii::$app->mailer->compose(['text' => '@app/modules/user/mails/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;
 }
开发者ID:CNeverDie,项目名称:CommentSG,代码行数:24,代码来源:SignupForm.php

示例13: 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->status = User::STATUS_WAIT;
         $user->generateAuthKey();
         $user->generateEmailConfirmToken();
         if ($user->save()) {
             $auth = Yii::$app->authManager;
             $authorRole = $auth->getRole('author');
             $auth->assign($authorRole, $user->getId());
             Yii::$app->mailer->compose(['text' => '@app/modules/user/mails/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;
 }
开发者ID:loop69,项目名称:yii2-rabbit-burrow,代码行数:25,代码来源:SignupForm.php

示例14: successCallback

 /**
  * Success callback for social networks authentication
  * @param $client
  * @throws ErrorException
  * @throws \yii\base\ExitException
  */
 public function successCallback($client)
 {
     $model = AuthClientHelper::findUserByService($client);
     if (is_object($model) === false) {
         // user not found, retrieve additional data
         $client = AuthClientHelper::retrieveAdditionalData($client);
         $attributes = AuthClientHelper::mapUserAttributesWithService($client);
         // check if it is anonymous user
         if (Yii::$app->user->isGuest === true) {
             $model = new User(['scenario' => 'registerService']);
             $security = Yii::$app->security;
             $model->setAttributes($attributes['user']);
             $model->status = User::STATUS_ACTIVE;
             if (empty($model->username) === true) {
                 // if we doesn't have username - generate unique random temporary username
                 // it will be needed for saving purposes
                 $model->username = $security->generateRandomString(18);
                 $model->username_is_temporary = 1;
             }
             $model->setPassword($security->generateRandomString(16));
             $model->generateAuthKey();
             if ($model->save() === false) {
                 if (isset($model->errors['username'])) {
                     // regenerate username
                     $model->username = $security->generateRandomString(18);
                     $model->username_is_temporary = 1;
                     $model->save();
                 }
                 if (isset($model->errors['email'])) {
                     // empty email
                     $model->email = null;
                     $model->save();
                 }
                 if (count($model->errors) > 0) {
                     throw new ErrorException(Yii::t('app', "Temporary error signing up user"));
                 }
             }
         } else {
             // non anonymous - link to existing account
             /** @var \app\modules\user\models\User $model */
             $model = Yii::$app->user->identity;
         }
         $service = new UserService();
         $service->service_type = $client->className();
         $service->service_id = '' . $attributes['service']['service_id'];
         $service->user_id = $model->id;
         if ($service->save() === false) {
             throw new ErrorException(Yii::t('app', "Temporary error saving social service"));
         }
     } elseif (Yii::$app->user->isGuest === false) {
         // service exists and user logged in
         // check if this service is binded to current user
         if ($model->id != Yii::$app->user->id) {
             throw new ErrorException(Yii::t('app', "This service is already binded to another user"));
         } else {
             throw new ErrorException(Yii::t('app', 'This service is already binded.'));
         }
     }
     TagDependency::invalidate(Yii::$app->cache, ['Session:' . Yii::$app->session->id]);
     Yii::$app->user->login($model, 86400);
     if ($model->username_is_temporary == 1 || empty($model->email)) {
         // show post-registration form
         $this->layout = $this->module->postRegistrationLayout;
         $model->setScenario('completeRegistration');
         echo $this->render('post-registration', ['model' => $model]);
         Yii::$app->end();
         return;
     }
 }
开发者ID:heartshare,项目名称:dotplant2,代码行数:75,代码来源:UserController.php


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