Esempio n. 1
0
 public function run($code)
 {
     $recovery = RecoveryPassword::model()->with('user')->find('code = :code', array(':code' => $code));
     if (!$recovery) {
         Yii::log(Yii::t('user', 'Код восстановления пароля {code} не найден!', array('{code}' => $code)), CLogger::LEVEL_ERROR, UserModule::$logCategory);
         Yii::app()->user->setFlash(YFlashMessages::ERROR_MESSAGE, Yii::t('user', 'Код восстановления пароля не найден! Попробуйте еще раз!'));
         $this->controller->redirect(array('/user/account/recovery'));
     }
     // автоматическое восстановление пароля
     if (Yii::app()->getModule('user')->autoRecoveryPassword) {
         $newPassword = Registration::model()->generateRandomPassword();
         $recovery->user->password = Registration::model()->hashPassword($newPassword, $recovery->user->salt);
         $transaction = Yii::app()->db->beginTransaction();
         try {
             if ($recovery->user->save() && RecoveryPassword::model()->deleteAll('user_id = :user_id', array(':user_id' => $recovery->user->id))) {
                 $transaction->commit();
                 $emailBody = $this->controller->renderPartial('application.modules.user.views.email.passwordAutoRecoverySuccessEmail', array('model' => $recovery->user, 'password' => $newPassword), true);
                 Yii::app()->mail->send(Yii::app()->getModule('user')->notifyEmailFrom, $recovery->user->email, Yii::t('user', 'Успешное восстановление пароля!'), $emailBody);
                 Yii::app()->user->setFlash(YFlashMessages::NOTICE_MESSAGE, Yii::t('user', 'Новый пароль отправлен Вам на email!'));
                 Yii::log(Yii::t('user', 'Успешное восстановление пароля!'), CLogger::LEVEL_ERROR, UserModule::$logCategory);
                 $this->controller->redirect(array('/user/account/login'));
             }
         } catch (CDbException $e) {
             $transaction->rollback();
             Yii::app()->user->setFlash(YFlashMessages::ERROR_MESSAGE, Yii::t('user', 'Ошибка при смене пароля!'));
             Yii::log(Yii::t('user', 'Ошибка при автоматической смене пароля {error}!', array('{error}' => $e->getMessage())), CLogger::LEVEL_ERROR, UserModule::$logCategory);
             $this->controller->redirect(array('/user/account/recovery'));
         }
     }
     // выбор своего пароля
     $changePasswordForm = new ChangePasswordForm();
     // если отправили фому с новым паролем
     if (Yii::app()->request->isPostRequest && isset($_POST['ChangePasswordForm'])) {
         $changePasswordForm->setAttributes($_POST['ChangePasswordForm']);
         if ($changePasswordForm->validate()) {
             $transaction = Yii::app()->db->beginTransaction();
             try {
                 // смена пароля пользователя
                 $recovery->user->password = Registration::model()->hashPassword($changePasswordForm->password, $recovery->user->salt);
                 // удалить все запросы на восстановление для данного пользователя
                 if ($recovery->user->save() && RecoveryPassword::model()->deleteAll('user_id = :user_id', array(':user_id' => $recovery->user->id))) {
                     $transaction->commit();
                     Yii::app()->user->setFlash(YFlashMessages::NOTICE_MESSAGE, Yii::t('user', 'Пароль изменен!'));
                     Yii::log(Yii::t('user', 'Успешная смена пароля для пользоателя {user}!', array('{user}' => $recovery->user->id)), CLogger::LEVEL_INFO, UserModule::$logCategory);
                     $emailBody = $this->controller->renderPartial('application.modules.user.views.email.passwordRecoverySuccessEmail', array('model' => $recovery->user), true);
                     Yii::app()->mail->send(Yii::app()->getModule('user')->notifyEmailFrom, $recovery->user->email, Yii::t('user', 'Успешное восстановление пароля!'), $emailBody);
                     $this->controller->redirect(array('/user/account/login'));
                 }
             } catch (CDbException $e) {
                 $transaction->rollback();
                 Yii::app()->user->setFlash(YFlashMessages::ERROR_MESSAGE, Yii::t('user', 'Ошибка при смене пароля!'));
                 Yii::log(Yii::t('Ошибка при смене пароля {error}!', array('{error}' => $e->getMessage())), CLogger::LEVEL_ERROR, UserModule::$logCategory);
                 $this->controller->redirect(array('/user/account/recovery'));
             }
         }
     }
     $this->controller->render('changePassword', array('model' => $changePasswordForm));
 }
