Overview

Packages

  • alpha::controller
  • alpha::controller::front
  • alpha::exceptions
  • alpha::model
  • alpha::model::types
  • alpha::tasks
  • alpha::tests
  • alpha::util
  • alpha::util::cache
  • alpha::util::codehighlight
  • alpha::util::convertors
  • alpha::util::feeds
  • alpha::util::filters
  • alpha::util::graphs
  • alpha::util::helpers
  • alpha::util::metrics
  • alpha::view
  • alpha::view::renderers
  • alpha::view::widgets

Classes

  • AlphaController
  • CacheManager
  • Create
  • CreateArticle
  • Detail
  • Edit
  • EditArticle
  • EditDEnum
  • EditTags
  • GenSecureQueryStrings
  • Install
  • ListAll
  • ListBusinessObjects
  • ListDEnums
  • ListSequences
  • Login
  • Logout
  • PreviewArticle
  • Search
  • TagManager
  • ViewArticle
  • ViewArticleFile
  • ViewArticlePDF
  • ViewArticlePrint
  • ViewArticleTitle
  • ViewAttachment
  • ViewExcel
  • ViewFeed
  • ViewImage
  • ViewLog
  • ViewMetrics
  • ViewRecordSelector
  • ViewTestResults

Interfaces

  • AlphaControllerInterface
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  1: <?php
  2: 
  3: // include the config file
  4: if(!isset($config)) {
  5:     require_once '../util/AlphaConfig.inc';
  6:     $config = AlphaConfig::getInstance();
  7: 
  8:     require_once $config->get('app.root').'alpha/util/AlphaAutoLoader.inc';
  9: }
 10: 
 11: /**
 12:  * Login controller that adds the current user object to the session
 13:  *
 14:  * @package alpha::controller
 15:  * @since 1.0
 16:  * @author John Collins <dev@alphaframework.org>
 17:  * @version $Id: Login.php 1645 2013-02-14 16:11:19Z alphadevx $
 18:  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
 19:  * @copyright Copyright (c) 2013, John Collins (founder of Alpha Framework).
 20:  * All rights reserved.
 21:  *
 22:  * <pre>
 23:  * Redistribution and use in source and binary forms, with or
 24:  * without modification, are permitted provided that the
 25:  * following conditions are met:
 26:  *
 27:  * * Redistributions of source code must retain the above
 28:  *   copyright notice, this list of conditions and the
 29:  *   following disclaimer.
 30:  * * Redistributions in binary form must reproduce the above
 31:  *   copyright notice, this list of conditions and the
 32:  *   following disclaimer in the documentation and/or other
 33:  *   materials provided with the distribution.
 34:  * * Neither the name of the Alpha Framework nor the names
 35:  *   of its contributors may be used to endorse or promote
 36:  *   products derived from this software without specific
 37:  *   prior written permission.
 38:  *
 39:  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
 40:  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 41:  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 42:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 43:  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 44:  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 45:  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 46:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 47:  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 48:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 49:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 50:  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 51:  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 52:  * </pre>
 53:  *
 54:  */
 55: class Login extends AlphaController implements AlphaControllerInterface {
 56:     /**
 57:      * The person to be logged in
 58:      *
 59:      * @var PersonObject
 60:      * @since 1.0
 61:      */
 62:     protected $personObject;
 63: 
 64:     /**
 65:      * The person view object
 66:      *
 67:      * @var PersonView
 68:      * @since 1.0
 69:      */
 70:     private $personView;
 71: 
 72:     /**
 73:      * Trace logger
 74:      *
 75:      * @var Logger
 76:      * @since 1.0
 77:      */
 78:     private static $logger = null;
 79: 
 80:     /**
 81:      * constructor to set up the object
 82:      * @since 1.0
 83:      */
 84:     public function __construct() {
 85:         self::$logger = new Logger('Login');
 86:         self::$logger->debug('>>__construct()');
 87: 
 88:         global $config;
 89: 
 90:         // ensure that the super class constructor is called, indicating the rights group
 91:         parent::__construct('Public');
 92: 
 93:         $this->personObject = new PersonObject();
 94:         $this->personView = AlphaView::getInstance($this->personObject);
 95:         $this->setBO($this->personObject);
 96: 
 97:         // set up the title and meta details
 98:         $this->setTitle('Login to '.$config->get('app.title'));
 99:         $this->setDescription('Login page.');
100:         $this->setKeywords('login,logon');
101: 
102:         self::$logger->debug('<<__construct');
103:     }
104: 
105:     /**
106:      * Handle GET requests
107:      *
108:      * @param array $params
109:      * @throws IllegalArguementException
110:      * @since 1.0
111:      */
112:     public function doGET($params) {
113:         self::$logger->debug('>>doGET($params=['.var_export($params, true).'])');
114: 
115:         if(!is_array($params))
116:             throw new IllegalArguementException('Bad $params ['.var_export($params, true).'] passed to doGET method!');
117: 
118:         echo AlphaView::displayPageHead($this);
119: 
120:         if (isset($params['reset']))
121:             echo $this->personView->displayResetForm();
122:         else
123:             echo $this->personView->displayLoginForm();
124: 
125:         echo AlphaView::displayPageFoot($this);
126: 
127:         self::$logger->debug('<<doGET');
128:     }
129: 
130:     /**
131:      * Handle POST requests (adds $currentUser PersonObject to the session)
132:      *
133:      * @param array $params
134:      * @throws IllegalArguementException
135:      * @since 1.0
136:      */
137:     public function doPOST($params) {
138:         self::$logger->debug('>>doPOST($params=['.var_export($params, true).'])');
139: 
140:         if(!is_array($params))
141:             throw new IllegalArguementException('Bad $params ['.var_export($params, true).'] passed to doPOST method!');
142: 
143:         global $config;
144: 
145:         try {
146:             // check the hidden security fields before accepting the form POST data
147:             if(!$this->checkSecurityFields())
148:                 throw new SecurityException('This page cannot accept post data from remote servers!');
149: 
150:             if (isset($params['loginBut'])) {
151:                 // if the database has not been set up yet, accept a login from the config admin username/password
152:                 if(!AlphaDAO::isInstalled()) {
153:                     if ($params['email'] == $config->get('app.install.username') && crypt($params['password'], $config->get('app.install.password')) == 
154:                         crypt($config->get('app.install.password'), $config->get('app.install.password'))) {
155: 
156:                         self::$logger->info('Logging in ['.$params['email'].'] at ['.date("Y-m-d H:i:s").']');
157:                         $admin = new PersonObject();
158:                         $admin->set('displayName', 'Admin');
159:                         $admin->set('email', $params['email']);
160:                         $admin->set('password', crypt($params['password'], $config->get('app.install.password')));
161:                         $admin->set('OID', '00000000001');
162:                         $_SESSION['currentUser'] = $admin;
163:                         if ($this->getNextJob() != '') {
164:                             $url = FrontController::generateSecureURL('act='.$this->getNextJob());
165:                             self::$logger->info('Redirecting to ['.$url.']');
166:                             header('Location: '.$url);
167:                             exit;
168:                         }else{
169:                             header('Location: '.$config->get('app.url').'alpha/controller/Install.php');
170:                             exit;
171:                         }
172:                     }else{
173:                         throw new ValidationException('Failed to login user '.$params['email'].', the password is incorrect!');
174:                     }
175:                 }else{
176:                     // here we are attempting to load the person from the email address
177:                     $this->personObject->loadByAttribute('email', $params['email'], true);
178: 
179:                     AlphaDAO::disconnect();
180: 
181:                     // checking to see if the account has been disabled
182:                     if (!$this->personObject->isTransient() && $this->personObject->get('state') == 'Disabled')
183:                         throw new SecurityException('Failed to login user '.$params['email'].', that account has been disabled!');
184: 
185:                     // check the password
186:                     $this->doLoginAndRedirect($params['password']);
187:                 }
188: 
189:                 echo AlphaView::displayPageHead($this);
190: 
191:                 echo $this->personView->displayLoginForm();
192:             }
193: 
194:             if (isset($params['resetBut'])) {
195:                 // here we are attempting to load the person from the email address
196:                 $this->personObject->loadByAttribute('email', $params['email']);
197: 
198:                 AlphaDAO::disconnect();
199: 
200:                 // generate a new random password
201:                 $new_password = $this->personObject->generatePassword();
202: 
203:                 // now encrypt and save the new password, then e-mail the user
204:                 $this->personObject->set('password', crypt($new_password));
205:                 $this->personObject->save();
206: 
207:                 $message = 'The password for your account has been reset to '.$new_password.' as you requested.  You can now login to the site using your '.
208:                     'e-mail address and this new password as before.';
209:                 $subject = 'Password change request';
210: 
211:                 $this->personObject->sendMail($message, $subject);
212: 
213:                 echo AlphaView::displayUpdateMessage('The password for the user <strong>'.$params['email'].'</strong> has been reset, and the new password '.
214:                     'has been sent to that e-mail address.');
215:                 echo '<a href="'.$config->get('app.url').'">Home Page</a>';
216:             }
217:         }catch(ValidationException $e) {
218:             echo AlphaView::displayPageHead($this);
219: 
220:             echo AlphaView::displayErrorMessage($e->getMessage());
221: 
222:             echo $this->personView->displayLoginForm();
223: 
224:             self::$logger->warn($e->getMessage());
225:         }catch(SecurityException $e) {
226:             echo AlphaView::displayPageHead($this);
227: 
228:             echo AlphaView::displayErrorMessage($e->getMessage());
229: 
230:             self::$logger->warn($e->getMessage());
231:         }catch(BONotFoundException $e) {
232:             echo AlphaView::displayPageHead($this);
233: 
234:             echo AlphaView::displayErrorMessage('Failed to find the user \''.$params['email'].'\'');
235: 
236:             echo $this->personView->displayLoginForm();
237: 
238:             self::$logger->warn($e->getMessage());
239:         }
240: 
241:         echo AlphaView::displayPageFoot($this);
242:         self::$logger->debug('<<doPOST');
243:     }
244: 
245:     /**
246:      * Login the user and re-direct to the defined destination
247:      *
248:      * @param string $password The password supplied by the user logging in
249:      * @throws ValidationException
250:      * @since 1.0
251:      */
252:     protected function doLoginAndRedirect($password) {
253:         self::$logger->debug('>>doLoginAndRedirect(password=['.$password.'])');
254: 
255:         global $config;
256: 
257:         if (!$this->personObject->isTransient() && $this->personObject->get('state') == 'Active') {
258:             if (crypt($password, $this->personObject->get('password')) == $this->personObject->get('password')) {
259: 
260:                 $_SESSION['currentUser'] = $this->personObject;
261: 
262:                 self::$logger->debug('Logging in ['.$this->personObject->get('email').'] at ['.date("Y-m-d H:i:s").']');
263:                 self::$logger->action('Login');
264: 
265:                 if ($this->getNextJob() != '') {
266:                     self::$logger->debug('<<doLoginAndRedirect');
267:                     $url = FrontController::generateSecureURL('act='.$this->getNextJob());
268:                     header('Location: '.$url);
269:                     exit;
270:                 }else{
271:                     self::$logger->debug('<<doLoginAndRedirect');
272:                     header('Location: '.$config->get('app.url'));
273:                     exit;
274:                 }
275:             }else{
276:                 throw new ValidationException('Failed to login user '.$this->personObject->get('email').', the password is incorrect!');
277:                 self::$logger->debug('<<doLoginAndRedirect');
278:             }
279:         }
280:     }
281: 
282:     /**
283:      * Displays the application version number on the login screen.
284:      *
285:      * @return string
286:      * @since 1.0
287:      */
288:     public function before_displayPageFoot_callback() {
289:         global $config;
290: 
291:         return '<p><em>Version '.$config->get('app.version').'</em></p>';
292:     }
293: }
294: 
295: // now build the new controller if this file is called directly
296: if ('Login.php' == basename($_SERVER['PHP_SELF'])) {
297:     $controller = new Login();
298: 
299:     if(!empty($_POST)) {
300:         $controller->doPOST($_POST);
301:     }else{
302:         $controller->doGET($_GET);
303:     }
304: }
305: 
306: ?>
Alpha Framework 1.2.2 API Documentation API documentation generated by ApiGen 2.8.0