@@ -19,14 +19,14 @@ |
||
19 | 19 | */ |
20 | 20 | class CompositionValidator extends BaseValidator implements ValidatorInterface |
21 | 21 | { |
22 | - /** |
|
23 | - * @var string |
|
24 | - */ |
|
22 | + /** |
|
23 | + * @var string |
|
24 | + */ |
|
25 | 25 | protected $error = ''; |
26 | 26 | |
27 | - /** |
|
28 | - * @var string |
|
29 | - */ |
|
27 | + /** |
|
28 | + * @var string |
|
29 | + */ |
|
30 | 30 | protected $suggestion = ''; |
31 | 31 | |
32 | 32 | /** |
@@ -6,86 +6,86 @@ |
||
6 | 6 | |
7 | 7 | class PasswordValidator |
8 | 8 | { |
9 | - /** |
|
10 | - * @var AuthConfig |
|
11 | - */ |
|
12 | - protected $config; |
|
13 | - |
|
14 | - protected $error; |
|
15 | - |
|
16 | - protected $suggestion; |
|
17 | - |
|
18 | - public function __construct(AuthConfig $config) |
|
19 | - { |
|
20 | - $this->config = $config; |
|
21 | - } |
|
22 | - |
|
23 | - /** |
|
24 | - * Checks a password against all of the Validators specified |
|
25 | - * in `$passwordValidators` setting in Config\Auth.php. |
|
26 | - * |
|
27 | - * @param string $password |
|
28 | - * @param User $user |
|
29 | - * |
|
30 | - * @return bool |
|
31 | - */ |
|
32 | - public function check(string $password, User $user = null): bool |
|
33 | - { |
|
34 | - if (is_null($user)) |
|
35 | - { |
|
36 | - throw AuthException::forNoEntityProvided(); |
|
37 | - } |
|
38 | - |
|
39 | - $password = trim($password); |
|
40 | - |
|
41 | - if (empty($password)) |
|
42 | - { |
|
43 | - $this->error = lang('Auth.errorPasswordEmpty'); |
|
44 | - |
|
45 | - return false; |
|
46 | - } |
|
47 | - |
|
48 | - $valid = false; |
|
49 | - |
|
50 | - foreach ($this->config->passwordValidators as $className) |
|
51 | - { |
|
52 | - $class = new $className(); |
|
53 | - $class->setConfig($this->config); |
|
54 | - |
|
55 | - if ($class->check($password, $user) === false) |
|
56 | - { |
|
57 | - $this->error = $class->error(); |
|
58 | - $this->suggestion = $class->suggestion(); |
|
59 | - |
|
60 | - $valid = false; |
|
61 | - break; |
|
62 | - } |
|
63 | - |
|
64 | - $valid = true; |
|
65 | - } |
|
66 | - |
|
67 | - return $valid; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Returns the current error, as defined by validator |
|
72 | - * it failed to pass. |
|
73 | - * |
|
74 | - * @return mixed |
|
75 | - */ |
|
76 | - public function error() |
|
77 | - { |
|
78 | - return $this->error; |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Returns a string with any suggested fix |
|
83 | - * based on the validator it failed to pass. |
|
84 | - * |
|
85 | - * @return mixed |
|
86 | - */ |
|
87 | - public function suggestion() |
|
88 | - { |
|
89 | - return $this->suggestion; |
|
90 | - } |
|
9 | + /** |
|
10 | + * @var AuthConfig |
|
11 | + */ |
|
12 | + protected $config; |
|
13 | + |
|
14 | + protected $error; |
|
15 | + |
|
16 | + protected $suggestion; |
|
17 | + |
|
18 | + public function __construct(AuthConfig $config) |
|
19 | + { |
|
20 | + $this->config = $config; |
|
21 | + } |
|
22 | + |
|
23 | + /** |
|
24 | + * Checks a password against all of the Validators specified |
|
25 | + * in `$passwordValidators` setting in Config\Auth.php. |
|
26 | + * |
|
27 | + * @param string $password |
|
28 | + * @param User $user |
|
29 | + * |
|
30 | + * @return bool |
|
31 | + */ |
|
32 | + public function check(string $password, User $user = null): bool |
|
33 | + { |
|
34 | + if (is_null($user)) |
|
35 | + { |
|
36 | + throw AuthException::forNoEntityProvided(); |
|
37 | + } |
|
38 | + |
|
39 | + $password = trim($password); |
|
40 | + |
|
41 | + if (empty($password)) |
|
42 | + { |
|
43 | + $this->error = lang('Auth.errorPasswordEmpty'); |
|
44 | + |
|
45 | + return false; |
|
46 | + } |
|
47 | + |
|
48 | + $valid = false; |
|
49 | + |
|
50 | + foreach ($this->config->passwordValidators as $className) |
|
51 | + { |
|
52 | + $class = new $className(); |
|
53 | + $class->setConfig($this->config); |
|
54 | + |
|
55 | + if ($class->check($password, $user) === false) |
|
56 | + { |
|
57 | + $this->error = $class->error(); |
|
58 | + $this->suggestion = $class->suggestion(); |
|
59 | + |
|
60 | + $valid = false; |
|
61 | + break; |
|
62 | + } |
|
63 | + |
|
64 | + $valid = true; |
|
65 | + } |
|
66 | + |
|
67 | + return $valid; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Returns the current error, as defined by validator |
|
72 | + * it failed to pass. |
|
73 | + * |
|
74 | + * @return mixed |
|
75 | + */ |
|
76 | + public function error() |
|
77 | + { |
|
78 | + return $this->error; |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Returns a string with any suggested fix |
|
83 | + * based on the validator it failed to pass. |
|
84 | + * |
|
85 | + * @return mixed |
|
86 | + */ |
|
87 | + public function suggestion() |
|
88 | + { |
|
89 | + return $this->suggestion; |
|
90 | + } |
|
91 | 91 | } |
@@ -4,9 +4,9 @@ |
||
4 | 4 | |
5 | 5 | class BaseValidator |
6 | 6 | { |
7 | - /** |
|
8 | - * @var AuthConfig |
|
9 | - */ |
|
7 | + /** |
|
8 | + * @var AuthConfig |
|
9 | + */ |
|
10 | 10 | protected $config; |
11 | 11 | |
12 | 12 | /** |
@@ -112,8 +112,8 @@ |
||
112 | 112 | $this->loginModel->purgeOldRememberTokens(); |
113 | 113 | } |
114 | 114 | |
115 | - // trigger login event, in case anyone cares |
|
116 | - Events::trigger('login', $user); |
|
115 | + // trigger login event, in case anyone cares |
|
116 | + Events::trigger('login', $user); |
|
117 | 117 | |
118 | 118 | return true; |
119 | 119 | } |
@@ -5,66 +5,66 @@ |
||
5 | 5 | |
6 | 6 | abstract class BaseActivator |
7 | 7 | { |
8 | - /** |
|
9 | - * @var AuthConfig |
|
10 | - */ |
|
11 | - protected $config; |
|
8 | + /** |
|
9 | + * @var AuthConfig |
|
10 | + */ |
|
11 | + protected $config; |
|
12 | 12 | |
13 | - /** |
|
14 | - * @var string |
|
15 | - */ |
|
16 | - protected $error = ''; |
|
13 | + /** |
|
14 | + * @var string |
|
15 | + */ |
|
16 | + protected $error = ''; |
|
17 | 17 | |
18 | - /** |
|
19 | - * Sends an activation message to user |
|
20 | - * |
|
21 | - * @param User $user |
|
22 | - * |
|
23 | - * @return bool |
|
24 | - */ |
|
25 | - abstract public function send(User $user = null): bool; |
|
18 | + /** |
|
19 | + * Sends an activation message to user |
|
20 | + * |
|
21 | + * @param User $user |
|
22 | + * |
|
23 | + * @return bool |
|
24 | + */ |
|
25 | + abstract public function send(User $user = null): bool; |
|
26 | 26 | |
27 | - /** |
|
28 | - * Sets the initial config file. |
|
29 | - * |
|
30 | - * @param AuthConfig|null $config |
|
31 | - */ |
|
32 | - public function __construct(AuthConfig $config = null) |
|
33 | - { |
|
34 | - $this->config = $config ?? config('Auth'); |
|
35 | - } |
|
27 | + /** |
|
28 | + * Sets the initial config file. |
|
29 | + * |
|
30 | + * @param AuthConfig|null $config |
|
31 | + */ |
|
32 | + public function __construct(AuthConfig $config = null) |
|
33 | + { |
|
34 | + $this->config = $config ?? config('Auth'); |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * Allows for changing the config file on the Activator. |
|
39 | - * |
|
40 | - * @param AuthConfig $config |
|
41 | - * |
|
42 | - * @return $this |
|
43 | - */ |
|
44 | - public function setConfig(AuthConfig $config) |
|
45 | - { |
|
46 | - $this->config = $config; |
|
37 | + /** |
|
38 | + * Allows for changing the config file on the Activator. |
|
39 | + * |
|
40 | + * @param AuthConfig $config |
|
41 | + * |
|
42 | + * @return $this |
|
43 | + */ |
|
44 | + public function setConfig(AuthConfig $config) |
|
45 | + { |
|
46 | + $this->config = $config; |
|
47 | 47 | |
48 | - return $this; |
|
49 | - } |
|
48 | + return $this; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Gets a config settings for current Activator. |
|
53 | - * |
|
54 | - * @return object |
|
55 | - */ |
|
56 | - public function getActivatorSettings() |
|
57 | - { |
|
58 | - return (object) $this->config->userActivators[static::class]; |
|
59 | - } |
|
51 | + /** |
|
52 | + * Gets a config settings for current Activator. |
|
53 | + * |
|
54 | + * @return object |
|
55 | + */ |
|
56 | + public function getActivatorSettings() |
|
57 | + { |
|
58 | + return (object) $this->config->userActivators[static::class]; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * Returns the current error. |
|
63 | - * |
|
64 | - * @return string |
|
65 | - */ |
|
66 | - public function error(): string |
|
67 | - { |
|
68 | - return $this->error; |
|
69 | - } |
|
61 | + /** |
|
62 | + * Returns the current error. |
|
63 | + * |
|
64 | + * @return string |
|
65 | + */ |
|
66 | + public function error(): string |
|
67 | + { |
|
68 | + return $this->error; |
|
69 | + } |
|
70 | 70 | } |
@@ -4,34 +4,34 @@ |
||
4 | 4 | |
5 | 5 | class UserActivator extends BaseActivator implements ActivatorInterface |
6 | 6 | { |
7 | - /** |
|
7 | + /** |
|
8 | 8 | * Sends activation message to the user via specified class |
9 | 9 | * in `$requireActivation` setting in Config\Auth.php. |
10 | - * |
|
11 | - * @param User $user |
|
12 | - * |
|
13 | - * @return bool |
|
14 | - */ |
|
15 | - public function send(User $user = null): bool |
|
16 | - { |
|
17 | - if (! $this->config->requireActivation) |
|
18 | - { |
|
19 | - return true; |
|
20 | - } |
|
10 | + * |
|
11 | + * @param User $user |
|
12 | + * |
|
13 | + * @return bool |
|
14 | + */ |
|
15 | + public function send(User $user = null): bool |
|
16 | + { |
|
17 | + if (! $this->config->requireActivation) |
|
18 | + { |
|
19 | + return true; |
|
20 | + } |
|
21 | 21 | |
22 | - $className = $this->config->requireActivation; |
|
22 | + $className = $this->config->requireActivation; |
|
23 | 23 | |
24 | - $class = new $className(); |
|
25 | - $class->setConfig($this->config); |
|
24 | + $class = new $className(); |
|
25 | + $class->setConfig($this->config); |
|
26 | 26 | |
27 | - if ($class->send($user) === false) |
|
28 | - { |
|
27 | + if ($class->send($user) === false) |
|
28 | + { |
|
29 | 29 | log_message('error', "Failed to send activation messaage to: {$user->email}"); |
30 | - $this->error = $class->error(); |
|
30 | + $this->error = $class->error(); |
|
31 | 31 | |
32 | - return false; |
|
33 | - } |
|
32 | + return false; |
|
33 | + } |
|
34 | 34 | |
35 | - return true; |
|
36 | - } |
|
35 | + return true; |
|
36 | + } |
|
37 | 37 | } |
@@ -27,11 +27,11 @@ |
||
27 | 27 | $settings = $this->getActivatorSettings(); |
28 | 28 | |
29 | 29 | $sent = $email->setFrom($settings->fromEmail ?? $config->fromEmail, $settings->fromName ?? $config->fromName) |
30 | - ->setTo($user->email) |
|
31 | - ->setSubject(lang('Auth.activationSubject')) |
|
32 | - ->setMessage(view($this->config->views['emailActivation'], ['hash' => $user->activate_hash])) |
|
33 | - ->setMailType('html') |
|
34 | - ->send(); |
|
30 | + ->setTo($user->email) |
|
31 | + ->setSubject(lang('Auth.activationSubject')) |
|
32 | + ->setMessage(view($this->config->views['emailActivation'], ['hash' => $user->activate_hash])) |
|
33 | + ->setMailType('html') |
|
34 | + ->send(); |
|
35 | 35 | |
36 | 36 | if (! $sent) |
37 | 37 | { |
@@ -108,7 +108,7 @@ |
||
108 | 108 | } |
109 | 109 | |
110 | 110 | $this->db->table('auth_tokens') |
111 | - ->where('expires <=', date('Y-m-d H:i:s')) |
|
112 | - ->delete(); |
|
111 | + ->where('expires <=', date('Y-m-d H:i:s')) |
|
112 | + ->delete(); |
|
113 | 113 | } |
114 | 114 | } |
@@ -8,100 +8,100 @@ |
||
8 | 8 | */ |
9 | 9 | class Auth extends BaseCollector |
10 | 10 | { |
11 | - /** |
|
12 | - * Whether this collector has data that can |
|
13 | - * be displayed in the Timeline. |
|
14 | - * |
|
15 | - * @var boolean |
|
16 | - */ |
|
17 | - protected $hasTimeline = false; |
|
11 | + /** |
|
12 | + * Whether this collector has data that can |
|
13 | + * be displayed in the Timeline. |
|
14 | + * |
|
15 | + * @var boolean |
|
16 | + */ |
|
17 | + protected $hasTimeline = false; |
|
18 | 18 | |
19 | - /** |
|
20 | - * Whether this collector needs to display |
|
21 | - * content in a tab or not. |
|
22 | - * |
|
23 | - * @var boolean |
|
24 | - */ |
|
25 | - protected $hasTabContent = true; |
|
19 | + /** |
|
20 | + * Whether this collector needs to display |
|
21 | + * content in a tab or not. |
|
22 | + * |
|
23 | + * @var boolean |
|
24 | + */ |
|
25 | + protected $hasTabContent = true; |
|
26 | 26 | |
27 | - /** |
|
28 | - * Whether this collector has data that |
|
29 | - * should be shown in the Vars tab. |
|
30 | - * |
|
31 | - * @var boolean |
|
32 | - */ |
|
33 | - protected $hasVarData = false; |
|
27 | + /** |
|
28 | + * Whether this collector has data that |
|
29 | + * should be shown in the Vars tab. |
|
30 | + * |
|
31 | + * @var boolean |
|
32 | + */ |
|
33 | + protected $hasVarData = false; |
|
34 | 34 | |
35 | - /** |
|
36 | - * The 'title' of this Collector. |
|
37 | - * Used to name things in the toolbar HTML. |
|
38 | - * |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - protected $title = 'Auth'; |
|
35 | + /** |
|
36 | + * The 'title' of this Collector. |
|
37 | + * Used to name things in the toolbar HTML. |
|
38 | + * |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + protected $title = 'Auth'; |
|
42 | 42 | |
43 | - //-------------------------------------------------------------------- |
|
43 | + //-------------------------------------------------------------------- |
|
44 | 44 | |
45 | - /** |
|
46 | - * Returns any information that should be shown next to the title. |
|
47 | - * |
|
48 | - * @return string |
|
49 | - */ |
|
50 | - public function getTitleDetails(): string |
|
51 | - { |
|
52 | - return get_class(service('authentication')); |
|
53 | - } |
|
45 | + /** |
|
46 | + * Returns any information that should be shown next to the title. |
|
47 | + * |
|
48 | + * @return string |
|
49 | + */ |
|
50 | + public function getTitleDetails(): string |
|
51 | + { |
|
52 | + return get_class(service('authentication')); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Returns the data of this collector to be formatted in the toolbar |
|
57 | - * |
|
58 | - * @return string |
|
59 | - */ |
|
60 | - public function display(): string |
|
61 | - { |
|
62 | - $authenticate = service('authentication'); |
|
55 | + /** |
|
56 | + * Returns the data of this collector to be formatted in the toolbar |
|
57 | + * |
|
58 | + * @return string |
|
59 | + */ |
|
60 | + public function display(): string |
|
61 | + { |
|
62 | + $authenticate = service('authentication'); |
|
63 | 63 | |
64 | - if ($authenticate->isLoggedIn()) |
|
65 | - { |
|
66 | - $user = $authenticate->user(); |
|
67 | - $groups = model(GroupModel::class)->getGroupsForUser($user->id); |
|
64 | + if ($authenticate->isLoggedIn()) |
|
65 | + { |
|
66 | + $user = $authenticate->user(); |
|
67 | + $groups = model(GroupModel::class)->getGroupsForUser($user->id); |
|
68 | 68 | |
69 | - $groupsForUser = implode(', ', array_column($groups, 'name')); |
|
69 | + $groupsForUser = implode(', ', array_column($groups, 'name')); |
|
70 | 70 | |
71 | - $html = '<h3>Current User</h3>'; |
|
72 | - $html .= '<table><tbody>'; |
|
73 | - $html .= "<tr><td style='width:150px;'>User ID</td><td>#{$user->id}</td></tr>"; |
|
74 | - $html .= "<tr><td>Username</td><td>{$user->username}</td></tr>"; |
|
75 | - $html .= "<tr><td>Email</td><td>{$user->email}</td></tr>"; |
|
76 | - $html .= "<tr><td>Groups</td><td>{$groupsForUser}</td></tr>"; |
|
77 | - $html .= '</tbody></table>'; |
|
78 | - } |
|
79 | - else |
|
80 | - { |
|
81 | - $html = '<p>Not logged in.</p>'; |
|
82 | - } |
|
83 | - return $html; |
|
84 | - } |
|
71 | + $html = '<h3>Current User</h3>'; |
|
72 | + $html .= '<table><tbody>'; |
|
73 | + $html .= "<tr><td style='width:150px;'>User ID</td><td>#{$user->id}</td></tr>"; |
|
74 | + $html .= "<tr><td>Username</td><td>{$user->username}</td></tr>"; |
|
75 | + $html .= "<tr><td>Email</td><td>{$user->email}</td></tr>"; |
|
76 | + $html .= "<tr><td>Groups</td><td>{$groupsForUser}</td></tr>"; |
|
77 | + $html .= '</tbody></table>'; |
|
78 | + } |
|
79 | + else |
|
80 | + { |
|
81 | + $html = '<p>Not logged in.</p>'; |
|
82 | + } |
|
83 | + return $html; |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Gets the "badge" value for the button. |
|
88 | - * |
|
89 | - * @return int|null ID of the current User, or null when not logged in |
|
90 | - */ |
|
91 | - public function getBadgeValue(): ?int |
|
92 | - { |
|
93 | - return service('authentication')->isLoggedIn() ? service('authentication')->id() : null; |
|
94 | - } |
|
86 | + /** |
|
87 | + * Gets the "badge" value for the button. |
|
88 | + * |
|
89 | + * @return int|null ID of the current User, or null when not logged in |
|
90 | + */ |
|
91 | + public function getBadgeValue(): ?int |
|
92 | + { |
|
93 | + return service('authentication')->isLoggedIn() ? service('authentication')->id() : null; |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * Display the icon. |
|
98 | - * |
|
99 | - * Icon from https://icons8.com - 1em package |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - public function icon(): string |
|
104 | - { |
|
105 | - return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAADLSURBVEhL5ZRLCsIwGAa7UkE9gd5HUfEoekxxJx7AhXoCca/fhESkJiQxBHwMDG3S/9EmJc0n0JMruZVXK/fMdWQRY7mXt4A7OZJvwZu74hRayIEc2nv3jGtXZrOWrnifiRY0OkhiWK5sWGeS52bkZymJ2ZhRJmwmySxLCL6CmIsZZUIixkiNezCRR+kSUyWH3Cgn6SuQIk2iuOBckvN+t8FMnq1TJloUN3jefN9mhvJeCAVWb8CyUDj0vxc3iPFHDaofFdUPu2+iae7nYJMCY/1bpAAAAABJRU5ErkJggg=='; |
|
106 | - } |
|
96 | + /** |
|
97 | + * Display the icon. |
|
98 | + * |
|
99 | + * Icon from https://icons8.com - 1em package |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + public function icon(): string |
|
104 | + { |
|
105 | + return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAADLSURBVEhL5ZRLCsIwGAa7UkE9gd5HUfEoekxxJx7AhXoCca/fhESkJiQxBHwMDG3S/9EmJc0n0JMruZVXK/fMdWQRY7mXt4A7OZJvwZu74hRayIEc2nv3jGtXZrOWrnifiRY0OkhiWK5sWGeS52bkZymJ2ZhRJmwmySxLCL6CmIsZZUIixkiNezCRR+kSUyWH3Cgn6SuQIk2iuOBckvN+t8FMnq1TJloUN3jefN9mhvJeCAVWb8CyUDj0vxc3iPFHDaofFdUPu2+iae7nYJMCY/1bpAAAAABJRU5ErkJggg=='; |
|
106 | + } |
|
107 | 107 | } |