Controllers
[ class tree: Controllers ] [ index: Controllers ] [ all elements ]

Source for file LoginController.php

Documentation is available at LoginController.php

  1. <?php
  2. /**
  3.  * LoginController
  4.  * 
  5.  * Copyright (C) 2009  Mai (Me Artificial Intelligence)
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License as published by
  9.  * the Free Software Foundation, either version 3 of the License, or
  10.  * (at your option) any later version.
  11.  *
  12.  * This program is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  * GNU General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU General Public License
  18.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  19.  * 
  20.  * @author Wouter Bulten (wouterbulten@mai-ai.org)
  21.  * @copyright Copyright (C) 2009  Mai (Me Artificial Intelligence)
  22.  * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
  23.  * @link http://www.launchpad.net/mai
  24.  * 
  25.  * @package Controllers
  26.  * @subpackage User
  27.  * 
  28.  */
  29.  
  30. /**
  31.  * LoginController
  32.  * 
  33.  * @author Wouter Bulten (wouterbulten@mai-ai.org)
  34.  * @copyright Copyright (C) 2009  Mai (Me Artificial Intelligence)
  35.  * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
  36.  * @link http://www.launchpad.net/mai
  37.  * 
  38.  * @package Controllers
  39.  * @subpackage User
  40.  * 
  41.  *  
  42.  */
  43.  
  44. class LoginController extends Zend_Controller_Action
  45. {
  46.     /**
  47.      * Automatically removes every session for security reasons.
  48.      */
  49.     public function preDispatch()
  50.     {
  51.         if(User_Session::isValid())
  52.         {
  53.             User_Session::remove();
  54.         }
  55.     }
  56.     
  57.     /**
  58.      * Shows the login form and possible errors.
  59.      * @return void 
  60.      */
  61.     public function indexAction()
  62.     {
  63.         $params $this->getRequest()->getParams();
  64.         $this->view->error (!empty($params['error'])) $params['error'false;        
  65.     }
  66.     
  67.     /**
  68.      * First step of the login process. Checks the OpenID identifier.
  69.      * @return void 
  70.      */
  71.     public function step1Action()
  72.     {
  73.  
  74.         $identifier $this->getRequest()->getParam('openid_identifier');
  75.         
  76.         if(!$identifier)
  77.         {
  78.             $this->_forward('index'nullnullarray('error' => 'U heeft het formulier niet goed ingevuld.'));
  79.         }
  80.         else
  81.         {
  82.             //In development we want a fast login with the identifier 'test'
  83.             if(Zend_Registry::get('config')->application->development && $identifier === 'test')
  84.             {
  85.                 if(!$user User_Gateway::getUser($identifier))
  86.                 {         
  87.                     //Create an account
  88.                     $user User_Gateway::newUser();
  89.                     $user->identifier $identifier;
  90.                     
  91.                     $user->save(Zend_Registry::get('conn_dbuser'));
  92.                 }
  93.                 
  94.                 //Create session
  95.                 User_Session::set($user->id);
  96.                 
  97.                 //Redirect to Mai
  98.                 $this->_redirect('/');
  99.             }
  100.             else
  101.             {
  102.                 $consumer new Zend_OpenId_Consumer();
  103.                 if(!$consumer->login($identifier'/login/step2/'))
  104.                 {
  105.                     $this->_forward('index'nullnullarray('error' => 'De door u opgegeven OpenID is niet geldig.'));
  106.                 }
  107.             }
  108.         }
  109.     }
  110.     
  111.     /**
  112.      * Second and last step of the login system. Starts a session on success.
  113.      * @return void 
  114.      */
  115.     public function step2Action()
  116.     {
  117.         $consumer new Zend_OpenId_Consumer();
  118.         if($consumer->verify($_GET$identifier))
  119.         {    
  120.             if(!$user User_Gateway::getUser($identifier))
  121.             {         
  122.                 //Create an account
  123.                 $user User_Gateway::newUser();
  124.                 $user->identifier $identifier;
  125.                 
  126.                 $user->save(Zend_Registry::get('conn_dbuser'));
  127.             }
  128.             
  129.             //Create session
  130.             User_Session::set($user->id);
  131.             
  132.             //Redirect to Mai
  133.             $this->_redirect('/');
  134.         }
  135.         else
  136.         {    
  137.             $this->_forward('index'nullnullarray('error' => 'De door u opgegeven OpenID is niet geldig.'));
  138.         }
  139.     }
  140. }

Documentation generated on Mon, 27 Jul 2009 19:51:57 +0200 by phpDocumentor 1.4.1