コード例 #1
0
 public function indexAction()
 {
     try {
         $user_form = new Application_Form_UserForm();
         $this->view->form = $user_form;
         $usersMapper = new Application_Model_UsersMapper();
         $users = new Application_Model_Users();
         $request = $this->getRequest();
         if ($request->isPost()) {
             $request_type = $request->getParam("request_type", false);
             if ($request_type) {
                 if ($request_type == "add") {
                     $params = $request->getParams();
                     if ($user_form->isValid($params)) {
                         foreach ($params as $param => $value) {
                             if ($param == "hashed_password") {
                                 $value = sha1($value);
                             }
                             $users->__set($param, $value);
                         }
                         $users->__set("user_fb_id", "");
                         if ($usersMapper->addNewUser($users)) {
                             $this->view->message = "User added successfully";
                             $this->view->hasMessage = true;
                             $this->view->messageType = "success";
                         } else {
                             $this->view->message = "Error occured while adding. Please try again";
                             $this->view->hasMessage = true;
                             $this->view->messageType = "danger";
                         }
                     } else {
                         $this->view->message = "Error occured while Adding. Please fill form correctly";
                         $this->view->hasMessage = true;
                         $this->view->messageType = "danger";
                     }
                 } elseif ($request_type == "delete") {
                     $id = $request->getParam("id");
                     if ($usersMapper->deleteUserById($id)) {
                         $this->view->hasMessage = true;
                         $this->view->messageType = "success";
                         $this->view->message = "User deleted successfully.";
                     } else {
                         $this->view->hasMessage = true;
                         $this->view->messageType = "danger";
                         $this->view->message = "Error occured while deleting. Please try again.";
                     }
                 }
             }
         }
         $user = $usersMapper->getAllUsers();
         $this->view->users = $user;
         $this->authorised = true;
     } catch (Exception $ex) {
         $this->authorised = false;
         $this->view->hasMessage = true;
         $this->view->messageType = "danger";
         $this->view->message = $ex->getMessage();
     }
 }
