summaryrefslogblamecommitdiffstats
path: root/application/controllers/AuthController.php
blob: b3f6bbfcfb923d2b6e3ae331dd4365e10b6a7496 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14













                                                                           

                                   
                                  

                                           


                              


                                                                
                                                                     



                                                                                                                                                                                                             



                                     











                                                                                
                                                                  



                                                                                                                                                        
 

                                                                                                         
 

                                                                                                      
 









                                                                                                                                                    
                                                 












                                                              
                                                            


                                                        



                                                            
 
<?php
/*
 * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg
 * This program is free software distributed under the GPL version 2.
 * See http://gpl.openslx.org/
 *
 * If you have any feedback please consult http://feedback.openslx.org/ and
 * send your suggestions, praise, or complaints to feedback@openslx.org
 *
 * General information about OpenSLX can be found at http://openslx.org/
 */

class AuthController extends Zend_Controller_Action
{
	protected $config = null;
	protected $pbs2host = null;
	protected $pbs2Api = null;
	protected $userIDsNamespace = null;
	protected $acl = null;

	public function init()
	{
		$bootstrap = $this->getInvokeArg('bootstrap');
		$this->config = $bootstrap->getOptions();
		$this->pbs2host = $this->config['pbs2']['host'];
		$this->pbs2Api = new Poolctrl_Pbs2Api($this->config);
		$this->userIDsNamespace = Zend_Session::namespaceGet('userIDs');
		if(isset($this->userIDsNamespace['apikey'])) {
			$this->acl = new Poolctrl_Acl($this->pbs2host, $this->config['pbs2']['checkright'] . $this->userIDsNamespace['apikey'], 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
		}
	}

	public function indexAction()
	{
		$this->_helper->redirector('login', 'auth');
	}

	public function loginAction()
	{
		if (Zend_Auth::getInstance()->hasIdentity()) {
			$this->_redirect('/');
		} else {
			if (!isset($_POST["login"])){
				$loginForm = new Application_Form_Login();
			} else {
				$loginForm = new Application_Form_Login($_POST);
				if ($loginForm->isValid($_POST)) {
					$membershipSession = new Zend_Session_Namespace('memberships');
					if($this->pbs2Api->login($loginForm->getValue('email'), $loginForm->getValue('password'), $membershipSession)) {
						$personSession = new Zend_Session_Namespace('persons');
						$this->pbs2Api->getPerson($personSession);

						$userSession = new Zend_Session_Namespace('userIDs');
						$userSession->personID = sprintf("%s", $login->personid);

						$authSession = new Zend_Session_Namespace('auth');
						$authSession->storage = $loginForm->getValue('email');

						$this->_helper->redirector('selectmembership', 'person');
						return;
					} else {
						$error = sprintf("%s", $login->error);
						if($error == "wrong email or password") {
							$poolctrlNotifier = new Poolctrl_Notifier();
							$this->view->notification = $poolctrlNotifier->notify('Wrong Email or Password', 'error');
						} else if($error == "person suspended") {
							$poolctrlNotifier = new Poolctrl_Notifier();
							$this->view->notification = $poolctrlNotifier->notify('Your Account is suspended', 'error');
						}
					}
				}
			}
			$this->view->loginForm = $loginForm;
		}
	}

	public function logoutAction()
	{
		$this->_helper-> viewRenderer-> setNoRender();
		$auth = Zend_Auth::getInstance();
		$auth->clearIdentity();
		Zend_Session::namespaceUnset('userIDs');
		Zend_Session::namespaceUnset('memberships');
		Zend_Session::namespaceUnset('persons');
		Zend_Session::namespaceUnset('groups');
		Zend_Session::namespaceUnset('roles');
		Zend_Session::forgetMe();
		$this->_helper->redirector('login', 'auth');
		return;
	}
}