5 public $defaultAction =
'recovery';
15 $form->attributes = @$_POST[
'UserChangePassword'];
17 if (isset($_POST[
'ajax'])) {
18 echo CActiveForm::validate($form);
22 if ($form->validate()) {
23 $user =
User::model()->notsafe()->findByAttributes(array(
'email' => @$_POST[
'email']));
24 if (!isset($user) || $user->activkey != @$_POST[
'activkey']) {
25 $form->addError(
'password',
'Active key is expired');
29 if (!$form->hasErrors()) {
30 $user->password = Yii::app()->controller->module->encrypting($form->password);
31 $user->activkey = Yii::app()->controller->module->encrypting(microtime() . $form->password);
33 Yii::app()->user->setFlash(
'recoveryMessage',
UserModule::t(
"New password is saved."));
35 Yii::app()->user->setState(
'UserChangePassword', array(
'attributes' => $form->attributes,
'errors' => $form->getErrors()));
37 if (isset($_GET[
'return_url'])) {
38 $this->redirect($_GET[
'return_url']);
41 $this->redirect(Yii::app()->getModule(
'user')->recoveryChangePasswordUrl);
50 if (Yii::app()->user->isGuest) {
51 if (isset($_POST[
'UserRecoveryForm'])) {
52 $form->attributes = $_POST[
'UserRecoveryForm'];
53 if ($form->validate()) {
54 $user =
User::model()->with(
'account')->notsafe()->findbyPk($form->user_id);
56 Yii::app()->user->setFlash(
'recoveryMessage',
UserModule::t(
"You used TPA for logged in. You can not recovery password"));
58 $activation_url = $this->_getChangePasswordUrl(array(
"activkey" => $user->activkey,
"email" => $user->email));
59 $subject =
UserModule::t(
"You have requested the password recovery site {site_name}",
61 '{site_name}' => Yii::app()->name,
63 $message = $this->renderMail(
'/mail_templates/recovery', $subject, array(
'activation_url' => $activation_url));
67 array(
new EmailRecipient($user->email, $this->module->passwordForgottenEmail,
'',
true))
69 Yii::app()->notificationManager->notifyAbout($notification);
70 Yii::app()->user->setFlash(
'recoveryMessage',
UserModule::t(
"Please check your email. An instruction was sent to your email address."));
73 Yii::app()->user->setState(
'UserRecoveryForm', array(
'attributes' => $form->attributes,
'errors' => $form->getErrors()));
77 Yii::app()->user->setFlash(
'recoveryMessage',
UserModule::t(
"Please log out."));
80 if (isset($_REQUEST[
'return_url'])) {
81 $this->redirect($_REQUEST[
'return_url']);
83 $this->render(
'recovery', array(
'form' => $form));
87 private function _getChangePasswordUrl($params)
89 if (preg_match(
'/.+\.(php|html)$/', $this->module->recoveryChangePasswordUrl)) {
90 return $this->createAbsoluteUrl($this->module->recoveryChangePasswordUrl .
'?' . http_build_query($params));
92 return $this->createAbsoluteUrl($this->module->recoveryChangePasswordUrl, $params);