.

UpdateUsersBaseCommand Class Reference
[Usermanagement]

Update a user. More...

Inheritance diagram for UpdateUsersBaseCommand:
CommandChain CommandBase ICommand IAction ISerializable UpdateUsersCommand

List of all members.

Protected Member Functions

  check_for_email_confirmation ($user, &$params)
  Check if an email confirmation must be created (that is user changed email).
  check_for_pwd_confirmation ($user, &$params)
  Check if an password confirmation must be created (that is user changed password).
  do_execute ()
  Execute this command.
  hash_password ($user, &$params)
  Hash the password.
  link_roles ($user, $params)
  Link Roles.
  send_email_notification ($user, $email)
  Create an email change notification.
  send_pwd_notification ($user, $pwd)
  Create a password change notification.

Detailed Description

Update a user.

Author:
Gerd Riesselmann

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


Member Function Documentation

UpdateUsersBaseCommand::check_for_email_confirmation ( user,
&$  params  
) [protected]

Check if an email confirmation must be created (that is user changed email).

Since:
0.5.1

Definition at line 59 of file updateusers.cmd.php.

00059                                                                          {
00060                 $email = Arr::get_item($params, 'email', $user->email);
00061                 if (!Users::current_has_role(USER_ROLE_ADMIN)) {
00062                         // None-admins cannot change mail directly!
00063                         if ($user->email !== $email) {
00064                                 $this->send_email_notification($user, $email);
00065                         } 
00066                         unset($params['email']);
00067                 }
00068         }
UpdateUsersBaseCommand::check_for_pwd_confirmation ( user,
&$  params  
) [protected]

Check if an password confirmation must be created (that is user changed password).

Since:
0.6

Definition at line 75 of file updateusers.cmd.php.

00075                                                                        {
00076                 $pwd = Arr::get_item($params, 'password', $user->password);
00077                 if (!Users::current_has_role(USER_ROLE_ADMIN)) {
00078                         // None-admins cannot change mail directly!
00079                         if ($user->password !== $pwd) {
00080                                 $this->send_pwd_notification($user, $pwd);
00081                         } 
00082                         unset($params['password']);
00083                 }
00084         }       
UpdateUsersBaseCommand::do_execute (  )  [protected]

Execute this command.

Reimplemented from CommandChain.

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

00012                                         {
00013                 $ret = new Status();
00014                 
00015                 $params = $this->get_params();
00016                 $user = $this->get_instance();
00017                 
00018                 // Validate
00019                 $cmd_validate = CommandsFactory::create_command($user, 'validate', $params);
00020                 $ret->merge($cmd_validate->execute());
00021 
00022                 if ($ret->is_ok()) {
00023                         // Check if to send an email confirmation mail
00024                         $this->check_for_email_confirmation($user, $params);
00025                         
00026                         // HAsh password
00027                         $this->hash_password($user, $params);
00028                         $this->check_for_pwd_confirmation($user, $params);
00029         
00030                         // Chain next commands
00031                         Load::commands('generics/update');
00032                         $this->append(new UpdateCommand($user, $params));
00033         
00034                         $ret->merge($this->link_roles($user, $params));
00035                 }
00036                 return $ret;
00037         }       
UpdateUsersBaseCommand::hash_password ( user,
&$  params  
) [protected]

Hash the password.

Since:
0.5.1

Definition at line 44 of file updateusers.cmd.php.

00044                                                           {
00045                 $pwd = Arr::get_item($params, 'password', '');
00046                 if (!empty($pwd)) {
00047                         $params['password'] = Users::create_hash($pwd, $user->hash_type);
00048                 }
00049                 else {
00050                         unset($params['password']);
00051                 }
00052         }       
UpdateUsersBaseCommand::link_roles ( user,
params  
) [protected]

Link Roles.

Parameters:
DAOUsers  $user
array  $params
Returns:
Status

Definition at line 123 of file updateusers.cmd.php.

00123                                                       {
00124                 $ret = new Status();
00125                 $roles = Arr::get_item($params, 'roles', false);
00126                 if ($roles === false) {
00127                         return $ret;
00128                 }
00129                 
00130                 if (empty($roles)) {
00131                         $ret->append(tr('You must assign at least one role', 'users'));
00132                         return $ret;
00133                 }
00134                 
00135                 // delete old
00136                 $dao = new DAOUsers2userroles();
00137                 $dao->add_where('id_user', '=', $user->id);
00138                 $sql = $dao->create_delete_query(DAOUsers2userroles::WHERE_ONLY)->get_sql();
00139                 Load::commands('generics/execute.sql');
00140                 $this->append(new ExecuteSqlCommand($sql));
00141                 
00142                 // Append link creation commands
00143                 foreach($roles as $role) {
00144                         $params_link = array(
00145                                 'id_user' => $user->id,
00146                                 'id_role' => $role 
00147                         );
00148                         $this->append(CommandsFactory::create_command('users2userroles', 'create', $params_link));
00149                 }
00150                 return $ret;
00151         }               
UpdateUsersBaseCommand::send_email_notification ( user,
email  
) [protected]

Create an email change notification.

Since:
0.5.1

Definition at line 91 of file updateusers.cmd.php.

00091                                                                   {
00092                 // Indirectly change mail, if desired
00093                 $params = array(
00094                         'id_item' => $user->id,
00095                         'action' => 'changeemail',
00096                         'data' => $email
00097                 );
00098                 $this->append(CommandsFactory::create_command('confirmations', 'create', $params));
00099         }
UpdateUsersBaseCommand::send_pwd_notification ( user,
pwd  
) [protected]

Create a password change notification.

Since:
0.6

Definition at line 106 of file updateusers.cmd.php.

00106                                                               {
00107                 // Indirectly change mail, if desired
00108                 $params = array(
00109                         'id_item' => $user->id,
00110                         'action' => 'changepassword',
00111                         'data' => $pwd
00112                 );
00113                 $this->append(CommandsFactory::create_command('confirmations', 'create', $params));
00114         }

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