public function actionForgotPassword() { $objValidator = new helpers\Validation(); $params = array('email'); try { $isRequestValid = $objValidator->validateRequest($params); if ($isRequestValid) { $email = $this->_request->getPost('email'); $objUserAuthMdl = new \models\Users(); // check if user is valid or not $return = $objUserAuthMdl->resetPassword($email); if ($return === 1) { $this->_request->sendSuccessResponse('success', array()); } else { if ($return === -1) { $this->_request->sendErrorResponse(403, 403, 'User not found'); } else { if ($return === -2) { $this->_request->sendErrorResponse(404, 404, 'Error sending mail'); } else { $this->_request->sendErrorResponse(404, 404, 'oops!! something went wrong'); } } } } else { $this->_request->sendErrorResponse(403, 403, 'Request cannot be validated'); } } catch (\Exception $e) { echo $e->getMessage(); $this->_request->sendErrorResponse(404, 404, $e->getMessage()); } }
public function actionResetPassword() { $token = $this->_request->getParam('token'); $referrer = $this->_request->getParam('r'); $message = null; if ($this->_request->isPost()) { $newPassword = $this->_request->getParam('newpassword'); $confirmPassword = $this->_request->getParam('cnewpassword'); // check if new password is equal to the confirm password if ($newPassword == $confirmPassword && !empty($newPassword)) { // check if password matches the required criteria or not $isPatternMatched = preg_match('/^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[$@$!%*?&])[A-Za-z\\d$@$!%*?&]{9,15}$/', $newPassword); if ($isPatternMatched) { $objUserMdl = new \models\Users(); $isTokenValid = \R::findOne("users", "token=:t", array(':t' => $token)); // check of token is valid or not if ($isTokenValid) { $isPasswordReset = $objUserMdl->resetPassword($token, $newPassword); if ($isPasswordReset) { $referrerUrl = $this->_serverinfo->getHostFromRefferer($referrer); header("Location:{$referrerUrl}"); } } else { $message = "This token is not valid"; } } else { $message = "Please enter minimum 9 and maximum 15 characters at least 1 uppercase alphabet, 1 lowercase alphabet, 1 number and 1 special character"; } } else { $message = "New password and old password does not match or password is empty"; } } $viewData = array('message' => $message); $this->render('resetpassword', $viewData); }