Skip to content
Snippets Groups Projects
Select Git revision
  • 6f70ef6ae9ba2315cfde60eaac228ed9d39eb358
  • master default protected
2 results

HomeController.java

Blame
  • Forked from CSCE 361 / examples / JavaFX SceneBuilder Examples
    Source project has a limited visibility.
    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');
        }
    
    }
    
    ?>