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 authenticateAction() { if ($data = $this->getRequest()->getPost()) { try { if (empty($data["email"])) { throw new Exception($this->_("The email is required")); } if (empty($data["password"])) { throw new Exception($this->_("The password is required")); } $email = $data["email"]; $password = $data["password"]; $data = array("success" => 1); $admin = new Admin_Model_Admin(); $admin->find($email, "email"); if (!$admin->getId()) { throw new Exception("The user doesn't exist."); } if (!$admin->authenticate($password)) { throw new Exception($this->_("Authentication failed.")); } $data["token"] = $admin->getLoginToken(); } catch (Exception $e) { $data = array("error" => 1, "message" => $e->getMessage()); } $this->_sendHtml($data); } }
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 loginpostAction() { if ($datas = $this->getRequest()->getPost()) { $this->getSession()->resetInstance(); $canBeLoggedIn = false; try { if (empty($datas['email']) or empty($datas['password'])) { throw new Exception($this->_('Authentication failed. Please check your email and/or your password')); } $admin = new Admin_Model_Admin(); $admin->findByEmail($datas['email']); if ($admin->authenticate($datas['password'])) { $this->getSession()->setAdmin($admin); } if (!$this->getSession()->isLoggedIn()) { throw new Exception($this->_('Authentication failed. Please check your email and/or your password')); } } catch (Exception $e) { $this->getSession()->addError($e->getMessage()); } } $this->_redirect('/'); return $this; }