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->_helper->SyjMedias->addStyleSheets('login');
13 public function loginAction() {
14 $form = new Syj_Form_Login(array('name' => 'loginform'));
15 $request = $this->getRequest();
16 $formData = $request->getPost();
17 $this->view->form = $form;
18 $httprequest = $request->isXmlHttpRequest();
21 $this->_jsLocaleStrings();
24 if (empty ($formData) or !$form->isValid($formData)) {
26 throw new Syj_Exception_Request();
32 /* form has been filled */
33 if (!$this->_helper->SyjUserManager->validate($formData['login_user'],
34 sha1($formData['login_password']),
35 $formData['login_rememberme'])) {
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 === $user->id);
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"));