Rev 790 | Rev 1086 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 790 | Rev 1050 | ||
---|---|---|---|
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | /* |
3 | /* |
4 | * OIDplus 2.0 |
4 | * OIDplus 2.0 |
5 | * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft |
5 | * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft |
6 | * |
6 | * |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | * you may not use this file except in compliance with the License. |
8 | * you may not use this file except in compliance with the License. |
9 | * You may obtain a copy of the License at |
9 | * You may obtain a copy of the License at |
10 | * |
10 | * |
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
12 | * |
12 | * |
13 | * Unless required by applicable law or agreed to in writing, software |
13 | * Unless required by applicable law or agreed to in writing, software |
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | * See the License for the specific language governing permissions and |
16 | * See the License for the specific language governing permissions and |
17 | * limitations under the License. |
17 | * limitations under the License. |
18 | */ |
18 | */ |
19 | 19 | ||
20 | if (!defined('INSIDE_OIDPLUS')) die(); |
20 | namespace ViaThinkSoft\OIDplus; |
21 | 21 | ||
22 | class OIDplusRA extends OIDplusBaseClass { |
22 | class OIDplusRA extends OIDplusBaseClass { |
23 | private $email = null; |
23 | private $email = null; |
24 | 24 | ||
25 | public function __construct($email) { |
25 | public function __construct($email) { |
26 | $this->email = $email; |
26 | $this->email = $email; |
27 | } |
27 | } |
28 | 28 | ||
29 | public function raEmail() { |
29 | public function raEmail() { |
30 | return $this->email; |
30 | return $this->email; |
31 | } |
31 | } |
32 | 32 | ||
33 | public function existing() { |
33 | public function existing() { |
34 | $res = OIDplus::db()->query("select email from ###ra where email = ?", array($this->email)); |
34 | $res = OIDplus::db()->query("select email from ###ra where email = ?", array($this->email)); |
35 | return ($res->any()); |
35 | return ($res->any()); |
36 | } |
36 | } |
37 | 37 | ||
38 | public function raName() { |
38 | public function raName() { |
39 | $res = OIDplus::db()->query("select ra_name from ###ra where email = ?", array($this->email)); |
39 | $res = OIDplus::db()->query("select ra_name from ###ra where email = ?", array($this->email)); |
40 | if (!$res->any()) return _L('(RA not in database)'); |
40 | if (!$res->any()) return _L('(RA not in database)'); |
41 | $row = $res->fetch_array(); |
41 | $row = $res->fetch_array(); |
42 | return $row['ra_name']; |
42 | return $row['ra_name']; |
43 | } |
43 | } |
44 | 44 | ||
45 | public static function getAllRAs() { |
45 | public static function getAllRAs() { |
46 | $out = array(); |
46 | $out = array(); |
47 | $res = OIDplus::db()->query("select email from ###ra"); |
47 | $res = OIDplus::db()->query("select email from ###ra"); |
48 | while ($row = $res->fetch_array()) { |
48 | while ($row = $res->fetch_array()) { |
49 | $out[] = new OIDplusRA($row['email']); |
49 | $out[] = new OIDplusRA($row['email']); |
50 | } |
50 | } |
51 | return $out; |
51 | return $out; |
52 | } |
52 | } |
53 | 53 | ||
54 | public function change_password($new_password) { |
54 | public function change_password($new_password) { |
55 | $authInfo = OIDplus::authUtils()->raGeneratePassword($new_password); |
55 | $authInfo = OIDplus::authUtils()->raGeneratePassword($new_password); |
56 | $s_salt = $authInfo->getSalt(); |
56 | $s_salt = $authInfo->getSalt(); |
57 | $calc_authkey = $authInfo->getAuthKey(); |
57 | $calc_authkey = $authInfo->getAuthKey(); |
58 | OIDplus::db()->query("update ###ra set salt=?, authkey=? where email = ?", array($s_salt, $calc_authkey, $this->email)); |
58 | OIDplus::db()->query("update ###ra set salt=?, authkey=? where email = ?", array($s_salt, $calc_authkey, $this->email)); |
59 | } |
59 | } |
60 | 60 | ||
61 | public function change_email($new_email) { |
61 | public function change_email($new_email) { |
62 | OIDplus::db()->query("update ###ra set email = ? where email = ?", array($new_email, $this->email)); |
62 | OIDplus::db()->query("update ###ra set email = ? where email = ?", array($new_email, $this->email)); |
63 | } |
63 | } |
64 | 64 | ||
65 | public function register_ra($new_password) { |
65 | public function register_ra($new_password) { |
66 | if (is_null($new_password)) { |
66 | if (is_null($new_password)) { |
67 | // Invalid password (used for LDAP/OAuth) |
67 | // Invalid password (used for LDAP/OAuth) |
68 | $s_salt = ''; |
68 | $s_salt = ''; |
69 | $calc_authkey = ''; |
69 | $calc_authkey = ''; |
70 | } else { |
70 | } else { |
71 | $authInfo = OIDplus::authUtils()->raGeneratePassword($new_password); |
71 | $authInfo = OIDplus::authUtils()->raGeneratePassword($new_password); |
72 | $s_salt = $authInfo->getSalt(); |
72 | $s_salt = $authInfo->getSalt(); |
73 | $calc_authkey = $authInfo->getAuthKey(); |
73 | $calc_authkey = $authInfo->getAuthKey(); |
74 | } |
74 | } |
75 | 75 | ||
76 | OIDplus::db()->query("insert into ###ra (salt, authkey, email, registered, ra_name, personal_name, organization, office, street, zip_town, country, phone, mobile, fax) values (?, ?, ?, ".OIDplus::db()->sqlDate().", ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", array($s_salt, $calc_authkey, $this->email, "", "", "", "", "", "", "", "", "", "")); |
76 | OIDplus::db()->query("insert into ###ra (salt, authkey, email, registered, ra_name, personal_name, organization, office, street, zip_town, country, phone, mobile, fax) values (?, ?, ?, ".OIDplus::db()->sqlDate().", ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", array($s_salt, $calc_authkey, $this->email, "", "", "", "", "", "", "", "", "", "")); |
77 | } |
77 | } |
78 | 78 | ||
79 | public function getAuthInfo()/*: ?OIDplusRAAuthInfo*/ { |
79 | public function getAuthInfo()/*: ?OIDplusRAAuthInfo*/ { |
80 | $ra_res = OIDplus::db()->query("select authkey, salt from ###ra where email = ?", array($this->email)); |
80 | $ra_res = OIDplus::db()->query("select authkey, salt from ###ra where email = ?", array($this->email)); |
81 | if (!$ra_res->any()) return null; // User not found |
81 | if (!$ra_res->any()) return null; // User not found |
82 | $ra_row = $ra_res->fetch_array(); |
82 | $ra_row = $ra_res->fetch_array(); |
83 | 83 | ||
84 | return new OIDplusRAAuthInfo($ra_row['salt'], $ra_row['authkey']); |
84 | return new OIDplusRAAuthInfo($ra_row['salt'], $ra_row['authkey']); |
85 | } |
85 | } |
86 | 86 | ||
87 | public function checkPassword($password) { |
87 | public function checkPassword($password) { |
88 | return OIDplus::authUtils()->raCheckPassword($this->email, $password); |
88 | return OIDplus::authUtils()->raCheckPassword($this->email, $password); |
89 | } |
89 | } |
90 | 90 | ||
91 | public function delete() { |
91 | public function delete() { |
92 | OIDplus::db()->query("delete from ###ra where email = ?", array($this->email)); |
92 | OIDplus::db()->query("delete from ###ra where email = ?", array($this->email)); |
93 | } |
93 | } |
94 | 94 | ||
95 | public function setRaName($ra_name) { |
95 | public function setRaName($ra_name) { |
96 | OIDplus::db()->query("update ###ra set ra_name = ? where email = ?", array($ra_name, $this->email)); |
96 | OIDplus::db()->query("update ###ra set ra_name = ? where email = ?", array($ra_name, $this->email)); |
97 | } |
97 | } |
98 | 98 | ||
99 | public function isPasswordLess() { |
99 | public function isPasswordLess() { |
100 | $authInfo = $this->getAuthInfo(); |
100 | $authInfo = $this->getAuthInfo(); |
101 | if (!$authInfo) return null; // user not found |
101 | if (!$authInfo) return null; // user not found |
102 | return $authInfo->isPasswordLess(); |
102 | return $authInfo->isPasswordLess(); |
103 | } |
103 | } |
104 | } |
104 | } |
105 | 105 |