public function forgottenpasswordAction()
 {
     if ($data = Zend_Json::decode($this->getRequest()->getRawBody())) {
         try {
             if (empty($data['email'])) {
                 throw new Exception($this->_('Please enter your email address'));
             }
             $user = new Backoffice_Model_User();
             $user->find($data['email'], 'email');
             if (!$user->getId()) {
                 throw new Exception($this->_("Your email address does not exist"));
             }
             $password = Core_Model_Lib_String::generate(8);
             $user->setPassword($password)->save();
             $sender = System_Model_Config::getValueFor("support_email");
             $support_name = System_Model_Config::getValueFor("support_name");
             $layout = $this->getLayout()->loadEmail('admin', 'forgot_password');
             $subject = $this->_('Your new password');
             $layout->getPartial('content_email')->setPassword($password);
             $content = $layout->render();
             $mail = new Zend_Mail('UTF-8');
             $mail->setBodyHtml($content);
             $mail->setFrom($sender, $support_name);
             $mail->addTo($user->getEmail(), $user->getName());
             $mail->setSubject($subject);
             $mail->send();
             $data = array("success" => 1, "message" => $this->_('Your new password has been sent to the entered email address'));
         } catch (Exception $e) {
             $data = array("error" => 1, "message" => $e->getMessage());
         }
     }
     $this->_sendHtml($data);
 }
 public function deleteAction()
 {
     if ($data = Zend_Json::decode($this->getRequest()->getRawBody())) {
         try {
             if (empty($data["user_id"])) {
                 throw new Exception($this->_("An error occurred while saving. Please try again later."));
             }
             $user = new Backoffice_Model_User();
             $user->find($data["user_id"]);
             if (!$user->getId()) {
                 throw new Exception($this->_("An error occurred while saving. Please try again later."));
             }
             if ($user->findAll()->count() <= 1) {
                 throw new Exception($this->_("How do you want to access the backoffice if you remove the only user remaining?"));
             }
             $user->delete();
             $data = array("success" => 1, "message" => $this->_("User successfully deleted"));
         } catch (Exception $e) {
             $data = array("error" => 1, "message" => $e->getMessage());
         }
         $this->_sendHtml($data);
     }
 }
 public function saveAction()
 {
     if ($data = Zend_Json::decode($this->getRequest()->getRawBody())) {
         try {
             if (!Zend_Validate::is($data["email"], "emailAddress")) {
                 throw new Exception($this->_("Please, enter a correct email address."));
             }
             $user = new Backoffice_Model_User();
             $dummy = new Backoffice_Model_User();
             $dummy->find($data["email"], "email");
             $isNew = true;
             if (!empty($data["id"])) {
                 $user->find($data["id"]);
                 $isNew = !$user->getId();
             }
             $user->addData($data);
             if ($dummy->getEmail() == $user->getEmail() and $dummy->getId() != $user->getId()) {
                 throw new Exception($this->_("We are sorry but this email address already exists."));
             }
             if ($isNew and empty($data["password"])) {
                 throw new Exception($this->_("Please, enter a password."));
             }
             if (!empty($data["password"]) and $data["password"] != $data["confirm_password"]) {
                 throw new Exception($this->_("Passwords don't match"));
             }
             if (!empty($data["password"])) {
                 $user->setPassword($data["password"]);
             }
             $user->save();
             $data = array("success" => 1, "message" => $this->_("User successfully saved"));
         } catch (Exception $e) {
             $data = array("error" => 1, "message" => $e->getMessage());
         }
         $this->_sendHtml($data);
     }
 }
Example #4
0
 public function __construct($params)
 {
     $admin = new Backoffice_Model_User();
     $admin->find($params['id']);
     $this->setObject($admin);
 }
 public function forgotpasswordpostAction()
 {
     if ($datas = $this->getRequest()->getPost() and !$this->getSession()->isLoggedIn(Core_Model_Session::TYPE_BACKOFFICE)) {
         try {
             if (empty($datas['email'])) {
                 throw new Exception($this->_('Please enter your email address'));
             }
             $user = new Backoffice_Model_User();
             $user->find($datas['email'], 'email');
             if (!$user->getId()) {
                 throw new Exception($this->_("Your email address does not exist"));
             }
             $password = Core_Model_Lib_String::generate(8);
             $user->setPassword($password)->save();
             $sender = System_Model_Config::getValueFor("support_email");
             $support_name = System_Model_Config::getValueFor("support_name");
             $layout = $this->getLayout()->loadEmail('admin', 'forgot_password');
             $subject = $this->_('Your new password');
             $layout->getPartial('content_email')->setPassword($password);
             $content = $layout->render();
             $mail = new Zend_Mail('UTF-8');
             $mail->setBodyHtml($content);
             $mail->setFrom($sender, $support_name);
             $mail->addTo($user->getEmail(), $user->getName());
             $mail->setSubject($subject);
             $mail->send();
             $this->getSession()->addSuccess($this->_('Your new password has been sent to the entered email address'));
         } catch (Exception $e) {
             $this->getSession()->addError($e->getMessage());
         }
     }
     $this->_redirect('backoffice');
     return $this;
 }