Esempio n. 2
0
 public function run()
 {
     $form = new RecoveryForm();
     if (Yii::app()->request->isPostRequest && isset($_POST['RecoveryForm'])) {
         $form->setAttributes($_POST['RecoveryForm']);
         if ($form->validate()) {
             $user = $form->getUser();
             // если пароль должен быть сгенерирован автоматически
             if (Yii::app()->getModule('user')->autoRecoveryPassword) {
                 $recovery = new RecoveryPassword();
                 $recovery->setAttributes(array('user_id' => $user->id, 'code' => $recovery->generateRecoveryCode($user->id)));
                 if ($recovery->save()) {
                     // отправить письмо с сылкой на сброс пароля
                     Yii::log(Yii::t('user', 'Заявка на автоматическое восстановление пароля.'), CLogger::LEVEL_INFO, UserModule::$logCategory);
                     Yii::app()->user->setFlash(YFlashMessages::NOTICE_MESSAGE, Yii::t('user', 'На указанный email отправлено письмо с инструкцией по восстановлению пароля!'));
                     $emailBody = $this->controller->renderPartial('passwordAutoRecoveryEmail', array('model' => $recovery), true);
                     Yii::app()->mail->send(Yii::app()->getModule('user')->notifyEmailFrom, $user->email, Yii::t('user', 'Восстановление пароля!'), $emailBody);
                     $this->controller->redirect(array('/user/account/login'));
                 } else {
                     Yii::log(Yii::t('user', 'Ощибка при создании заявки на автоматическое восстановление пароля'), CLogger::LEVEL_ERROR, UserModule::$logCategory);
                     Yii::app()->user->setFlash(YFlashMessages::ERROR_MESSAGE, Yii::t('user', 'При восстановлении пароля произошла ошибка! Повторите попытку позже!!!'));
                     $this->controller->redirect(array('/user/account/recovery'));
                 }
             } else {
                 $recovery = new RecoveryPassword();
                 $recovery->setAttributes(array('user_id' => $user->id, 'code' => $recovery->generateRecoveryCode($user->id)));
                 if ($recovery->save()) {
                     Yii::log(Yii::t('user', 'Заявка на восстановление пароля.'), CLogger::LEVEL_INFO, UserModule::$logCategory);
                     Yii::app()->user->setFlash(YFlashMessages::NOTICE_MESSAGE, Yii::t('user', 'На указанный email отправлено письмо с инструкцией по восстановлению пароля!'));
                     // отправить email уведомление
                     $emailBody = $this->controller->renderPartial('passwordRecoveryEmail', array('model' => $recovery), true);
                     Yii::app()->mail->send(Yii::app()->getModule('user')->notifyEmailFrom, $user->email, Yii::t('user', 'Восстановление пароля!'), $emailBody);
                     $this->controller->redirect(array('/user/account/recovery'));
                 } else {
                     Yii::app()->user->setFlash(YFlashMessages::ERROR_MESSAGE, Yii::t('user', 'При восстановлении пароля произошла ошибка!'));
                     Yii::log($e->getMessage(), CLogger::LEVEL_ERROR, UserModule::$logCategory);
                     $this->controller->redirect(array('/user/account/recovery'));
                 }
             }
         }
     }
     $this->controller->render('recovery', array('model' => $form));
 }
Esempio n. 3
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  */
 public function loadModel()
 {
     if ($this->_model === null) {
         if (isset($_GET['id'])) {
             $this->_model = RecoveryPassword::model()->findbyPk($_GET['id']);
         }
         if ($this->_model === null) {
             throw new CHttpException(404, 'The requested page does not exist.');
         }
     }
     return $this->_model;
 }
