import v1.0.0-RC4 | 2009-05-20
This commit is contained in:
59
modules/users/models/User.php
Executable file
59
modules/users/models/User.php
Executable file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD License
|
||||
* @author Keyboard Monkeys Ltd.
|
||||
* @since Textroller 0.9
|
||||
* @package TextRoller
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
|
||||
class User extends Zend_Db_Table_Row_Abstract
|
||||
{
|
||||
const ROLE_GUEST = 'guest';
|
||||
const ROLE_REGISTERED = 'registered';
|
||||
const ROLE_ADMIN = 'admin';
|
||||
|
||||
/**
|
||||
* To identify the app that owns the user obj in the session.
|
||||
* Useful when sharing the user between apps.
|
||||
*/
|
||||
|
||||
public function getFullName()
|
||||
{
|
||||
return $this->firstname . ' ' . $this->lastname;
|
||||
}
|
||||
|
||||
public function generateRandomPassword()
|
||||
{
|
||||
return substr(md5($this->getFullName() . time()), 0, 6);
|
||||
}
|
||||
|
||||
/**
|
||||
* Password is stored using md5($this->openid.$password) because
|
||||
* that's what's used in Zend_OpenId
|
||||
*/
|
||||
public function setClearPassword($password)
|
||||
{
|
||||
$this->password = md5($this->openid.$password);
|
||||
$this->password_changed = date('Y-m-d');
|
||||
}
|
||||
|
||||
public function isAllowed($resource, $privilege)
|
||||
{
|
||||
$acl = Zend_Registry::get('acl');
|
||||
return $acl->isAllowed($this->role, $resource, $privilege);
|
||||
}
|
||||
|
||||
public static function generateToken()
|
||||
{
|
||||
$token = '';
|
||||
for ($i = 0; $i < 50; $i++) {
|
||||
$token .= chr(rand(48, 122));
|
||||
}
|
||||
|
||||
return md5($token.time());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user