1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee\Modules\Users;
13
14 15 16
17 class IsUniqueOperation extends \ICanBoogie\Operation
18 {
19 protected function get_controls()
20 {
21 return [
22
23 self::CONTROL_AUTHENTICATION => true
24
25 ] + parent::get_controls();
26 }
27
28 protected function validate(\ICanboogie\Errors $errors)
29 {
30 $request = $this->request;
31 $username = $request[User::USERNAME];
32 $email = $request[User::EMAIL];
33 $uid = $request[User::UID] ?: 0;
34
35 if ($username)
36 {
37 if ($this->module->model->select('uid')->where('username = ? AND uid != ?', $username, $uid)->rc)
38 {
39 $errors[User::USERNAME] = 'This username is already used';
40 }
41 }
42 else
43 {
44 $errors[User::USERNAME] = null;
45 }
46
47 if ($email)
48 {
49 if ($this->module->model->select('uid')->where('email = ? AND uid != ?', $email, $uid)->rc)
50 {
51 $errors[User::EMAIL] = 'This email is already used';
52 }
53 }
54 else
55 {
56 $errors[User::EMAIL] = null;
57 }
58
59 return count($errors) == 0;
60 }
61
62 protected function process()
63 {
64 return true;
65 }
66 }