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'], sha1($formData['login_password']))) {
37 throw new Syj_Exception_Forbidden();
39 $form->addError('Wrong login/password');
44 $user = $this->_helper->SyjUserManager->current();
47 $api = $this->_helper->SyjApi->setCode(200);
48 $data = array('pseudo' => $user->pseudo);
50 $login_geom_id = $formData['login_geom_id'];
52 $path = new Syj_Model_Path();
53 $pathMapper = new Syj_Model_PathMapper();
54 if (!$pathMapper->find((int)$login_geom_id, $path)) {
55 throw new Syj_Exception_Request();
57 $data['iscreator'] = ($path->creator->id === $userid);
59 $data['iscreator'] = true;
61 $api->setBodyJson($data);
67 public function logoutAction() {
68 $this->_helper->SyjUserManager->logout();
72 protected function redirect($target = null) {
73 if (!isset($target)) {
74 $target = $this->getRequest()->getQuery('redirect');
77 if (!isset($target)) {
78 $target = $this->view->baseUrl();
84 $this->_helper->Redirector->gotoURL($target, array('prependBase' => false));
87 protected function _jsLocaleStrings() {
88 $this->view->jslocales = array(
89 'userEmptyWarn' => __("you must enter a login name"));