public function savepostAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         $admin = new Admin_Model_Admin();
         $check_email_admin = new Admin_Model_Admin();
         try {
             if (!empty($datas['admin_id'])) {
                 $admin->find($datas['admin_id']);
                 if (!$admin->getId()) {
                     throw new Exception($this->_('An error occurred while saving your account. Please try again later.'));
                 }
             }
             if (empty($datas['email'])) {
                 throw new Exception($this->_('The email is required'));
             }
             $isNew = (bool) (!$admin->getId());
             $check_email_admin->find($datas['email'], 'email');
             if ($check_email_admin->getId() and $check_email_admin->getId() != $admin->getId()) {
                 throw new Exception($this->_('This email address is already used'));
             }
             if (isset($datas['password'])) {
                 if ($datas['password'] != $datas['confirm_password']) {
                     throw new Exception($this->_('Your password does not match the entered password.'));
                 }
                 if (!empty($datas['old_password']) and !$admin->isSamePassword($datas['old_password'])) {
                     throw new Exception($this->_("The old password does not match the entered password."));
                 }
                 if (!empty($datas['password'])) {
                     $admin->setPassword($datas['password']);
                     unset($datas['password']);
                 }
             } else {
                 if ($isNew) {
                     throw new Exception($this->_('The password is required'));
                 }
             }
             $admin->addData($datas)->save();
             $this->getSession()->addSuccess($this->_('The account has been successfully saved'));
             $this->_redirect('admin/backoffice/list');
         } catch (Exception $e) {
             $this->getSession()->addError($e->getMessage());
             if ($admin->getId()) {
                 $this->_redirect('admin/backoffice/edit', array('admin_id' => $admin->getId()));
             } else {
                 $this->_redirect('admin/backoffice/new');
             }
         }
     }
 }
Ejemplo n.º 2
0
 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."));
             }
             $admin = new Admin_Model_Admin();
             $dummy = new Admin_Model_Admin();
             $dummy->find($data["email"], "email");
             $isNew = true;
             $data["confirm_password"] = !empty($data["confirm_password"]) ? $data["confirm_password"] : "";
             if (!empty($data["id"])) {
                 $admin->find($data["id"]);
                 $isNew = !$admin->getId();
             }
             if ($isNew and empty($data["password"])) {
                 throw new Exception($this->_("Please, enter a password."));
             }
             if (empty($data["password"]) and empty($data["confirm_password"])) {
                 unset($data["password"]);
                 unset($data["confirm_password"]);
             }
             if (!empty($data["password"]) and $data["password"] != $data["confirm_password"]) {
                 throw new Exception($this->_("Passwords don't match"));
             }
             $admin->addData($data);
             if ($dummy->getEmail() == $admin->getEmail() and $dummy->getId() != $admin->getId()) {
                 throw new Exception($this->_("We are sorry but this email address already exists."));
             }
             if (!empty($data["password"])) {
                 $admin->setPassword($data["password"]);
             }
             if (!empty($data["publication_access_type"])) {
                 $admin->setPublicationAccessType($data["publication_access_type"]);
             }
             $admin->save();
             $data = array("success" => 1, "message" => $this->_("User successfully saved"));
         } catch (Exception $e) {
             $data = array("error" => 1, "message" => $e->getMessage());
         }
         $this->_sendHtml($data);
     }
 }
Ejemplo n.º 3
0
 public function forgotpasswordAction()
 {
     if ($data = $this->getRequest()->getPost()) {
         try {
             if (empty($data['email'])) {
                 throw new Exception($this->_('Please enter your email address'));
             }
             $admin = new Admin_Model_Admin();
             $admin->findByEmail($data['email']);
             if (!$admin->getId()) {
                 throw new Exception($this->_("This email address does not exist"));
             }
             $password = Core_Model_Lib_String::generate(8);
             $admin->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->_('%s - Your new password', $support_name);
             $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($admin->getEmail(), $admin->getName());
             $mail->setSubject($subject);
             $mail->send();
             $data = array("success" => 1);
         } catch (Exception $e) {
             $data = array('error' => 1, 'message' => $e->getMessage());
         }
         $this->_sendHtml($data);
     }
 }
Ejemplo n.º 4
0
 public function forgotpasswordpostAction()
 {
     if ($datas = $this->getRequest()->getPost() and !$this->getSession()->isLoggedIn('admin') and !$this->getSession()->isLoggedIn('pos')) {
         try {
             if (empty($datas['email'])) {
                 throw new Exception($this->_('Please enter your email address'));
             }
             $admin = new Admin_Model_Admin();
             $admin->findByEmail($datas['email']);
             if (!$admin->getId()) {
                 throw new Exception($this->_("Your email address does not exist"));
             }
             $password = Core_Model_Lib_String::generate(8);
             $admin->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->_('%s - Your new password', $support_name);
             $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($admin->getEmail(), $admin->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('/');
     return $this;
 }