2 /* This file is part of Syj, Copyright (c) 2010-2011 Arnaud Renevier,
3 and is published under the AGPL license. */
5 class LoginController extends Zend_Controller_Action
7 public function init() {
8 $this->view->headTitle($this->view->translate("login"));
9 $this->_helper->SyjMedias->addScripts('login');
10 $this->view->headLink()->appendStylesheet('css/generic.css', 'all');
11 $this->view->headLink()->appendStylesheet('css/form.css', 'all');
12 $this->view->headLink()->appendStylesheet('css/login.css', 'all');
15 public function loginAction() {
16 $form = new Syj_Form_Login(array('name' => 'loginform'));
17 $request = $this->getRequest();
18 $formData = $request->getPost();
19 $this->view->form = $form;
20 $httprequest = $request->isXmlHttpRequest();
23 $this->_jsLocaleStrings();
26 if (empty ($formData) or !$form->isValid($formData)) {
28 throw new Syj_Exception_Request();
34 /* form has been filled */
35 if (!$this->_helper->SyjUserManager->validate($formData['login_user'],
36 sha1($formData['login_password']),
37 $formData['login_rememberme'])) {
39 throw new Syj_Exception_Forbidden();
41 $form->addError('Wrong login/password');
46 $user = $this->_helper->SyjUserManager->current();
49 $api = $this->_helper->SyjApi->setCode(200);
50 $data = array('pseudo' => $user->pseudo);
52 $login_geom_id = $formData['login_geom_id'];
54 $path = new Syj_Model_Path();
55 $pathMapper = new Syj_Model_PathMapper();
56 if (!$pathMapper->find((int)$login_geom_id, $path)) {
57 throw new Syj_Exception_Request();
59 $data['iscreator'] = ($path->creator->id === $user->id);
61 $data['iscreator'] = true;
63 $api->setBodyJson($data);
69 public function logoutAction() {
70 $this->_helper->SyjUserManager->logout();
74 protected function redirect($target = null) {
75 if (!isset($target)) {
76 $target = $this->getRequest()->getQuery('redirect');
79 if (!isset($target)) {
80 $target = $this->view->baseUrl();
86 $this->_helper->Redirector->gotoURL($target, array('prependBase' => false));
89 protected function _jsLocaleStrings() {
90 $this->view->jslocales = array(
91 'userEmptyWarn' => __("you must enter a login name"));