コード例 #1
0
ファイル: AuthController.php プロジェクト: ankuradhey/laundry
 public function resetPasswordAction()
 {
     $request = $this->getRequest();
     //echo "inside function";
     $code = $request->getParam("code");
     if ($code) {
         $adminsMapper = new Application_Model_AdminsMapper();
         $admin = $adminsMapper->getAdminByResetCode($code);
         if (!$admin) {
             $this->view->hasMessage = true;
             $this->view->messageType = "danger";
             $this->view->message = "Invalid reset code";
         }
         if ($request->isPost()) {
             $password = $request->getParam("new_pass");
             $cpassword = $request->getParam("cpass");
             $errors = array();
             if (empty($password)) {
                 $errors[] = "New Password Should not be empty";
             }
             if (empty($cpassword)) {
                 $errors[] = "Confirm Password Should not be empty";
             }
             if ($password != $cpassword) {
                 $this->view->hasMessage = true;
                 $this->view->messageType = "danger";
                 $this->view->message = "Passwords doesn't match, Try again";
             } else {
                 $hashed_password = sha1($password);
                 if (count($errors) == 0) {
                     $admin->__set("hashed_password", $hashed_password);
                     $admin->__set("reset_code", "");
                     if ($adminsMapper->updateAdmin($admin)) {
                         $this->view->hasMessage = true;
                         $this->view->messageType = "success";
                         $this->view->message = "Password reset successful. <a href='" . $this->view->baseUrl() . "/admin/auth'>Click here</a> to login.";
                     } else {
                         $this->view->hasMessage = true;
                         $this->view->messageType = "danger";
                         $this->view->message = "Error while adding admin";
                     }
                 } else {
                     $errorString = "";
                     foreach ($errors as $error) {
                         $errorString .= $error . "<br/>";
                     }
                     $this->view->hasMessage = true;
                     $this->view->messageType = "danger";
                     $this->view->message = $errorString;
                 }
             }
         }
     }
 }
コード例 #2
0
 public function editAction()
 {
     try {
         //$admins = new Application_Model_Admins;
         $adminsMapper = new Application_Model_AdminsMapper();
         $request = $this->getRequest();
         $admin_form = new Application_Form_AdminForm();
         $admin_form->removeElement("hashed_password");
         $admin_form->removeElement("cpassword");
         $admin_form->removeElement("admin_email");
         $elements = $admin_form->getElements();
         $this->view->form = $admin_form;
         $admin_form_password = new Application_Form_AdminForm();
         $this->view->password_form = $admin_form_password;
         $admin_id = $request->getParam("id");
         $secure = new My_Secure();
         $id = $secure->decode($admin_id);
         $admin = $adminsMapper->getAdminById($id);
         $this->view->admin = $admin;
         foreach ($elements as $element) {
             $element->setValue($admin->__get($element->getName()));
         }
         if ($request->isPost()) {
             $request_type = $request->getParam("request_type", false);
             if ($request_type) {
                 if ($request_type == "edit") {
                     $params = $request->getParams();
                     if ($admin_form->isValid($params)) {
                         foreach ($params as $param => $value) {
                             $admin->__set($param, $value);
                         }
                         if ($adminsMapper->updateAdmin($admin)) {
                             $this->view->message = "Admin Updated successfully";
                             $this->view->hasMessage = true;
                             $this->view->messageType = "success";
                         } else {
                             $this->view->message = "Error occured while updating. Please try again";
                             $this->view->hasMessage = true;
                             $this->view->messageType = "danger";
                         }
                     } else {
                         $this->view->message = "Error occured while updating. Please fill form correctly";
                         $this->view->hasMessage = true;
                         $this->view->messageType = "danger";
                     }
                 } elseif ($request_type == "change_password") {
                     $pass = $request->getParam("hashed_password");
                     $cpaas = $request->getParam("cpassword");
                     $errors = array();
                     if (empty($pass)) {
                         $errors[] = "Password Should Not Be Empty";
                     }
                     if (empty($cpaas)) {
                         $errors[] = "Confirm Password Should Not Be Empty";
                     }
                     if ($pass != $cpaas) {
                         $this->view->hasMessage = true;
                         $this->view->messageType = "danger";
                         $this->view->message = "Password don't match";
                     } else {
                         $hashed_password = $admin->__get("hashed_password");
                         $hashed_password = sha1($pass);
                         if (count($errors) == 0) {
                             $admin->__set("hashed_password", $hashed_password);
                             if ($adminsMapper->updateAdmin($admin)) {
                                 $this->view->hasMessage = true;
                                 $this->view->messageType = "success";
                                 $this->view->message = "Password changed successfully";
                             } else {
                                 $this->view->hasMessage = true;
                                 $this->view->messageType = "danger";
                                 $this->view->message = "Error updating password. Try again";
                             }
                         } else {
                             $errorString = "";
                             foreach ($errors as $error) {
                                 $errorString .= $error . "<br/>";
                             }
                             $this->view->hasMessage = true;
                             $this->view->messageType = "danger";
                             $this->view->message = $errorString;
                         }
                     }
                 }
             }
         }
         $this->authorised = true;
     } catch (Exception $ex) {
         $this->authorised = false;
         $this->view->hasMessage = true;
         $this->view->messageType = "danger";
         $this->view->message = $ex->getMessage();
     }
 }