コード例 #1
0
ファイル: User.php プロジェクト: AnduZhang/nws
 public function register()
 {
     if ($this->getIsNewRecord() == false) {
         throw new \RuntimeException('Calling "' . __CLASS__ . '::' . __METHOD__ . '" on existing user');
     }
     if ($this->module->enableConfirmation == false) {
         $this->confirmed_at = time();
     }
     if ($this->module->enableGeneratingPassword) {
         $this->password = Password::generate(8);
     }
     $this->trigger(self::USER_REGISTER_INIT);
     if ($this->save()) {
         $this->trigger(self::USER_REGISTER_DONE);
         if ($this->module->enableConfirmation) {
             $token = \Yii::createObject(['class' => Token::className(), 'type' => Token::TYPE_CONFIRMATION]);
             $token->link('user', $this);
             $this->mailer->sendConfirmationMessage($this, $token);
         } else {
             \Yii::$app->user->login($this);
         }
         if ($this->module->enableGeneratingPassword) {
             $this->mailer->sendWelcomeMessage($this);
         }
         \Yii::$app->session->setFlash('info', $this->getFlashMessage());
         \Yii::getLogger()->log('User has been registered', Logger::LEVEL_INFO);
         return true;
     }
     \Yii::getLogger()->log('An error occurred while registering user account', Logger::LEVEL_ERROR);
     return false;
 }
コード例 #2
0
ファイル: User.php プロジェクト: singleso/singleso
 /** @inheritdoc */
 public function create()
 {
     // Create a random password, minimum length, but better than most users create.
     if ($this->password === null) {
         $this->password = Password::generate(static::$passwordLengthMin);
     }
     return parent::create();
 }
コード例 #3
0
 /**
  * Creates a new User model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $user = Yii::createObject(['class' => User::className(), 'scenario' => 'create']);
     if ($user->load(Yii::$app->request->post())) {
         /*            $coordenadas = sysconfigs::getCoordinates($user->direccion);
                     $user->latitud = $coordenadas['latitud'];
                     $user->longitud = $coordenadas['longitud'];*/
         //generamos password
         $user->password = $user->password == null ? Password::generate(8) : $user->password;
         if ($user->save()) {
             $user->mailer->sendWelcomeMessage($user, null);
             return $this->redirect(['update', 'id' => $user->id]);
         } else {
             return $this->render('create', ['user' => $user]);
         }
     } else {
         return $this->render('create', ['user' => $user]);
     }
 }
コード例 #4
0
 /**
  * @inheritdoc
  */
 public function register()
 {
     if ($this->getIsNewRecord() == false) {
         throw new \RuntimeException('Calling "' . __CLASS__ . '::' . __METHOD__ . '" on existing user');
     }
     $this->confirmed_at = $this->module->enableConfirmation ? null : time();
     $this->password = $this->module->enableGeneratingPassword ? Password::generate(self::PASSWORD_MIN_LENGTH) : $this->password;
     $this->trigger(self::BEFORE_REGISTER);
     if (!$this->save()) {
         return false;
     }
     if ($this->module->enableConfirmation) {
         /** @var Token $token */
         $token = Yii::createObject(['class' => Token::className(), 'type' => Token::TYPE_CONFIRMATION]);
         $token->link('user', $this);
     }
     if ($this->module->enableConfirmation || $this->module->enableGeneratingPassword) {
         $this->mailer->sendWelcomeMessage($this, isset($token) ? $token : null);
     }
     $this->trigger(self::AFTER_REGISTER);
     return true;
 }
コード例 #5
0
ファイル: User.php プロジェクト: bokko79/servicemapp
 /**
  * This method is used to register new user account. If Module::enableConfirmation is set true, this method
  * will generate new confirmation token and use mailer to send it to the user.
  *
  * @return bool
  */
 public function temporary()
 {
     if ($this->getIsNewRecord() == false) {
         throw new \RuntimeException('Calling "' . __CLASS__ . '::' . __METHOD__ . '" on existing user');
     }
     $this->confirmed_at = $this->module->enableConfirmation ? null : time();
     $this->password = $this->module->enableGeneratingPassword ? \dektrium\user\helpers\Password::generate(8) : $this->password;
     $this->trigger(self::BEFORE_REGISTER);
     // echo '<pre>'; print_r($this); die();
     if (!$this->save()) {
         return false;
     }
     $this->trigger(self::AFTER_REGISTER);
     return true;
 }
