Пример #1
0
 public function actionIndex()
 {
     if (!user()->isGuest) {
         // Если авторизирован
         $this->redirect(array('/cabinet/default/index'));
     }
     $model = new ForgottenPasswordForm();
     if (isset($_POST['ForgottenPasswordForm'])) {
         $model->attributes = $_POST['ForgottenPasswordForm'];
         if ($model->validate()) {
             $cache = new CFileCache();
             $cache->init();
             $cacheData = array('hash' => md5(randomString(rand(10, 30)) . userIp() . time()), 'login' => $model->login, 'ls_id' => $model->gs_list[$model->gs_id]['login_id'], 'email' => $model->email);
             $cache->set($this->_cacheName . $cacheData['hash'], $cacheData, (int) config('forgotten_password.cache_time') * 60);
             notify()->forgottenPasswordStep1($model->email, array('hash' => $cacheData['hash']));
             user()->setFlash(FlashConst::MESSAGE_SUCCESS, Yii::t('main', 'На Email <b>:email</b> отправлены инструкции по восстановлению пароля.', array(':email' => $model->email)));
             $this->refresh();
         }
     }
     $this->render('//forgotten-password', array('model' => $model));
 }
 public function actionRecover()
 {
     // create ForgottenPasswordForm object
     $model = new ForgottenPasswordForm();
     // verify if ForgottenPasswordForm was used
     if (isset($_POST['ForgottenPasswordForm'])) {
         $model->attributes = $_POST['ForgottenPasswordForm'];
         // validate model
         if ($model->validate()) {
             // criteria object used to find all user data information
             $userCriteria = new CDbCriteria();
             $userCriteria->condition = "user_email = :user_email";
             $userCriteria->params = array(':user_email' => $model->user_email);
             $CountUser = Users::model()->count($userCriteria);
             $transaction = Yii::app()->db->beginTransaction();
             if ($CountUser > 0) {
                 $user = Users::model()->find($userCriteria);
                 // -- Password Generator
                 $vowels = 'aeiou';
                 $consonants = 'bcdfghjklmnpqrstvwxyz';
                 $password = '';
                 $alt = time() % 2;
                 for ($i = 0; $i < 10; $i++) {
                     if ($alt == 1) {
                         $password .= $consonants[rand() % strlen($consonants)];
                         $alt = 0;
                     } else {
                         $password .= $vowels[rand() % strlen($vowels)];
                         $alt = 1;
                     }
                 }
                 $user->user_password = md5($password);
                 if ($user->save(false)) {
                     $str = $this->renderPartial('//templates/users/PasswordChanged', array('userRequest' => $user->CompleteName, 'user_email' => $user->user_email, 'user_password' => $password, 'applicationName' => Yii::app()->name, 'applicationUrl' => "http://" . $_SERVER['SERVER_NAME'] . Yii::app()->request->baseUrl), true);
                     $subject = Yii::t('email', 'PasswordReset');
                     Yii::import('application.extensions.phpMailer.yiiPhpMailer');
                     $mailer = new yiiPhpMailer();
                     $mailer->Ready($subject, $str, array('name' => $user->CompleteName, 'email' => $user->user_email), Emails::PRIORITY_NORMAL);
                     Yii::app()->user->setFlash('PasswordSuccessChanged', Yii::t('site', 'PasswordSuccessChanged'));
                     $this->refresh();
                 } else {
                     throw new CException('Error #000001');
                 }
             } else {
                 throw new CException(Yii::t('site', 'EmailNotExist'));
             }
         }
     }
     $this->layout = 'login';
     $this->render('recover', array('model' => $model));
 }
Пример #3
0
 /**
  * Displays the forgotten password page
  */
 public function actionForgottenPassword()
 {
     if (!Yii::app()->user->isGuest) {
         $this->redirect(Yii::app()->homeUrl);
     }
     $model = new ForgottenPasswordForm();
     $User = null;
     $mailError = false;
     // collect user input data
     if (isset($_POST['ForgottenPasswordForm'])) {
         $model->scenario = 'changePassword';
         $model->attributes = $_POST['ForgottenPasswordForm'];
         // validate user input and redirect to the previous page if valid
         if ($model->validate()) {
             $User = $model->User;
             $User->password_retrieval_key = $User->generatePassword(50, 4);
             $User->update_time = new CDbExpression('NOW()');
             $User->update();
             $adminEmail = SnapUtil::config('boxomatic/adminEmail');
             $adminEmailFromName = SnapUtil::config('boxomatic/adminEmailFromName');
             $message = new YiiMailMessage('FoodBox password renewal');
             $message->view = 'forgottenPassword';
             $url = $this->createAbsoluteUrl('user/passwordReset', array('p' => $User->password_retrieval_key));
             //userModel is passed to the view
             $message->setBody(array('User' => $User, 'url' => $url), 'text/html');
             $message->addTo($User->email);
             $message->setFrom(array($adminEmail => $adminEmailFromName));
             if (!@Yii::app()->mail->send($message)) {
                 $mailError = true;
             }
         }
     }
     // display the login form
     $this->render('forgottenPassword', array('model' => $model, 'User' => $User, 'mailError' => $mailError));
 }