Esempio n. 4
0
 public function actionRecovery()
 {
     $form = new UserRecoveryForm();
     /*if(!Yii::app()->user->id){ #tiene que estár logeado el jefe
     			$this->redirect(Yii::app()->controller->module->returnUrl);
     		}else{*/
     $email = isset($_GET['email']) ? $_GET['email'] : '';
     $activkey = isset($_GET['activkey']) ? $_GET['activkey'] : '';
     if ($email && $activkey) {
         $form2 = new UserChangePassword();
         $find = User::model()->notsafe()->findByAttributes(array('email' => $email));
         if (isset($find) && $find->activkey == $activkey) {
             if (isset($_POST['UserChangePassword'])) {
                 $form2->attributes = $_POST['UserChangePassword'];
                 if ($form2->validate()) {
                     $find->password = Yii::app()->controller->module->encrypting($form2->password);
                     $find->activkey = Yii::app()->controller->module->encrypting(microtime() . $form2->password);
                     if ($find->status == 0) {
                         $find->status = 1;
                     }
                     $find->save();
                     Yii::app()->user->setFlash('success', UserModule::t("New password is saved."));
                     $registro = RecoveryPassword::model()->findByAttributes(array('email' => $email));
                     $registro->delete();
                     #$this->redirect(Yii::app()->controller->module->recoveryUrl);
                     $this->redirect(array('/RecoveryPassword/index'));
                 }
             }
             $this->render('changepassword', array('model' => $form2));
         } else {
             Yii::app()->user->setFlash('error', UserModule::t("Incorrect recovery link."));
             $this->redirect(Yii::app()->controller->module->recoveryUrl);
         }
     } else {
         if (isset($_POST['UserRecoveryForm'])) {
             $form->attributes = $_POST['UserRecoveryForm'];
             if ($form->validate()) {
                 $user = User::model()->notsafe()->findbyPk($form->user_id);
                 $activation_url = 'http://' . $_SERVER['HTTP_HOST'] . $this->createUrl(implode(Yii::app()->controller->module->recoveryUrl), array("activkey" => $user->activkey, "email" => $user->email));
                 $activation_url = 'http://' . $_SERVER['HTTP_HOST'] . $this->createUrl('/user/recovery/recovery', array("activkey" => $user->activkey, "email" => $user->email));
                 ##
                 $recoveryPass = new RecoveryPassword();
                 $recoveryPass->idUser = $user->id;
                 $recoveryPass->email = $user->email;
                 $recoveryPass->link = $activation_url;
                 $recoveryPass->save();
                 $this->redirect(array('Recovery/hecho'));
                 /*$subject = UserModule::t("You have requested a password recovery of {site_name}",
                  					array(
                  						'{site_name}'=>Yii::app()->name,
                  					));
                  			$message = UserModule::t("You have requested our password recovery services. To receive a new password, go to {activation_url}. Sincerely, Team of {site_name}",
                  					array(
                  						'{site_name}'=>Yii::app()->name,
                  						'{activation_url}'=>$activation_url,
                  					));
                 	
                  			UserModule::sendMail($user->email,$subject,$message);*/
                 ##
                 #Yii::app()->user->setFlash('info',UserModule::t("Please check your email. Further instructions are sent to your email address."));
                 #$this->refresh();
             }
         }
         $this->render('recovery', array('model' => $form));
     }
     #}
 }
Esempio n. 5
0
" class="btn btn-xs btn-default">
									VER
								</a>
							</span>
						</div>
					</div>
				</div>
				<div class="col-md-12">
					<div class="info-box bg-yellow">
						<span class="info-box-icon">
							<i class="fa fa-key"></i>
						</span>
						<div class="info-box-content">
							<span class="info-box-text">Solicitudes de restauración de contraseña</span>
							<span class="info-box-number"><?php 
$count = RecoveryPassword::getNum($datos->profile->idDepartamento);
echo $count;
?>
</span>
							<span class="progress-description">
								<a href="<?php 
echo Yii::app()->createUrl('recoveryPassword/index');
?>
" class="btn btn-xs btn-default">
									VER
								</a>
							</span>
						</div>
					</div>
				</div>
			</div>
Esempio n. 6
0
</p>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <b>Departamento:</b><br>
                                        <p><?php 
echo $model->profile->depto->nombre_departamento;
?>
</p>
                                    </td>
                                </tr>
                                <tr class="text-center">
                                    <td>
                                        <?php 
$solicitudDeContrasena = RecoveryPassword::model()->find("idUser="******"<?php 
    echo $solicitudDeContrasena->link;
    ?>
" class="btn btn-block btn-social btn-default">
                                                <i class="fa fa-unlock-alt"></i> Restaurar Contraseña
                                            </a>
                                        <?php 
}