Rev 1090 | Rev 1119 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1090 | Rev 1116 | ||
---|---|---|---|
Line 24... | Line 24... | ||
24 | // phpcs:enable PSR1.Files.SideEffects |
24 | // phpcs:enable PSR1.Files.SideEffects |
25 | 25 | ||
26 | class OIDplusRA extends OIDplusBaseClass { |
26 | class OIDplusRA extends OIDplusBaseClass { |
27 | private $email = null; |
27 | private $email = null; |
28 | 28 | ||
- | 29 | /** |
|
- | 30 | * @param string $email |
|
- | 31 | */ |
|
29 | public function __construct($email) { |
32 | public function __construct(string $email) { |
30 | $this->email = $email; |
33 | $this->email = $email; |
31 | } |
34 | } |
32 | 35 | ||
- | 36 | /** |
|
- | 37 | * @return string |
|
- | 38 | */ |
|
33 | public function raEmail() { |
39 | public function raEmail(): string { |
34 | return $this->email; |
40 | return $this->email; |
35 | } |
41 | } |
36 | 42 | ||
- | 43 | /** |
|
- | 44 | * @return bool |
|
- | 45 | * @throws OIDplusException |
|
- | 46 | */ |
|
37 | public function existing() { |
47 | public function existing(): bool { |
38 | $res = OIDplus::db()->query("select email from ###ra where email = ?", array($this->email)); |
48 | $res = OIDplus::db()->query("select email from ###ra where email = ?", array($this->email)); |
39 | return ($res->any()); |
49 | return ($res->any()); |
40 | } |
50 | } |
41 | 51 | ||
- | 52 | /** |
|
- | 53 | * @return string |
|
- | 54 | * @throws OIDplusException |
|
- | 55 | */ |
|
42 | public function raName() { |
56 | public function raName(): string { |
43 | $res = OIDplus::db()->query("select ra_name from ###ra where email = ?", array($this->email)); |
57 | $res = OIDplus::db()->query("select ra_name from ###ra where email = ?", array($this->email)); |
44 | if (!$res->any()) return _L('(RA not in database)'); |
58 | if (!$res->any()) return _L('(RA not in database)'); |
45 | $row = $res->fetch_array(); |
59 | $row = $res->fetch_array(); |
46 | return $row['ra_name']; |
60 | return $row['ra_name']; |
47 | } |
61 | } |
48 | 62 | ||
- | 63 | /** |
|
- | 64 | * @return OIDplusRA[] |
|
- | 65 | * @throws OIDplusException |
|
- | 66 | */ |
|
49 | public static function getAllRAs() { |
67 | public static function getAllRAs(): array { |
50 | $out = array(); |
68 | $out = array(); |
51 | $res = OIDplus::db()->query("select email from ###ra"); |
69 | $res = OIDplus::db()->query("select email from ###ra"); |
52 | while ($row = $res->fetch_array()) { |
70 | while ($row = $res->fetch_array()) { |
53 | $out[] = new OIDplusRA($row['email']); |
71 | $out[] = new OIDplusRA($row['email']); |
54 | } |
72 | } |
55 | return $out; |
73 | return $out; |
56 | } |
74 | } |
57 | 75 | ||
- | 76 | /** |
|
- | 77 | * @param string $new_password |
|
- | 78 | * @return void |
|
- | 79 | * @throws OIDplusException |
|
- | 80 | */ |
|
58 | public function change_password($new_password) { |
81 | public function change_password(string $new_password) { |
59 | $authInfo = OIDplus::authUtils()->raGeneratePassword($new_password); |
82 | $authInfo = OIDplus::authUtils()->raGeneratePassword($new_password); |
60 | $calc_authkey = $authInfo->getAuthKey(); |
83 | $calc_authkey = $authInfo->getAuthKey(); |
61 | OIDplus::db()->query("update ###ra set authkey=? where email = ?", array($calc_authkey, $this->email)); |
84 | OIDplus::db()->query("update ###ra set authkey=? where email = ?", array($calc_authkey, $this->email)); |
62 | } |
85 | } |
63 | 86 | ||
- | 87 | /** |
|
- | 88 | * @param string $new_email |
|
- | 89 | * @return void |
|
- | 90 | * @throws OIDplusException |
|
- | 91 | */ |
|
64 | public function change_email($new_email) { |
92 | public function change_email(string $new_email) { |
65 | OIDplus::db()->query("update ###ra set email = ? where email = ?", array($new_email, $this->email)); |
93 | OIDplus::db()->query("update ###ra set email = ? where email = ?", array($new_email, $this->email)); |
66 | } |
94 | } |
67 | 95 | ||
- | 96 | /** |
|
- | 97 | * @param string|null $new_password |
|
- | 98 | * @return void |
|
- | 99 | * @throws OIDplusException |
|
- | 100 | */ |
|
68 | public function register_ra($new_password) { |
101 | public function register_ra(/*?string*/ $new_password) { |
69 | if (is_null($new_password)) { |
102 | if (is_null($new_password)) { |
70 | // Invalid password (used for LDAP/OAuth) |
103 | // Invalid password (used for LDAP/OAuth) |
71 | $calc_authkey = ''; |
104 | $calc_authkey = ''; |
72 | } else { |
105 | } else { |
73 | $authInfo = OIDplus::authUtils()->raGeneratePassword($new_password); |
106 | $authInfo = OIDplus::authUtils()->raGeneratePassword($new_password); |
Line 75... | Line 108... | ||
75 | } |
108 | } |
76 | 109 | ||
77 | OIDplus::db()->query("insert into ###ra (authkey, email, registered, ra_name, personal_name, organization, office, street, zip_town, country, phone, mobile, fax) values (?, ?, ".OIDplus::db()->sqlDate().", ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", array($calc_authkey, $this->email, "", "", "", "", "", "", "", "", "", "")); |
110 | OIDplus::db()->query("insert into ###ra (authkey, email, registered, ra_name, personal_name, organization, office, street, zip_town, country, phone, mobile, fax) values (?, ?, ".OIDplus::db()->sqlDate().", ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", array($calc_authkey, $this->email, "", "", "", "", "", "", "", "", "", "")); |
78 | } |
111 | } |
79 | 112 | ||
- | 113 | /** |
|
- | 114 | * @return OIDplusRAAuthInfo|null |
|
- | 115 | * @throws OIDplusException |
|
- | 116 | */ |
|
80 | public function getAuthInfo()/*: ?OIDplusRAAuthInfo*/ { |
117 | public function getAuthInfo()/*: ?OIDplusRAAuthInfo*/ { |
81 | $ra_res = OIDplus::db()->query("select authkey from ###ra where email = ?", array($this->email)); |
118 | $ra_res = OIDplus::db()->query("select authkey from ###ra where email = ?", array($this->email)); |
82 | if (!$ra_res->any()) return null; // User not found |
119 | if (!$ra_res->any()) return null; // User not found |
83 | $ra_row = $ra_res->fetch_array(); |
120 | $ra_row = $ra_res->fetch_array(); |
84 | 121 | ||
85 | return new OIDplusRAAuthInfo($ra_row['authkey']); |
122 | return new OIDplusRAAuthInfo($ra_row['authkey']); |
86 | } |
123 | } |
87 | 124 | ||
- | 125 | /** |
|
- | 126 | * @param string $password |
|
- | 127 | * @return bool |
|
- | 128 | * @throws OIDplusException |
|
- | 129 | */ |
|
88 | public function checkPassword($password) { |
130 | public function checkPassword(string $password): bool { |
89 | return OIDplus::authUtils()->raCheckPassword($this->email, $password); |
131 | return OIDplus::authUtils()->raCheckPassword($this->email, $password); |
90 | } |
132 | } |
91 | 133 | ||
- | 134 | /** |
|
- | 135 | * @return void |
|
- | 136 | * @throws OIDplusException |
|
- | 137 | */ |
|
92 | public function delete() { |
138 | public function delete() { |
93 | OIDplus::db()->query("delete from ###ra where email = ?", array($this->email)); |
139 | OIDplus::db()->query("delete from ###ra where email = ?", array($this->email)); |
94 | } |
140 | } |
95 | 141 | ||
- | 142 | /** |
|
- | 143 | * @param string $ra_name |
|
- | 144 | * @return void |
|
- | 145 | * @throws OIDplusException |
|
- | 146 | */ |
|
96 | public function setRaName($ra_name) { |
147 | public function setRaName(string $ra_name) { |
97 | OIDplus::db()->query("update ###ra set ra_name = ? where email = ?", array($ra_name, $this->email)); |
148 | OIDplus::db()->query("update ###ra set ra_name = ? where email = ?", array($ra_name, $this->email)); |
98 | } |
149 | } |
99 | 150 | ||
- | 151 | /** |
|
- | 152 | * @return bool|null |
|
- | 153 | * @throws OIDplusException |
|
- | 154 | */ |
|
100 | public function isPasswordLess() { |
155 | public function isPasswordLess()/*: ?bool*/ { |
101 | $authInfo = $this->getAuthInfo(); |
156 | $authInfo = $this->getAuthInfo(); |
102 | if (!$authInfo) return null; // user not found |
157 | if (!$authInfo) return null; // user not found |
103 | return $authInfo->isPasswordLess(); |
158 | return $authInfo->isPasswordLess(); |
104 | } |
159 | } |
105 | } |
160 | } |