Debian Codegraph @

classes/Users/AdminUser.php

raw symbols SCIP
1 <?php
2
3 /**
4 * dmarc-srg - A php parser, viewer and summary report generator for incoming DMARC reports.
5 * Copyright (C) 2023 Aleksey Andreev (liuch)
6 *
7 * Available at:
8 * https://github.com/liuch/dmarc-srg
9 *
10 * This program is free software: you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation, either version 3 of the License.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18 *
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
21 *
22 * =========================
23 *
24 * This file contains the class AdminUser
25 *
26 * @category API
27 * @package DmarcSrg
28 * @author Aleksey Andreev (liuch)
29 * @license https://www.gnu.org/licenses/gpl-3.0.html GNU/GPLv3
30 */
31
32 namespace Liuch\DmarcSrg\Users;
33
34 use Liuch\DmarcSrg\Core;
35
36 /**
37 * The class implements the built-in admin user
38 */
39 class AdminUser extends User
40 {
41 /** @var Core */
42 private $core = null;
43
44 /**
45 * Constructor
46 *
47 * @param Core|null $core Instance of the Core class
48 *
49 * @return void
50 */
51 public function __construct($core = null)
52 {
53 $this->core = $core ?? Core::instance();
54 }
55
56 /**
57 * Returns the admin Id
58 *
59 * @return int
60 */
61 public function id():int
62 {
63 return 0;
64 }
65
66 /**
67 * Returns the admin name
68 *
69 * @return string
70 */
71 public function name(): string
72 {
73 return 'admin';
74 }
75
76 /**
77 * Returns the admin's access level
78 *
79 * @return int
80 */
81 public function level(): int
82 {
83 return static::LEVEL_ADMIN;
84 }
85
86 /**
87 * Checks if the user is enabled
88 *
89 * @return bool
90 */
91 public function isEnabled(): bool
92 {
93 return true;
94 }
95
96 /**
97 * Returns the admin's data as an array
98 *
99 * @return array
100 */
101 public function toArray(): array
102 {
103 return [
104 'id' => $this->id(),
105 'name' => $this->name(),
106 'level' => $this->level(),
107 'enabled' => true
108 ];
109 }
110
111 /**
112 * Verifies the passed password with the password from the configuration file
113 *
114 * @param string $password Password to validate
115 *
116 * @return bool
117 */
118 public function verifyPassword(string $password): bool
119 {
120 $r_password = $this->core->config('admin/password');
121 return $r_password === null || ($r_password !== '' && $r_password === $password);
122 }
123 }