00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010 class ValidateUsersBaseCommand extends CommandComposite {
00011
00012
00013
00014 protected function do_execute() {
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
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 }
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 protected function validate_email($email) {
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 }
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 protected function validate_username($name) {
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 }
00078 }