Change `notValid` to `invalid`
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / data / user / UserRegistrationAction.class.php
1 <?php
2 namespace wcf\data\user;
3 use wcf\util\UserRegistrationUtil;
4 use wcf\util\UserUtil;
5
6 /**
7 * Executes user registration-related actions.
8 *
9 * @author Marcel Werk
10 * @copyright 2001-2016 WoltLab GmbH
11 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
12 * @package WoltLabSuite\Core\Data\User
13 */
14 class UserRegistrationAction extends UserAction {
15 /**
16 * @inheritDoc
17 */
18 protected $allowGuestAccess = ['validateEmailAddress', 'validatePassword', 'validateUsername'];
19
20 /**
21 * Validates the validate username function.
22 */
23 public function validateValidateUsername() {
24 $this->readString('username');
25 }
26
27 /**
28 * Validates the validate email address function.
29 */
30 public function validateValidateEmailAddress() {
31 $this->readString('email');
32 }
33
34 /**
35 * Validates the validate password function.
36 */
37 public function validateValidatePassword() {
38 $this->readString('password');
39 }
40
41 /**
42 * Validates the given username.
43 *
44 * @return array
45 */
46 public function validateUsername() {
47 if (!UserRegistrationUtil::isValidUsername($this->parameters['username'])) {
48 return [
49 'isValid' => false,
50 'error' => 'invalid'
51 ];
52 }
53
54 if (!UserUtil::isAvailableUsername($this->parameters['username'])) {
55 return [
56 'isValid' => false,
57 'error' => 'notUnique'
58 ];
59 }
60
61 return [
62 'isValid' => true
63 ];
64 }
65
66 /**
67 * Validates given email address.
68 *
69 * @return array
70 */
71 public function validateEmailAddress() {
72 if (!UserRegistrationUtil::isValidEmail($this->parameters['email'])) {
73 return [
74 'isValid' => false,
75 'error' => 'invalid'
76 ];
77 }
78
79 if (!UserUtil::isAvailableEmail($this->parameters['email'])) {
80 return [
81 'isValid' => false,
82 'error' => 'notUnique'
83 ];
84 }
85
86 return [
87 'isValid' => true
88 ];
89 }
90
91 /**
92 * Validates given password.
93 *
94 * @return array
95 */
96 public function validatePassword() {
97 if (!UserRegistrationUtil::isSecurePassword($this->parameters['password'])) {
98 return [
99 'isValid' => false,
100 'error' => 'notSecure'
101 ];
102 }
103
104 return [
105 'isValid' => true
106 ];
107 }
108 }