.

Users Class Reference
[Usermanagement]

Usermanagement Business Logic. More...

List of all members.

Static Public Member Functions

static  confirm_email ($user)
  Confirm the email address of given user.
static  count_unconfirmed ()
  Return number of unconfirmed users.
static  create ($params, &$result)
  Creates an account.
static  create_adapter ()
  Prepare DAO instance for retrieving users (that are ACTIVE).
static  create_all_user_adapter ()
  Prepare DAO instance for retrieving all user.
static  create_hash ($source, $hash_type)
  Create a hash of $source using algorith $hash_type.
static  create_hash_algorithm ($hash_type)
  Create a hash algorith instance of $hash_type.
static  create_role_adapter ($roles)
  Prepare DAO instance for retrieving all user with given roles.
static  current_has_role ($role)
  Returns true, if current user has given access level (or higher).
static  do_login ($user)
  Performs actual login for a given user.
static  get ($id)
  Returns user with given ID or false if not found.
static  get_current_user ()
  Returns the user logged in or null, if no user is logged in.
static  get_current_user_id ()
  Returns the id of the user logged in or false, if no user is logged in.
static  get_email_statuses ()
  Return all possible email status.
static  get_statuses ()
  Return all possible status.
static  get_user_roles ()
  Get user roles.
static  initialize ()
  Initialize user management, session et al.
static  is_current ($user)
  Returns true, if the user passed is the user logged in.
static  is_logged_in ()
  Returns true, if an user is logged in, else false.
static  is_unique_username ($name)
  Returns wether a given username is unique or not.
static  login ($params, $permanent)
  Login given user.
static  login_as_system ()
  Log in as System user.
static  logout ()
  Logout current user.
static  lost_password ($email)
  Creates one time login for user that lost password.
static  register ($username, $password, $email, &$result)
  Registers a new User.
static  reload_current ()
  Reload current user (which is stored in session).
static  resend_registration_mail ($email)
  Resend registration mail.
static  update (DAOUsers $user, $params)
  Edit account data of current user.

Public Attributes

const  EMAIL_STATUS_BOUNCED = 'BOUNCED'
const  EMAIL_STATUS_CONFIRMED = 'CONFIRMED'
const  EMAIL_STATUS_EXPIRED = 'EXPIRED'
const  EMAIL_STATUS_UNCONFIRMED = 'UNCONFIRMED'
const  STATUS_ACTIVE = 'ACTIVE'
const  STATUS_DELETED = 'DELETED'
const  STATUS_DISABLED = 'DISABLED'
const  STATUS_UNCONFIRMED = 'UNCONFIRMED'

Detailed Description

Usermanagement Business Logic.

Author:
Gerd Riesselmann

Definition at line 10 of file users.facade.php.


Member Function Documentation

static Users::confirm_email ( user  )  [static]

Confirm the email address of given user.

Parameters:
DAOUsers  $user
Returns:
Status

Definition at line 449 of file users.facade.php.

00449                                                     {
00450                 $cmd = CommandsFactory::create_command($user, 'confirmemail', false);
00451                 return $cmd->execute();
00452         }
static Users::count_unconfirmed (  )  [static]

Return number of unconfirmed users.

Returns:
int

Definition at line 280 of file users.facade.php.

00280                                                    {
00281                 $users = new DAOUsers();
00282                 $users->status = USER_STATUS_UNCONFIRMED;       
00283                 return $users->count();
00284         }       
static Users::create ( params,
&$  result  
) [static]

Creates an account.

Parameters:
array  $params Associative array with account's properties
DAOUsers  $result User created
Returns:
Status

Definition at line 178 of file users.facade.php.

00178                                                          {
00179                 $cmd = CommandsFactory::create_command('users', 'create', $params);
00180                 $err = $cmd->execute();
00181                 $result = $cmd->get_result();
00182                 return $err;
00183         }
static Users::create_adapter (  )  [static]

Prepare DAO instance for retrieving users (that are ACTIVE).

Returns:
DAOUsers

Definition at line 230 of file users.facade.php.

00230                                                 {
00231                 $users = new DAOUsers();        
00232                 $users->status = self::STATUS_ACTIVE;
00233                 return $users;
00234         } 
static Users::create_all_user_adapter (  )  [static]

Prepare DAO instance for retrieving all user.

Returns:
DAOUsers

Definition at line 241 of file users.facade.php.

