Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // *****************************************************************************
- // Capital IT Inc.
- // Copyright (C) 2008. All Rights Reserved
- //
- // $Source: /cvsroot/smn/app/lib/user/SMNUser.class.php,v $
- // $Revision: 1.1 $
- // $Date: 2008/11/02 23:46:43 $
- // $Author: btiernay $
- //
- // *****************************************************************************
- class SMNUser extends AgaviRbacSecurityUser {
- public function startup() {
- parent::startup ();
- $rq = $this->getContext()->getRequest();
- $rd = $rq->getRequestData();
- if (!$this->isAuthenticated() && $rd->hasCookie('autologon')) {
- $login = $rd->getCookie('autologon');
- try {
- $this->login ($login['username'], $login ['password'], true);
- } catch (AgaviSecurityException $e) {
- $response = $this->getContext()->getController()->getGlobalResponse();
- // Login didn't work, the cookie is invalid so delete it
- $response->setCookie('autologon[username]', false);
- $response->setCookie('autologon[password]', false);
- }
- }
- }
- public function login($username, $password, $isPasswordHashed = true) {
- $um = $this->context->getModel('Users', 'Default');
- $user = $um->getUserByEmail($username);
- if (!isset($user)) {
- throw new AgaviSecurityException('Invalid username or password');
- }
- if ($isPasswordHashed) {
- $password = md5($password);
- }
- if ($password != $user['password']) {
- throw new AgaviSecurityException('Invalid username or password');
- }
- $user['last_login_date'] = $um->updateLogin($user);
- $this->setAttribute('user', $user);
- $this->setAuthenticated(true);
- $this->clearCredentials();
- }
- public function logout() {
- $this->clearCredentials();
- $this->setAuthenticated(false);
- }
- }
- ?>
Add Comment
Please, Sign In to add comment