コード例 #2
0
 public function registerAction()
 {
     $request = $this->getRequest();
     $usersMapper = new Application_Model_UsersMapper();
     $userWalletMapper = new Application_Model_UserWalletMapper();
     $userWallet = new Application_Model_UserWallet();
     $request_type = $request->getParam("request_type", FALSE);
     $referred_by = $request->getParam("refer", FALSE);
     if ($referred_by) {
         $user = $usersMapper->getUserByEmail($referred_by);
         $user_id = $user->__get("user_id");
     } else {
         $user_id = 0;
     }
     $this->view->user_id = $user_id;
     $usersMapper = new Application_Model_UsersMapper();
     $users = new Application_Model_Users();
     if ($request_type) {
         if ($request_type == "register") {
             $user_fname = $request->getParam("user_fname");
             $user_lname = $request->getParam("user_lname");
             $user_email = $request->getParam("user_email");
             $password = $request->getParam("hashed_password");
             $cpassword = $request->getParam("cpassword");
             $user_number = $request->getParam("user_number");
             $user_address = $request->getParam("user_address");
             $user_locality = $request->getParam("user_locality");
             $user_landmark = $request->getParam("user_landmark");
             $user_city = $request->getParam("user_city");
             $user_state = $request->getParam("user_state");
             $user_country = $request->getParam("user_country");
             $reference_email = $request->getParam("refer");
             $errors = array();
             if (empty($user_fname)) {
                 $errors[] = "First Name Should Not Be Empty";
             }
             if (empty($user_lname)) {
                 $errors[] = "Last Name Should Not Be Empty";
             }
             if (empty($user_email)) {
                 $errors[] = "Email Should Not Be Empty";
             }
             if (empty($password)) {
                 $errors[] = "Password Should Not Be EMpty";
             }
             if (empty($cpassword)) {
                 $errors[] = "Confirm Password Should Not Be Empty";
             }
             if (empty($user_number)) {
                 $errors[] = "Number Should Not Be Empty";
             }
             if (empty($user_address)) {
                 $errors[] = "Address Should Not Be Empty";
             }
             if (empty($user_city)) {
                 $errors[] = "City Should Not Be Empty";
             }
             if (empty($user_state)) {
                 $errors[] = "State Should Not Be Empty";
             }
             if (empty($user_country)) {
                 $errors[] = "Country Should Not Be Empty";
             }
             if ($password != $cpassword) {
                 $errors[] = "Password Did Not Match";
             }
             if ($user_number < 10 && $user_number > 10) {
                 $errors[] = "Phone Number Should Be of 10 Digits";
             }
             $emailValidator = new Zend_Validate_EmailAddress();
             if (!$emailValidator->isValid($user_email)) {
                 $errors[] = "Email address not valid";
             }
             $options = array("table" => "users", "field" => "user_email");
             $recordValidation = new Zend_Validate_Db_RecordExists($options);
             if ($recordValidation->isValid($user_email)) {
                 $errors[] = "Email address already in use";
             }
             $hashed_password = sha1($password);
             if (count($errors) == 0) {
                 $users->__set("user_fname", $user_fname);
                 $users->__set("user_lname", $user_lname);
                 $users->__set("user_email", $user_email);
                 $users->__set("user_number", $user_number);
                 $users->__set("hashed_password", $hashed_password);
                 $users->__set("user_address", $user_address);
                 if ($user_locality) {
                     $users->__set("user_locality", $user_locality);
                 } else {
                     $users->__set("user_locality", "");
                 }
                 if ($user_landmark) {
                     $users->__set("user_landmark", $user_landmark);
                 } else {
                     $users->__set("user_landmark", "");
                 }
                 $users->__set("user_city", $user_city);
                 $users->__set("user_state", $user_state);
                 $users->__set("user_country", $user_country);
                 $users->__set("user_fb_id", "");
                 if ($reference_email) {
                     $new_user = $usersMapper->getUserByEmail($reference_email);
                     if ($new_user) {
                         $users->__set("referred_by", $new_user->__get("user_id"));
                     }
                 }
                 $user_id = $usersMapper->addNewUser($users);
                 if ($reference_email) {
                     $new_user = $usersMapper->getUserByEmail($reference_email);
                     if ($new_user) {
                         $reference_by = $new_user->__get("user_id");
                         $userWallet->__set("user_id", $reference_by);
                         $userWallet->__set("entry_type", "CREDIT");
                         $userWallet->__set("entry_amount", "100");
                         $userWalletMapper->addNewUserWallet($userWallet);
                         $userWallet->__set("user_id", $user_id);
                         $userWalletMapper->addNewUserWallet($userWallet);
                     }
                 }
                 $subject = "Hi " . $user_fname . " " . $user_lname . ", Welcome to Laundry Wala";
                 $message = "Dear " . $user_fname . " " . $user_lname . ",<br/><br/>\n                            Greetings From LaundryWala.<br/><br/>\n                            Thanks for registering with us and choosing us as your preferred laundry service.</strong><br/><br/>\n                            We offer affordable and professional laundry service at the convenience of your doorstep.<br/><br/>\n                            Do login to our website www.laundrywala.co.in for more details about us.<br/><br/>\n                            Look forward to being of service to you.<br/><br/>\n                            Best regards,<br/><br/>\n                            Customer Care Team<br/><br/>\n                            LaundryWala<br/><br/>";
                 $result = $this->_newForgotPasswordNotification($user_email, $subject, $message);
                 $result1 = $this->_newForgotPasswordNotification("*****@*****.**", $subject, $message);
                 $sms = "Dear " . $user_fname . ", Welcome to LaundryWala. Do login to our website www.laundrywala.co.in for more details. Look forward to being of service to you. Regards, LaundryWala";
                 $sms_result = $this->_smsNotification($user_number, $sms);
                 if ($user_id && $result && $result1) {
                     $this->view->hasMessage = true;
                     $this->view->messageType = "success";
                     $this->view->message = "User has been added successfully";
                 } else {
                     $this->view->hasMessage = true;
                     $this->view->messageType = "danger";
                     $this->view->message = "Error while adding user";
                 }
             } else {
                 $errorString = "";
                 foreach ($errors as $error) {
                     $errorString .= $error . "<br/>";
                 }
                 $this->view->hasMessage = true;
                 $this->view->messageType = "danger";
                 $this->view->message = $errorString;
             }
         }
     }
 }