00241                                                          {
00242                 $users = new DAOUsers();        
00243                 return $users;
00244         } 
static Users::create_hash ( source,
hash_type  
) [static]

Create a hash of $source using algorith $hash_type.

Since:
0.5.1
Returns:
string

Definition at line 438 of file users.facade.php.

00438                                                                 {
00439                 $algo = self::create_hash_algorithm($hash_type);
00440                 return $algo->hash($source);
00441         }
static Users::create_hash_algorithm ( hash_type  )  [static]

Create a hash algorith instance of $hash_type.

Since:
0.5.1
Returns:
IHashAlgorithm

Definition at line 422 of file users.facade.php.

00422                                                                  {
00423                 // Load hash class
00424                 $hash_type = strtolower($hash_type);
00425                 Load::classes_in_directory('behaviour/commands/users/hashes', $hash_type, 'hash', true);
00426                 $cls_name = Load::filename_to_classname($hash_type, 'hash');
00427                 
00428                 return new $cls_name();
00429         }
static Users::create_role_adapter ( roles  )  [static]

Prepare DAO instance for retrieving all user with given roles.

Returns:
DAOUsers

Definition at line 251 of file users.facade.php.

00251                                                            {
00252                 $users = new DAOUsers();
00253                 
00254                 $all_roles = self::get_user_roles();
00255                 $arr_roles_in = array();
00256                 foreach(Arr::force($roles, false) as $r) {
00257                         $key = array_search($r, $all_roles);
00258                         if ($key) {
00259                                 $arr_roles_in[] = $key;
00260                         }
00261                 } 
00262                 if (count($arr_roles_in) > 0) {
00263                         $link = new DAOUsers2userroles();
00264                         $link->add_where('id_role', DBWhere::OP_IN, $arr_roles_in);
00265                         $users->status = self::STATUS_ACTIVE;   
00266                         $users->join($link);                    
00267                 }
00268                 else {
00269                         $users->add_where('1 = 2');
00270                 }
00271                 
00272                 return $users;
00273         }
static Users::current_has_role ( role  )  [static]

Returns true, if current user has given access level (or higher).

Definition at line 72 of file users.facade.php.

00072                                                        {
00073                 if (self::is_logged_in()) {
00074                         return self::get_current_user()->has_role($role);
00075                 }
00076                 return false;
00077         }
static Users::do_login ( user  )  [static]

Performs actual login for a given user.

Returns:
Boolean True on success, false otherwise

Definition at line 165 of file users.facade.php.

00165                                                {
00166                 $cmd = CommandsFactory::create_command($user, 'loginknown', array());
00167                 $ret = $cmd->execute();
00168                 return $ret->is_ok();
00169         }
static Users::get ( id  )  [static]

Returns user with given ID or false if not found.

Returns:
DAOUsers

Definition at line 99 of file users.facade.php.

00099                                         {
00100                 return DB::get_item('users', 'id', $id); 
00101         } 
static Users::get_current_user (  )  [static]

Returns the user logged in or null, if no user is logged in.

Returns:
DAOUsers

Definition at line 26 of file users.facade.php.

00026                                                   {
00027                 return AccessControl::get_current_aro();
00028         }
static Users::get_current_user_id (  )  [static]

Returns the id of the user logged in or false, if no user is logged in.

Returns:
int

Definition at line 35 of file users.facade.php.

00035                                                      {
00036                 $ret = false;
00037                 $user = self::get_current_user();
00038                 if ($user) {
00039                         $ret = $user->id;
00040                 }
00041                 return $ret;
00042         }
static Users::get_email_statuses (  )  [static]

Return all possible email status.

Returns:
array

Definition at line 122 of file users.facade.php.

00122                                                     {
00123                 return array(
00124                         self::EMAIL_STATUS_UNCONFIRMED => tr(self::EMAIL_STATUS_UNCONFIRMED, 'users'),
00125                         self::EMAIL_STATUS_CONFIRMED => tr(self::EMAIL_STATUS_CONFIRMED, 'users'),
00126                         self::EMAIL_STATUS_EXPIRED => tr(self::EMAIL_STATUS_EXPIRED, 'users'),
00127                         self::EMAIL_STATUS_BOUNCED => tr(self::EMAIL_STATUS_BOUNCED, 'users'),
00128                 );
00129         }
static Users::get_statuses (  )  [static]

Return all possible status.

Returns:
array

Definition at line 108 of file users.facade.php.

