Skip to content
Snippets Groups Projects
Select Git revision
  • c3a8f4f648666047b749281407310bdc6591d06f
  • main default protected
  • threads
3 results

flipport.py

Blame
  • AuthController.php 2.19 KiB
    <?php
    
    class AuthController extends Nmc_Controller_Action
    {
    
        public function indexAction()
        {
            $out = new Application_View();
            $out->location = '/';
            echo $out->render('unlModernWrapper.xhtml');
        }
    
        public function loginAction()
        {
            Nmc_Registry_Session::getInstance()->erase('loginError');
    
            $in = $this->getRequest();
            $postData = $in->getPost();
    
            $out = new Application_View();
            $out->tagline = 'Processing...';
    
            try {
                $auth = Nmc_Auth::getInstance();
                $userName = $postData['user_name'];
                $password = $postData['password'];
    
                $ldap = new Nmc_Ldap('ldap://localhost:10389');
                $ldapAuth = new Nmc_Auth_Adapter_Ldap($ldap, $userName, $password);
                $auth->pushAdapter($ldapAuth);
    
                $dbTable = Auth::getInstance();
                $dbAuth = new Nmc_Auth_Adapter_ZendDb($dbTable, $userName, $password);
                $auth->pushAdapter($dbAuth);
    
                $alwaysAuth = new Nmc_Auth_Adapter_Always(true, $userName);
                //$auth->pushAdapter($alwaysAuth);
    
                $authResult = $auth->authenticate();
                if (!$authResult->isValid()) {
                    $message = "No valid logins:\n" . implode("\n", $authResult->getMessages());
                    throw new Zend_Auth_Exception($message);
                }
    
                Nmc_Registry_Session::getInstance()->userName = $userName;
    
                $user = People::getInstance()->findByUserName($userName);
                if(!$user) {
                    $user = People::getInstance()->fetchNewFromLdap($userName);
                    $user->save();
                }
                Nmc_User::getInstance()->login($user);
    
                $out->refresh = '/home';
            } catch(Zend_Auth_Exception $e) {
                Nmc_Registry_Session::getInstance()->loginError = $e->getMessage();
                $out->refresh = '/';
            }
    
            echo $out->render('unlModernWrapper.xhtml');
        }
    
        public function logoutAction()
        {
            Nmc_User::getInstance()->logout();
            Nmc_Auth::getInstance()->clearIdentity();
            $out = new Application_View();
            $out->location = '/';
            echo $out->render('unlModernWrapper.xhtml');
        }
    
    }
    
    ?>