.

ValidateUsersBaseCommand Class Reference
[Usermanagement]

Validate a user before create, update etc. More...

Inheritance diagram for ValidateUsersBaseCommand:
CommandComposite CommandBase ICommand IAction ISerializable ValidateUsersCommand

List of all members.

Protected Member Functions

  do_execute ()
  Execute this command.
  validate_email ($email)
  Validate the email address given.
  validate_username ($name)
  Validate the user name.

Detailed Description

Validate a user before create, update etc.

Since:
0.5.1
Author:
Gerd Riesselmann

Definition at line 10 of file validateusers.cmd.php.


Member Function Documentation

ValidateUsersBaseCommand::do_execute (  )  [protected]

Execute this command.

Reimplemented from CommandComposite.

Definition at line 14 of file validateusers.cmd.php.

00014                                         {
00015                 $ret = new Status();
00016                 
00017                 $params = $this->get_params();
00018                 
00019                 $user = $this->get_instance();
00020                 $user_is_instance = ($user instanceof DAOUsers);
00021                 $email = Arr::get_item($params, 'email', $user_is_instance ? $user->email : '');
00022                 $name = Arr::get_item($params, 'name', $user_is_instance ? $user->name : '');
00023                 
00024                 // Validate. Assume that current name/email is always OK
00025                 if (!$user_is_instance || $user->email != $email) {
00026                         $ret->merge($this->validate_email($email));
00027                 }
00028                 if (!$user_is_instance || $user->name != $name) {
00029                         $ret->merge($this->validate_username($name));
00030                 }
00031                 return $ret;
00032         }
ValidateUsersBaseCommand::validate_email ( email  )  [protected]

Validate the email address given.

Checks for valid mail address and uniqueness only

You may however overload this to do any check you like

Parameters:
string  $email
Returns:
Status

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

00044                                                   {
00045                 $ret = new Status();
00046                 if (!Validation::is_email($email)) {
00047                         $ret->append(tr('Please enter a valid email address'));
00048                         return $ret;
00049                 }
00050                                 
00051                 $user = new DAOUsers();
00052                 $user->add_where('status', '!=', Users::STATUS_DELETED);
00053                 $user->email = $email;
00054                 $c = $user->count();
00055                 if ($c > 0) {
00056                         $ret->append(tr('An user with this email address already exists', 'users'));
00057                 }
00058                 return $ret;
00059         }
ValidateUsersBaseCommand::validate_username ( name  )  [protected]

Validate the user name.

Checks for uniqueness only

You may however overload this to exclude some chars or do any check you like

Parameters:
string  $name
Returns:
Status

Definition at line 71 of file validateusers.cmd.php.

00071                                                     {
00072                 $ret = new Status();
00073                 if (!Users::is_unique_username($name)) {
00074                         $ret->append(tr('An user with this username already exists', 'users'));
00075                 }
00076                 return $ret;
00077         }

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