00108                                               {
00109                 return array(
00110                         self::STATUS_ACTIVE => tr(self::STATUS_ACTIVE, 'users'),
00111                         self::STATUS_DELETED => tr(self::STATUS_DELETED, 'users'),
00112                         self::STATUS_DISABLED => tr(self::STATUS_DISABLED, 'users'),
00113                         self::STATUS_UNCONFIRMED => tr(self::STATUS_UNCONFIRMED, 'users'),
00114                 );
00115         }
static Users::get_user_roles (  )  [static]

Get user roles.

Returns:
array Associative array with role id as key and role name as value

Definition at line 291 of file users.facade.php.

00291                                                 {
00292                 $ret = array();
00293                 $dao = new DAOUserroles();
00294                 $dao->find();
00295                 while($dao->fetch()) {
00296                         $ret[$dao->id] = tr($dao->name, 'app');
00297                 }
00298                 return $ret;                                                            
00299         }       
static Users::initialize (  )  [static]

Initialize user management, session et al.

Definition at line 304 of file users.facade.php.

00304                                             {
00305                 $current_user_id = Session::peek('current_user_id');
00306                 if (empty($current_user_id)) {
00307                         // Backward compatability
00308                         $current_user = Session::pull('current_user');
00309                 }
00310                 else {
00311                         $current_user = self::get($current_user_id);
00312                 }
00313                 
00314                 if (empty($current_user)) {
00315                         self::check_permanent_login();
00316                 }
00317                 else {
00318                         self::do_login($current_user);
00319                 }
00320         }
static Users::is_current ( user  )  [static]

Returns true, if the user passed is the user logged in.

Definition at line 58 of file users.facade.php.

00058                                                  {
00059                 $ret = false;
00060                 if ($user) {
00061                         $current = self::get_current_user();
00062                         if ($current) {
00063                                 $ret = ($current->id == $user->id);
00064                         }
00065                 }
00066                 return $ret;
00067         }
static Users::is_logged_in (  )  [static]

Returns true, if an user is logged in, else false.

Returns:
bool

Definition at line 50 of file users.facade.php.

00050                                               {
00051                 $user = self::get_current_user();
00052                 return ($user instanceof DAOUsers);
00053         }
static Users::is_unique_username ( name  )  [static]

Returns wether a given username is unique or not.

Returns:
bool

Definition at line 459 of file users.facade.php.

00459                                                          {
00460                 $user = new DAOUsers();
00461                 $user->add_where('status', '!=', Users::STATUS_DELETED);
00462                 $user->name = $name;
00463                 return ($user->count() == 0);                           
00464         }
static Users::login ( params,
permanent  
) [static]

Login given user.

Parameters:
array  $params Associative array with login information
bool  $permanent If TRUE, user get's permanently logged in
Returns:
Status

Definition at line 147 of file users.facade.php.

00147                                                           {
00148                 $params['permanent'] = $permanent;
00149                 $cmd = CommandsFactory::create_command('users', 'login', $params);
00150                 $ret = $cmd->execute();
00151 
00152                 if ($ret->is_ok() && $permanent) {
00153                         $user = self::get_current_user();
00154                         PermanentLogins::enable_permanent_login($user);
00155                 }
00156                 
00157                 return $ret;
00158         }
static Users::login_as_system (  )  [static]

Log in as System user.

Definition at line 339 of file users.facade.php.

00339                                                  {
00340                 Load::models('systemusers');
00341                 $user = new DAOSystemUsers();
00342                 self::do_login($user);
00343         }
static Users::logout (  )  [static]

Logout current user.

Definition at line 134 of file users.facade.php.

00134                                         {
00135                 $cmd = CommandsFactory::create_command('users', 'logout', false);
00136                 $cmd->execute();
00137         }
static Users::lost_password ( email  )  [static]

Creates one time login for user that lost password.

Parameters:
string  $email
Returns:
Status

Definition at line 351 of file users.facade.php.

00351                                                      {
00352                 $ret = new Status();
00353 
00354                 $user = new DAOUsers();
00355                 $user->email = $email;
00356                 $user->status = self::STATUS_ACTIVE;
00357                 if ($email && $user->find(IDataObject::AUTOFETCH)) {
00358                         $params = array(
00359                                 'id_item' => $user->id,
00360                                 'action' => 'onetimelogin',
00361                                 'data' => $email
00362                         );
00363                         $cmd = CommandsFactory::create_command('confirmations', 'create', $params);
00364                         $ret->merge($cmd->execute());
00365                 }
00366                 else {
00367                         $ret->append(tr('Unknown email', 'users'));
00368                 }
00369                 return $ret;
00370         }
static Users::register ( username,
password,
email,
&$  result  
) [static]

