Skip to content
Snippets Groups Projects
Select Git revision
  • 19fb5e50858ca2433021a26e1dcf57ed039569f4
  • 3.9 default
  • develop
  • 6.0
  • 5.0
  • 4.0
  • scrutinizer-patch-4
  • scrutinizer-patch-3
  • scrutinizer-patch-2
  • scrutinizer-patch-1
  • 3.7
  • 3.8
  • 3.6
  • 3.9_backported
  • 3.8_backported
  • 3.7_backported
  • 3.5
  • 3.6_backported
  • 3.5_backported
  • 3.4
  • 3.3_backported
  • 6.0.4
  • 6.0.3
  • 5.0.7
  • 6.0.2
  • 6.0.1
  • 5.0.6
  • 6.0.0
  • 5.0.5
  • 6.0.0-rc
  • 5.0.4
  • 6.0.0-beta
  • 5.0.3
  • 4.0.6
  • 5.0.2
  • 5.0.1
  • 4.0.5
  • 5.0.0
  • 4.0.4
  • 5.0.0-rc2
  • 5.0.0-rc1
41 results

FunctionsLibTest.php

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');
        }
    
    }
    
    ?>