public function actionForgotPass() { $result = ApiModule::$defaultSuccessResponse; $this->checkRequest(); $q = $this->q; $this->checkRequiredParams($q, array('email')); $model = new ForgotPasswordForm(); $model->email = trim($q->email); if ($model->validate()) { //check Email $criteria = new CDbCriteria(); $criteria->compare('t.email_not_login', $model->email); $criteria->compare('t.role_id', ROLE_AGENT); $mUser = Users::model()->find($criteria); if (!$mUser) { $model->addError('email', 'Email does not exist.'); } elseif ($mUser->status == STATUS_ACTIVE) { $password = substr(uniqid(rand(), 1), 1, 10); $pass_en = md5($password); $mUser->password_hash = $pass_en; $mUser->temp_password = $password; $mUser->update(array('password_hash', 'temp_password')); SendEmail::forgotPassword($mUser, $password, ROLE_AGENT); $result['message'] = Yii::t('systemmsg', 'An email with your new password has been sent to "{email}". ' . 'Please check your inbox. If you do not receive the email, ' . 'please add "@properyinfo.sg" to your mailbox safe list and check your Junk/Spam mailbox.', array('{email}' => $mUser->email_not_login)); } else { $model->addError('email', 'Email does not exist.'); } } $result['record_error_key'] = array_keys($model->getErrors()); $result['record_error'] = $model->getErrors(); ApiModule::sendResponse($result); }
public function actionForgotPassword() { $model = new ForgotPasswordForm(); if (isset($_POST['ForgotPasswordForm'])) { $model->attributes = $_POST['ForgotPasswordForm']; if ($model->validate()) { //check Email $user = Users::model()->findByAttributes(array('email' => trim($model->email), 'application_id' => BE)); if (!$user) { $model->addError('email', 'Email does not exist.'); } else { $name = $user->first_name . ' ' . $user->last_name; $key = ForgotPasswordForm::generateKey($user); $forgot_link = '<a href="' . Yii::app()->createAbsoluteUrl('/admin/site/ResetPassword', array('id' => $user->id, 'key' => $key)) . '">' . Yii::app()->createAbsoluteUrl('/admin/site/ResetPassword', array('id' => $user->id, 'key' => $key)) . '</a>'; $aBody = array('{NAME}' => $name, '{USERNAME}' => $user->username, '{EMAIL}' => $user->email, '{LINK}' => $forgot_link); //public static function sendmail($iEmailTemplateID, $aSubject, $aBody, $sTo) if (CmsEmail::sendmail(1, array(), $aBody, $user->email)) { Yii::app()->user->setFlash("success", "An email has sent to: {$model->email}. Please check email to verify this action."); } else { $model->addError('email', 'Can not send email.'); } } } } $this->render('forgotPassword', array('model' => $model)); }
} catch (Exception $exc) { throw new CHttpException(404, 'Invalid request. Please do not repeat this request again.'); } } /** * @throws CHttpException * <Jason> * <*****@*****.**> * <Landlord forgot password> */ public function actionlandlord_forgot_password() { $this->pageTitle = 'Forgot Password - ' . Yii::app()->params['title']; try { if (Yii::app()->user->id) { $role_id = Yii::app()->user->role_id; switch ($role_id) { case ROLE_REGISTER_MEMBER: $this->redirect(Yii::app()->createAbsoluteUrl('member/member_profile/myprofile')); break; case ROLE_TENANT: $this->redirect(Yii::app()->createAbsoluteUrl('member/tenant/property')); break; case ROLE_LANDLORD: $this->redirect(Yii::app()->createAbsoluteUrl('member/landlord/property')); break; case ROLE_AGENT: $this->redirect(Yii::app()->createAbsoluteUrl('member/dashboard')); break; } } else { $model = new ForgotPasswordForm(); if (isset($_POST['ForgotPasswordForm'])) { $model->attributes = $_POST['ForgotPasswordForm']; if ($model->validate()) { //check Email $criteria = new CDbCriteria(); $criteria->compare('t.email_not_login', $model->email); $criteria->compare('t.role_id', ROLE_LANDLORD); $criteria->compare('t.application_id', FE); $mUser = Users::model()->find($criteria); if (!$mUser) { $model->addError('email', 'Email does not exist.'); } elseif ($mUser->status == STATUS_ACTIVE) { $password = substr(uniqid(rand(), 1), 1, 10); $pass_en = md5($password); $mUser->password_hash = $pass_en; $mUser->temp_password = $password; $mUser->update(array('password_hash', 'temp_password')); SendEmail::forgotPassword($mUser, $password, ROLE_LANDLORD); Yii::app()->user->setFlash('success', "An email with your new password has been sent to " . $mUser->email_not_login . "\r\r <br/>Please check your inbox.\r\r <br/>If you do not receive the email, please add \"@properyinfo.sg\" to your mailbox safe list and check your Junk/Spam mailbox."); if (isset($_POST['back'])) { $this->redirect(Yii::app()->createAbsoluteUrl('site/landlordlogin')); } } else { $model->addError('email', 'Email does not exist.');
public function actionNewPassword($key = false) { if ($key) { $user = User::model()->findByAttributes(array('recover_pwd_key' => $key)); if ($user && time() < strtotime($user->recover_pwd_expiration)) { $model = new NewPasswordForm(); if (isset($_POST['NewPasswordForm'])) { $model->attributes = $_POST['NewPasswordForm']; if ($model->validate()) { $user->password = $model->password; $user->recover_pwd_key = ''; $user->recover_pwd_expiration = date('Y-m-d h:i:s', time() - 1); if ($user->save()) { Yii::app()->user->setFlash('success', 'You have successfully changed your password. You may now use it to login to Present Value.'); } else { $model->addErrors($user->errors); } } } $this->render('newPassword', array('model' => $model)); } else { throw new CHttpException(404, 'Not found or this link already expired'); } } else { $model = new ForgotPasswordForm(); if (isset($_POST['ForgotPasswordForm'])) { $model->attributes = $_POST['ForgotPasswordForm']; if ($model->validate()) { $user = User::model()->findByAttributes(array('email' => $model->email)); if ($user) { Yii::app()->user->setFlash('success', 'You will receive an email shortly with instructions to create a new password.'); EmailManager::sendRecoveryPassword($user); $this->refresh(); } else { $model->addError('email', 'Email address not found'); } } } $this->render('recoveryPassword', array('model' => $model)); } }
public function actionNewPassword($key = false) { if ($key) { $user = FrontendUser::model()->findByAttributes(array('recover_pwd_key' => $key)); if ($user && time() < strtotime($user->recover_pwd_expiration)) { $model = new NewPasswordForm(); if (isset($_POST['NewPasswordForm'])) { $model->attributes = $_POST['NewPasswordForm']; if ($model->validate()) { $user->password = $model->password; $user->recover_pwd_key = ''; $user->recover_pwd_expiration = date('Y-m-d h:i:s', time() - 1); if ($user->save()) { echo '{"status": "ok"}'; } else { echo json_encode(array('status' => 'fail', 'errors' => CHtml::errorSummary($user))); } } else { echo json_encode(array('status' => 'fail', 'errors' => CHtml::errorSummary($model))); } } } else { throw new CHttpException(404, 'Not found or this link already expired'); } } else { $model = new ForgotPasswordForm(); if (isset($_POST['ForgotPasswordForm'])) { $model->attributes = $_POST['ForgotPasswordForm']; if ($model->validate()) { $user = FrontendUser::model()->findByAttributes(array('email' => $model->email)); if ($user) { Yii::app()->user->setFlash('success', 'Вы получите письмо с инструкциями как восстановить ваш пароль.'); EmailManager::sendRecoveryPassword($user); $this->refresh(); } else { $model->addError('email', 'Email address not found'); } } } $this->render('recoveryPassword', array('model' => $model)); } }