Registers a new User.

Parameters:
string  $username
string  $password
string  $email
DAOUsers  $result User created
Returns:
Status

Definition at line 194 of file users.facade.php.

00194                                                                                 {
00195                 $params = array(
00196                         'name' => $username,
00197                         'email' => $email,
00198                         'password' => $password
00199                 );
00200                 $cmd = CommandsFactory::create_command('users', 'register', $params);
00201                 $err = $cmd->execute();
00202                 $result = $cmd->get_result();
00203                 return $err;
00204         }
static Users::reload_current (  )  [static]

Reload current user (which is stored in session).

Definition at line 82 of file users.facade.php.

00082                                                 {
00083                 if (self::is_logged_in()) {
00084                         $user = self::get(self::get_current_user_id());
00085                         if ($user) {
00086                                 self::do_login($user);
00087                         }
00088                         else {
00089                                 self::logout();
00090                         }
00091                 }
00092         }
static Users::resend_registration_mail ( email  )  [static]

Resend registration mail.

Parameters:
string  $email
Returns:
Status

Definition at line 378 of file users.facade.php.

00378                                                                 {
00379                 $user = new DAOUsers();
00380                 $user->email = $email;
00381                 $ret = new Status();
00382                 if ($email && $user->find(IDataObject::AUTOFETCH)) {
00383                         switch ($user->status) {
00384                                 case Users::STATUS_ACTIVE:
00385                                         $ret->append(tr('Your account already has been activated, use you user name and password to log in.', 'users'));
00386                                         $ret->persist();
00387                                         Url::create(ActionMapper::get_url('login'))->redirect();
00388                                         exit;
00389                                         break;
00390                                 case Users::STATUS_UNCONFIRMED:
00391                                         Load::models('confirmations');
00392                                         $confirmation = new DAOConfirmations();
00393                                         $confirmation->id_item = $user->id;
00394                                         $confirmation->action = 'createaccount'; 
00395                                         if ($confirmation->find(IDataObject::AUTOFETCH)) {
00396                                                 $handler = $confirmation->create_handler();
00397                                                 $ret->merge($handler->created());
00398                                         }
00399                                         else {
00400                                                 $ret->append(tr('You activation request already has expired.', 'users'));
00401                                         }
00402                                         break;
00403                                 default:
00404                                         // Deleted, banned, or watever
00405                                         $ret->append(tr('Unknown email', 'users'));
00406                                         break;
00407                         }
00408                 }
00409                 else {
00410                         $ret->append(tr('Unknown email', 'users'));
00411                 }
00412                 return $ret;
00413         }
static Users::update ( DAOUsers user,
params  
) [static]

Edit account data of current user.

Returns:
Status

Definition at line 211 of file users.facade.php.

00211                                                                {
00212                 $cmd = CommandsFactory::create_command($user, 'update', $params);
00213                 $err = $cmd->execute();
00214                 
00215                 // If all is OK, update user (only self)        
00216                 if ($err->is_ok()) {
00217                         if (self::is_current($user)) {
00218                                 self::do_login(clone($user));
00219                         }
00220                 }
00221 
00222                 return $err;            
00223         }

Member Data Documentation

const Users::EMAIL_STATUS_BOUNCED = 'BOUNCED'

Definition at line 19 of file users.facade.php.

const Users::EMAIL_STATUS_CONFIRMED = 'CONFIRMED'

Definition at line 17 of file users.facade.php.

const Users::EMAIL_STATUS_EXPIRED = 'EXPIRED'

Definition at line 18 of file users.facade.php.

const Users::EMAIL_STATUS_UNCONFIRMED = 'UNCONFIRMED'

Definition at line 16 of file users.facade.php.

const Users::STATUS_ACTIVE = 'ACTIVE'

Definition at line 11 of file users.facade.php.

const Users::STATUS_DELETED = 'DELETED'

Definition at line 12 of file users.facade.php.

const Users::STATUS_DISABLED = 'DISABLED'

Definition at line 13 of file users.facade.php.

const Users::STATUS_UNCONFIRMED = 'UNCONFIRMED'

Definition at line 14 of file users.facade.php.


The documentation for this class was generated from the following file: