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


PHP UserAccount::setPassword方法代码示例

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


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

示例1: resetPassword

 /**
  * Resets user's password and send it to email
  * @param UserAccount $user
  */
 public function resetPassword(UserAccount $user)
 {
     if ($user->status != UserAccount::STATUS_ACTIVE) {
         if (!$this->allowActivationOnPasswordReset) {
             throw new CException('Can\'t reset password for inactive users.');
         } else {
             $identity = Identity::model()->findByAttributes(array('user_id' => $user->id, 'type' => Identity::TYPE_EMAIL, 'status' => Identity::STATUS_NEED_CONFIRMATION));
             $identity->userIdentityConfirmation->confirm();
         }
     }
     $emailAddr = $user->getActiveEmail();
     $newPassword = $this->randomPassword();
     $user->setPassword($newPassword);
     $user->save(false, array('password'));
     $email = new YiiMailer('resetPassword', $data = array('newPassword' => $newPassword, 'description' => $description = 'Password reset'));
     $email->setSubject($description);
     $email->setTo($emailAddr);
     $email->setFrom(Yii::app()->params['noreplyAddress'], Yii::app()->name, FALSE);
     Yii::log('Sendign reset password mail to ' . $emailAddr);
     if ($email->send()) {
         Yii::log('Ok');
     } else {
         Yii::log('Failed');
         throw new CException('Failed to send the email');
     }
 }
开发者ID:vasiliy-pdk,项目名称:aes,代码行数:30,代码来源:UserAccountModule.php

示例2: run

 public function run()
 {
     $transaction = Yii::app()->db->beginTransaction();
     try {
         if ($this->data->validate()) {
             $user = new UserAccount();
             $user->setPassword($this->data->password);
             $user->status = UserAccount::STATUS_NEED_ACTIVATION;
             if (!$user->save()) {
                 throw new Exception("User registration failed. Cant save User row. Errors: " . var_export($user->getErrors(), true));
             }
             $identity = new Identity();
             $identity->user_id = $user->id;
             $identity->type = Identity::TYPE_EMAIL;
             $identity->status = Identity::STATUS_NEED_CONFIRMATION;
             $identity->identity = $this->data->email;
             if (!$identity->save()) {
                 throw new Exception("User registration failed. Can't save Identity. Errors: " . var_export($identity->getErrors(), true));
             }
             $profile = new Profile();
             $attributeNames = $profile->attributeNames();
             $attributes = $this->data->getAttributes($attributeNames);
             $profile->setAttributes($attributes, false);
             $profile->user_id = $user->id;
             if (!$profile->save()) {
                 throw new Exception("User registration failed. Can't save Profile. Errors: " . var_export($profile->getErrors(), true));
             }
             $this->afterRecordsCreated($user, $profile, $identity);
         } else {
             throw new Exception("Invalid registration data. Errors: " . var_export($this->data->getErrors(), true));
         }
     } catch (Exception $exc) {
         $transaction->rollback();
         throw $exc;
     }
     $transaction->commit();
     return true;
 }
开发者ID:vasiliy-pdk,项目名称:aes,代码行数:38,代码来源:UserRegistration.php


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