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); }
} 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.');