.

LoginUsersBaseCommand Class Reference
[Usermanagement]

Login command to be overloaded. More...

Inheritance diagram for LoginUsersBaseCommand:
CommandChain CommandBase ICommand IAction ISerializable LoginUsersCommand

List of all members.

Public Member Functions

  get_name ()
  Returns title of command.

Protected Member Functions

  check_password_hash (DAOUsers $user, $params)
  Validate password hash.
  do_can_execute ($user)
  do_create_user_dao ($params, $err)
  Find user from parameters given.
  do_execute ()
  do_get_default_error_message ()
  Returns default error message.
  do_prepare_user_dao (DAOUsers $user)
  Prepares dao object.
  do_validate_params ($params)
  Check params.
  params_extract_name ($params)
  Extracts name from param array.
  params_extract_password ($params)
  Extracts password from param array.

Detailed Description

Login command to be overloaded.

Author:
Gerd Riesselmann

Definition at line 8 of file login.cmd.php.


Member Function Documentation

LoginUsersBaseCommand::check_password_hash ( DAOUsers user,
params  
) [protected]

Validate password hash.

Since:
0.5.1

Definition at line 61 of file login.cmd.php.

00061                                                                         {
00062                 $ret = new Status();
00063                 $password = $this->params_extract_password($params);
00064                 if (!$user->password_match($password)) {
00065                         $ret->append($this->do_get_default_error_message()); 
00066                 }
00067                 else if ($user->hash_type != Config::get_value(ConfigUsermanagement::HASH_TYPE)) {
00068                         $user->hash_type = Config::get_value(ConfigUsermanagement::HASH_TYPE);
00069                         $algo = Users::create_hash_algorithm($user->hash_type);
00070                         $user->password = $algo->hash($password);
00071                         $this->append(CommandsFactory::create_command($user, 'update', array()));
00072                 }
00073                 return $ret;
00074         }
LoginUsersBaseCommand::do_can_execute ( user  )  [protected]

Reimplemented from CommandChain.

Definition at line 16 of file login.cmd.php.

00016                                                  {
00017                 return empty($user); // Not logged in only
00018         }
LoginUsersBaseCommand::do_create_user_dao ( params,
err  
) [protected]

Find user from parameters given.

Parameters:
array  $params
Status  $err
Returns:
DAOUsers

Definition at line 101 of file login.cmd.php.

00101                                                              {
00102                 $err->merge($this->do_validate_params($params));
00103                 $user = new DAOUsers();
00104                 $user->name = $this->params_extract_name($params);
00105                 
00106                 return $user;
00107         }
LoginUsersBaseCommand::do_execute (  )  [protected]

Reimplemented from CommandChain.

Definition at line 20 of file login.cmd.php.

00020                                         {
00021                 $ret = new Status();
00022                 $params = $this->get_params();
00023 
00024                 $user = $this->do_create_user_dao($params, $ret);
00025                 if ($ret->is_error()) {
00026                         return $ret;
00027                 }
00028                 
00029                 $this->do_prepare_user_dao($user);
00030                 // Try to load user
00031                 if ($user->find(IDataObject::AUTOFETCH)) {
00032                         $ret->merge($this->check_password_hash($user, $params));                        
00033                         if ($ret->is_ok()) {
00034                                 $this->set_result($user);
00035                                 switch ($user->status) {
00036                                         case Users::STATUS_UNCONFIRMED;
00037                                                 $ret->append(tr('Your account has not yet been activated', 'users')); 
00038                                                 break;
00039                                         case Users::STATUS_ACTIVE:
00040                                                 // We can login this user
00041                                                 $this->append(CommandsFactory::create_command($user, 'restartsession', false));
00042                                                 $this->append(CommandsFactory::create_command($user, 'loginknown', $params));
00043                                                 break;
00044                                         default:
00045                                                 $ret->append($this->do_get_default_error_message());
00046                                                 break;
00047                                 }
00048                         }
00049                 }
00050                 else {
00051                         $ret->append($this->do_get_default_error_message());
00052                 }
00053                 return $ret;
00054         }
LoginUsersBaseCommand::do_get_default_error_message (  )  [protected]

Returns default error message.

Definition at line 142 of file login.cmd.php.

00142                                                           {
00143                 return tr('Username or password are wrong. Please try again.', 'users');                
00144         }
LoginUsersBaseCommand::do_prepare_user_dao ( DAOUsers user  )  [protected]

Prepares dao object.

Parameters:
DAOUsers  $user

Definition at line 135 of file login.cmd.php.

00135                                                                {
00136                 $user->add_where('status', DBWhere::OP_IN, array(Users::STATUS_ACTIVE, Users::STATUS_UNCONFIRMED));             
00137         }
LoginUsersBaseCommand::do_validate_params ( params  )  [protected]

Check params.

Parameters:
array  $params
Returns:
Status $err

Definition at line 115 of file login.cmd.php.

00115                                                        {
00116                 $err = new Status();
00117                 $name = $this->params_extract_name($params);
00118                 $pwd = $this->params_extract_password($params);
00119                 
00120                 if ($name == '') {
00121                         $err->append(tr('Please provide a user name for login', 'users'));
00122                 }
00123                 if ($pwd == '') {
00124                         $err->append(tr('Please provide a password for login', 'users'));
00125                 }
00126                 
00127                 return $err;
00128         }       
LoginUsersBaseCommand::get_name (  ) 

Returns title of command.

Reimplemented from CommandBase.

Definition at line 12 of file login.cmd.php.

00012                                    {
00013                 return 'login';
00014         }
LoginUsersBaseCommand::params_extract_name ( params  )  [protected]

Extracts name from param array.

Returns:
string

Definition at line 81 of file login.cmd.php.

00081                                                         {
00082                 return Cast::string(Arr::get_item($params, 'name', ''));
00083         } 
LoginUsersBaseCommand::params_extract_password ( params  )  [protected]

Extracts password from param array.

Returns:
string

Definition at line 90 of file login.cmd.php.

00090                                                             {
00091                 return Cast::string(Arr::get_item($params, 'password', ''));
00092         } 

The documentation for this class was generated from the following file:
  • contributions/usermanagement/behaviour/commands/base/login.cmd.php