コード例 #6
0
ファイル: User.php プロジェクト: damasco/yii2-user
 /**
  * This method is used to register new user account. If Module::enableConfirmation is set true, this method
  * will generate new confirmation token and use mailer to send it to the user.
  *
  * @return bool
  */
 public function register()
 {
     if ($this->getIsNewRecord() == false) {
         throw new \RuntimeException('Calling "' . __CLASS__ . '::' . __METHOD__ . '" on existing user');
     }
     $transaction = $this->getDb()->beginTransaction();
     try {
         $this->confirmed_at = $this->module->enableConfirmation ? null : time();
         $this->password = $this->module->enableGeneratingPassword ? Password::generate(8) : $this->password;
         $this->trigger(self::BEFORE_REGISTER);
         if (!$this->save()) {
             $transaction->rollBack();
             return false;
         }
         if ($this->module->enableConfirmation) {
             /** @var Token $token */
             $token = \Yii::createObject(['class' => Token::className(), 'type' => Token::TYPE_CONFIRMATION]);
             $token->link('user', $this);
         }
         $this->mailer->sendWelcomeMessage($this, isset($token) ? $token : null);
         $this->trigger(self::AFTER_REGISTER);
         $transaction->commit();
         return true;
     } catch (\Exception $e) {
         $transaction->rollBack();
         \Yii::warning($e->getMessage());
         return false;
     }
 }
コード例 #7
0
ファイル: SiteController.php プロジェクト: babagay/razzd
 /**
  * @return string
  * @throws \yii\base\InvalidConfigException
  */
 public function actionFogotPassword()
 {
     if (!\Yii::$app->user->isGuest) {
         $this->goHome();
     }
     $sended = $result = false;
     $model = \Yii::createObject(['class' => \frontend\models\RecoveryForm::className(), 'scenario' => 'request']);
     $isLoaded = $model->load(Yii::$app->request->post());
     if (Yii::$app->request->isPost && $isLoaded && $model->validate()) {
         /** @var Token $token */
         $password = \dektrium\user\helpers\Password::generate(6);
         if ($model->user->resetPassword($password)) {
             $sendTo = $model->user->email;
             $subject = "Razzd Password Recovery";
             $replyTo = isset(\Yii::$app->params['supportEmail']) ? \Yii::$app->params['supportEmail'] : "";
             $subject_internal = "Your Password was changed";
             $password = "******";
             $username = $model->user->username;
             $mailer = new \common\helpers\Mandrill($sendTo, $subject, $local_tpl_name = null, $sender = null, ['from_name' => '[Auto-generated]', 'reply_to' => $replyTo, 'mandrill_template_name' => 'forgotpassword', 'vars' => ['header' => $subject_internal, 'username' => $username, 'password' => $password]]);
             $result = $mailer->sendWithMandrillTemplate();
         }
         $mess = (string) $result;
         if ($result) {
             Yii::$app->session->setFlash('success', 'Your password has been changed.');
             $sended = true;
         } else {
             Yii::$app->session->setFlash('error', 'There is something wrong. Contact Support.');
         }
     }
     return $this->renderAjax('fogot', ['model' => $model, 'sended' => $sended]);
 }
コード例 #8
0
 /**
  * This method is used to create new user account. If password is not set, this method will generate new 8-char
  * password. After saving user to database, this method uses mailer component to send credentials
  * (username and password) to user via email.
  *
  * @return bool
  */
 public function create()
 {
     if ($this->getIsNewRecord() == false) {
         throw new \RuntimeException('Calling "' . __CLASS__ . '::' . __METHOD__ . '" on existing user');
     }
     //$this->RegisterDate = new Expression('NOW()');
     if (empty($this->Password)) {
         $this->Password = Password::generate(8);
     }
     $this->Password = $this->generatePasswordHash($this->Password);
     $this->trigger(self::BEFORE_CREATE);
     if ($this->save()) {
         $this->trigger(self::AFTER_CREATE);
         //$this->mailer->sendWelcomeMessage($this);
         \Yii::info('Зарегистрирован пользователь №' . $this->id . ': ' . \yii\helpers\Html::a($this->getFullName(true), ['/user/admin/update', 'id' => $this->ID]), 'info');
         return true;
     }
     \Yii::error('An error occurred while creating user account', self::className());
     \Yii::error(VarDumper::dumpAsString($this->errors), self::className());
     \Yii::error(VarDumper::dumpAsString($this->attributes), self::className());
     return false;
 }