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); }
/** * Action ForgotPassword dùng để gửi email phục vụ việc đổi mật khẩu */ public function actionForgotPassword() { $model = new ForgotPasswordForm(); if (isset($_POST['ForgotPasswordForm'])) { $model->attributes = $_POST['ForgotPasswordForm']; // Validate username or email existed? if ($model->validate()) { // Delete old Code forgot password $model->user->activkey = $model->user->createCodeActivation(); $model->user->save(); // Create Code forgot password $codeForgotPassword = $model->user->activkey; if ($codeForgotPassword != '') { /** * @todo Change message email */ $strForgotPasswordUrl = $this->createAbsoluteUrl('/user/recovery/changepassword', array("code" => $codeForgotPassword, "email" => $model->user->email)); $strMsgHTML = "<a href='{$strForgotPasswordUrl}'>{$strForgotPasswordUrl}</a>"; Yii::import('application.extensions.phpmailer.HMailHelper'); HMailHelper::Send('Recovery Password', $strMsgHTML, array(array($model->user->email, ''))); // Notice Sent mail success $this->setRedirectOptions(array("title" => UserModule::t('Sent Mail Success'), "message" => UserModule::t('Access to the email to change your password!'))); $this->redirect(Yii::app()->user->loginUrl); } } } $this->render('forgotpassword', array('model' => $model)); }
/** * Displays the forgot password page */ public function actionForgotPassword() { $model = new ForgotPasswordForm(); // collect user input data if (isset($_POST['ForgotPasswordForm'])) { $model->attributes = $_POST['ForgotPasswordForm']; // validate user input and redirect to the previous page if valid if ($model->validate()) { $user = User::model()->find('email = "' . $model->email . '"'); if ($user === null) { $this->render('message', array('title' => 'Error', 'message' => 'There is no account with that email address.')); } else { $password = $this->createRandomPassword(); $user->password = $user->createHash($password); $user->save(); if ($this->emailNewPassword($password, $user)) { $this->render('message', array('title' => 'New Password Sent', 'message' => 'We have changed your password and emailed it to you.')); } else { $this->render('message', array('title' => 'Password Reset Error', 'message' => 'An error has occurred while resetting your password')); } } } else { $this->render('forgotpassword', array('model' => $model)); } } else { $this->render('forgotpassword', array('model' => $model)); } }
public function actionForgotPassword() { $this->pageTitle = 'Password Recovery'; $model = new ForgotPasswordForm(); $model_class_name = $model->getClassName(); if (isset($_POST[$model_class_name])) { $model->attributes = $_POST[$model_class_name]; if ($model->validate()) { Yii::app()->user->setFlash('success', $model->success_message); $this->refresh(); } } $this->render('forgotPassword', array('model' => $model)); }
public function actionForgot() { $model = new ForgotPasswordForm(); if (isset($_POST['ForgotPasswordForm'])) { $model->attributes = $_POST['ForgotPasswordForm']; //$this->refresh(); if ($model->validate()) { $tempPassword = Randomness::randomString(16, true); $model = User::model()->findByAttributes(array('email' => $model->email)); $model->isNewPassword = true; $model->password = $tempPassword; if ($model->save()) { //use 'passwordrest' view from views/mail $mail = new YiiMailer('passwordReset', array('tempPassword' => $tempPassword)); //$mail->setSmtp('smtp.gmail.com', 465, 'ssl', true, '*****@*****.**', 'your_password'); //render HTML mail, layout is set from config file or with $mail->setLayout('layoutName') //$mail->render();smtp.secureserver.net $mail->IsSMTP(); $mail->Host = 'smtp.teksavvy.com'; //$mail->SMTPAuth = true; //$mail->Host = 'smtpout.secureserver.net'; $mail->Port = 25; //$mail ->Username ='******'; //$mail -> Password ='******'; //set properties as usually with PHPMailer $mail->From = Yii::app()->params['nonReplyEmail']; $mail->FromName = Yii::app()->name; $mail->Subject = Yii::app()->name . ' - Password Reset'; $mail->AddAddress(YII_DEBUG ? Yii::app()->params['adminEmail'] : $model->email); //$mail->AddAddress(YII_DEBUG?Yii::app()->params['adminEmail']); //$mail->AddAddress('*****@*****.**'); //send if ($mail->Send()) { $mail->ClearAddresses(); Yii::app()->user->setFlash('success-', Yii::t('app', 'msg.success.password_reset')); } else { Yii::app()->user->setFlash('error-', 'Error while sending email: ' . $mail->ErrorInfo); } $this->refresh(true); } } } $this->render('application.modules.account.views.common.forgot', array('model' => $model)); }
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 actionResetPassword() { $id = Yii::app()->request->getParam('id'); $key = Yii::app()->request->getParam('key'); $model = Users::model()->findByPk((int) $id); if ($model !== null && $key == ForgotPasswordForm::generateKey($model)) { $pass = ActiveRecord::randString(6); $model->password_hash = md5($pass); $model->temp_password = $pass; $model->update(); $name = $model->first_name . ' ' . $model->last_name; $login_link = '<a href="' . Yii::app()->createAbsoluteUrl("admin/site/login") . '">' . Yii::app()->createAbsoluteUrl("admin/site/login") . '</a>'; $aBody = array('{NAME}' => $name, '{PASSWORD}' => $model->temp_password, '{LINK_LOGIN}' => $login_link); if (CmsEmail::sendmail(2, array(), $aBody, $model->email)) { Yii::app()->user->setFlash("success", "An email has sent to: {$model->email}. Please check email to get new password."); } else { $model->addError('email', 'Can not send email to: ' . $model->email); } } else { Yii::log('Invalid request. Please do not repeat this request again.'); throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.'); } $this->render('ResetPassword', array('model' => $model)); }
/** Retrieve a password for a user * @access public * @return void */ public function forgottenAction() { if ($this->_auth->getIdentity()) { $this->getFlash()->addMessage('You are already logged in.'); $this->_redirect('/users'); } $form = new ForgotPasswordForm(); $this->view->form = $form; if ($this->getRequest()->isPost() && $form->isValid($this->_request->getPost())) { if ($form->isValid($form->getValues())) { $results = $this->_users->findUser($form->getValue('email'), $form->getValue('username')); if ($results) { $length = 6; $newKey = ""; // define possible characters $possible = "0123456789bcdfghjkmnpqrstvwxyz"; $i = 0; // add random characters to $password until $length is reached while ($i < $length) { // pick a random character from the possible ones $char = substr($possible, mt_rand(0, strlen($possible) - 1), 1); // we don't want this character if it's already in the password if (!strstr($newKey, $char)) { $newKey .= $char; $i++; } } $updatesdata = array('activationKey' => $newKey); $to = array(array('email' => $form->getValue('email'), 'name' => $results[0]['fullname'])); $assignData = array_merge($results[0], array('activationKey' => $newKey), $form->getValues()); $this->_helper->mailer($assignData, 'forgottenPassword', $to); $where = array(); $where[] = $this->_users->getAdapter()->quoteInto('username = ?', (string) $form->getValue('username')); $where[] = $this->_users->getAdapter()->quoteInto('email = ?', (string) $form->getValue('email')); $this->_users->update($updatesdata, $where); $assignData = array_merge($updatesdata, $form->getValues()); $this->getFlash()->addMessage('Please check your email'); $this->_redirect('/users/account/resetpassword'); } else { $this->getFlash()->addMessage('Either your email address/or username is incorrect.'); } } else { $this->getFlash()->addMessage('You have not filled in the form correctly'); } } }
public function actionForgotPassword() { if (!Yii::app()->user->isGuest) { $this->redirect('/home'); } $model = new ForgotPasswordForm(); if (isset($_POST) && isset($_POST['ForgotPasswordForm'])) { $model->attributes = $_POST['ForgotPasswordForm']; if ($model->validate()) { // Generate Password here and redirect $tempPass = SecurityUtils::generateRandomString(8); $user = UserCredentials::model()->find('email_id=:email', array(':email' => $model->email)); if ($user) { $user->salt = SecurityUtils::generateSalt($user->email_id); $user->password = SecurityUtils::encryptPassword($tempPass, $user->salt); if ($user->save()) { $data['temp_password'] = $tempPass; $data['user'] = $user->id; EmailApi::sendEmail($model->email, "ACCOUNT.RESET.PASSWORD", $data); Yii::app()->user->setFlash('success', "We have sent you a new password to your email.\n\t\t\t\t\t\t<br/> Please add " . Yii::app()->params['adminEmail'] . " to your whitelist."); $this->redirect('/home'); } } } } $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.');
/** Retrieve a password */ public function forgottenAction() { if ($this->_auth->getIdentity()) { $this->_flashMessenger->addMessage('You are already logged in, reset your password if you have forgotten it!'); $this->_redirect('/users'); } $form = new ForgotPasswordForm(); $this->view->form = $form; if ($this->getRequest()->isPost() && $form->isValid($this->_request->getPost())) { if ($form->isValid($form->getValues())) { $email = $formData['email']; $username = $formData['username']; $results = $this->_users->findUser($form->getValue('email'), $form->getValue('username')); if ($results) { $length = 6; $password = ""; // define possible characters $possible = "0123456789bcdfghjkmnpqrstvwxyz"; $i = 0; // add random characters to $password until $length is reached while ($i < $length) { // pick a random character from the possible ones $char = substr($possible, mt_rand(0, strlen($possible) - 1), 1); // we don't want this character if it's already in the password if (!strstr($password, $char)) { $password .= $char; $i++; } } $updatesdata = array('password' => SHA1($this->_helper->config->auth->salt . $password)); $to = array(array('email' => $form->getValue('email'), 'name' => $results[0]['fullname'])); $assignData = array_merge($results[0], array('password' => $password), $form->getValues()); $this->_helper->mailer($assignData, 'forgottenPassword', $to); $where = array(); $where[] = $this->_users->getAdapter()->quoteInto('username = ?', (string) $username); $where[] = $this->_users->getAdapter()->quoteInto('email = ?', (string) $email); $this->_users->update($updatesdata, $where); $assignData = array_merge($updatesdata, $form->getValues()); $this->_flashMessenger->addMessage('A new password has been sent to you'); $this->_redirect('/users/'); } else { $this->_flashMessenger->addMessage('Either your email address/or username is incorrect.'); } } else { $this->_flashMessenger->addMessage('You have not filled in the form correctly. Please check the error messages below.'); } } }
public function actionForgotPassword() { $form = new ForgotPasswordForm(); // collect user input data if (isset($_POST['ForgotPasswordForm'])) { $form->attributes = $_POST['ForgotPasswordForm']; if ($form->validate()) { $user = User::model()->findByAttributes(array('username' => $form->username)); //$password = $user->password; if ($user == null) { Yii::app()->user->setFlash('fail', 'The email address doesn\'t exist in the database'); $form = new ForgotPasswordForm(); } else { $encryptKey = $user->username . Yii::app()->params['divider'] . time(); $encryptURL = $user->encryptLink($encryptKey); $user->user_key = $encryptURL; $user->save(false); Yii::app()->user->setFlash('success', 'Forgot key generated'); $form = new ForgotPasswordForm(); } } } // display the forgot password form $this->render('forgotpassword', array('model' => $form)); }
public function actionSendMailResetPassword() { if (isset($_POST['ForgotPasswordForm'])) { $model = new ForgotPasswordForm(); $model->attributes = $_POST['ForgotPasswordForm']; if ($model->validate()) { $modelBarcode = new UserBarcode(); $modelBarcode->id = UserBarcode::model()->getMaxId() + 1; $modelEmailTemplate = EmailTemplate::model()->findEMailTempalte('User Reset Password'); $modelUser = User::model()->findByAttributes(array('email' => $model->emailReset)); $modelBarcode->barcode = Yii::app()->extraFunctions->randomString(32); if ($modelEmailTemplate !== NULL && $modelUser !== NULL) { $description = $modelEmailTemplate->description; $subject = $modelEmailTemplate->subject; $variables = array('{link}' => CHtml::link(Yii::app()->createAbsoluteUrl('site/resetPassword', array('barcodeId' => $modelBarcode->id)), Yii::app()->createAbsoluteUrl('site/resetPassword', array('barcodeId' => $modelBarcode->id))), '{barcode}' => $modelBarcode->barcode); $final_array = Yii::app()->extraFunctions->emailSendArray($description, $variables); //replace varibles $send_mail_data = array('subject' => $subject, 'firstName' => ucwords($modelUser->first_name), 'content' => $final_array); $message = $this->renderPartial('_emailTemplate', $send_mail_data, true); //call a template view $result = Yii::app()->extraFunctions->sendEmail($modelUser->email, $subject, $message, $modelUser->first_name . ' ' . $modelUser->last_name); //send mail if ($result === TRUE) { $modelBarcode->userid = $modelUser->id; $modelBarcode->start_time = date('Y-m-d H:i:s'); $temp_startTime = Yii::app()->extraFunctions->getFormatDate($modelBarcode->start_time); $modelBarcode->end_time = Yii::app()->extraFunctions->getEndTime($temp_startTime, 1); $modelBarcode->action = 'resetPassword'; $modelBarcode->save(); } } else { Yii::app()->user->setFlash('error', Yii::t('backend', 'Your request failed. Please contact administrators.')); } $this->redirect(array('site/login')); } else { Yii::app()->user->setFlash('error', Yii::t('backend', 'Your email has not registered in our system.')); $this->redirect('login'); } } }
public function actionValidateForgetPassword() { $model = new ForgotPasswordForm(); if (isset($_POST['ForgotPasswordForm'])) { $model->attributes = $_POST['ForgotPasswordForm']; $email = $model->email; $user = FrontendUser::model()->findByAttributes(array('email' => $email)); if (!$model->validate()) { echo json_encode(array('status' => "fail", 'errors' => CHtml::error($model, 'email'))); Yii::app()->end(); } elseif (!$user) { echo json_encode(array('status' => "fail", 'errors' => 'Пользователь с таким e-mail не зарегистрирован')); Yii::app()->end(); } else { echo '{"status" : "ok"}'; Yii::app()->end(); } } echo '{status: "fail", errors: "Ошибка восстановления пароля"}'; }
public function actionForgotPassword() { $model = new ForgotPasswordForm(); if (isset($_POST['ForgotPasswordForm'])) { $model->attributes = $_POST['ForgotPasswordForm']; // validate user input and redirect to the previous page if valid if ($model->set_reset_token($this)) { $this->redirect(array('//login')); } } $this->render('forgot_password', array('model' => $model)); }