public function loginAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         $canBeLoggedIn = false;
         try {
             if (empty($datas['email']) or empty($datas['password'])) {
                 throw new Exception($this->_('Authentification impossible. Merci de vérifier votre email et/ou votre mot de passe'));
             }
             $admin = new Admin_Model_Admin();
             $admin->findByEmail($datas['email']);
             if ($admin->authenticate($datas['password'])) {
                 $application = $this->getApplication();
                 $datas = array('applications' => array());
                 $url = parse_url($application->getUrl());
                 $url['path'] = 'overview';
                 $icon = '';
                 if ($application->getIcon()) {
                     $icon = $this->getRequest()->getBaseUrl() . $application->getIcon();
                 }
                 $datas['application'] = array('id' => $application->getId(), 'icon' => $icon, 'startup_image' => $application->getStartupImageUrl(), 'startup_image_retina' => $application->getStartupImageUrl('retina'), 'name' => $application->getName(), 'scheme' => $url['scheme'], 'host' => $url['host'], 'path' => ltrim($url['path'], '/'), 'url' => $application->getUrl());
             } else {
                 throw new Exception($this->_('Authentification impossible. Merci de vérifier votre email et/ou votre mot de passe'));
             }
         } catch (Exception $e) {
             $datas = array('error' => $this->_('Authentification impossible. Merci de vérifier votre email et/ou votre mot de passe'));
             //                $datas = array('error' => $e->getMessage());
         }
         $this->getResponse()->setBody(Zend_Json::encode($datas))->sendResponse();
         die;
     }
 }
 public function loginAction()
 {
     try {
         $data = $this->getRequest()->getPost();
         if (!$this->getRequest()->isPost()) {
             $data = Zend_Json::decode($this->getRequest()->getRawBody());
             $this->getResponse()->setHeader("Access-Control-Allow-Credentials", true, true);
             $this->getResponse()->setHeader("Access-Control-Allow-Methods", "PUT", true);
             $this->getResponse()->setHeader("Access-Control-Allow-Origin", "*", true);
             $this->getResponse()->setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Pragma", true);
         }
         if (!empty($data)) {
             $canBeLoggedIn = false;
             if (empty($data['email']) or empty($data['password'])) {
                 throw new Exception($this->_('Authentication failed. Please check your email and/or your password'));
             }
             $admin = new Admin_Model_Admin();
             $admin->findByEmail($data['email']);
             if ($admin->authenticate($data['password'])) {
                 $applications = $admin->getApplications();
                 $data = array('applications' => array());
                 foreach ($applications as $application) {
                     if (!$application->isActive()) {
                         continue;
                     }
                     $url = parse_url($application->getUrl());
                     $key = "";
                     if (stripos($url["path"], $application->getKey())) {
                         $url["path"] = str_replace($application->getKey(), "", $url["path"]);
                         $key = $application->getKey();
                     }
                     $icon = '';
                     if ($application->getIcon()) {
                         $icon = $this->getRequest()->getBaseUrl() . $application->getIcon();
                     }
                     $data['applications'][] = array('id' => $application->getId(), 'icon' => $icon, 'startup_image' => str_replace("//", "/", $application->getStartupImageUrl()), 'startup_image_retina' => str_replace("//", "/", $application->getStartupImageUrl("retina")), 'name' => $application->getName(), 'scheme' => $url['scheme'], 'domain' => $url['host'], 'path' => ltrim($url['path'], '/'), 'key' => $key, 'url' => $application->getUrl());
                 }
             } else {
                 throw new Exception($this->_('Authentication failed. Please check your email and/or your password'));
             }
         }
     } catch (Exception $e) {
         $data = array('error' => $this->_('Authentication failed. Please check your email and/or your password'));
     }
     $this->getResponse()->setBody(Zend_Json::encode($data))->sendResponse();
     die;
 }
 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);
     }
 }
 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;
 }