Subversion Repositories oidplus

Rev

Rev 433 | Rev 454 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 daniel-mar 1
<?php
2
 
3
/*
4
 * OIDplus 2.0
5
 * Copyright 2019 Daniel Marschall, ViaThinkSoft
6
 *
7
 * Licensed under the Apache License, Version 2.0 (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
10
 *
11
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 */
19
 
20
class OIDplusRA {
21
        private $email = null;
22
 
115 daniel-mar 23
        public function __construct($email) {
2 daniel-mar 24
                $this->email = $email;
25
        }
26
 
115 daniel-mar 27
        public function raEmail() {
28
                return $this->email;
29
        }
329 daniel-mar 30
 
253 daniel-mar 31
        public function existing() {
261 daniel-mar 32
                $res = OIDplus::db()->query("select email from ###ra where email = ?", array($this->email));
253 daniel-mar 33
                return ($res->num_rows() > 0);
34
        }
115 daniel-mar 35
 
2 daniel-mar 36
        public function raName() {
261 daniel-mar 37
                $res = OIDplus::db()->query("select ra_name from ###ra where email = ?", array($this->email));
360 daniel-mar 38
                if ($res->num_rows() == 0) return _L('(RA not in database)');
236 daniel-mar 39
                $row = $res->fetch_array();
2 daniel-mar 40
                return $row['ra_name'];
41
        }
42
 
115 daniel-mar 43
        public static function getAllRAs() {
44
                $out = array();
261 daniel-mar 45
                $res = OIDplus::db()->query("select email from ###ra");
236 daniel-mar 46
                while ($row = $res->fetch_array()) {
115 daniel-mar 47
                        $out[] = new OIDplusRA($row['email']);
48
                }
49
                return $out;
50
        }
51
 
52
        public function change_password($new_password) {
421 daniel-mar 53
                list($s_salt, $calc_authkey) = OIDplus::authUtils()->raGeneratePassword($new_password);
261 daniel-mar 54
                OIDplus::db()->query("update ###ra set salt=?, authkey=? where email = ?", array($s_salt, $calc_authkey, $this->email));
2 daniel-mar 55
        }
56
 
115 daniel-mar 57
        public function change_email($new_email) {
261 daniel-mar 58
                OIDplus::db()->query("update ###ra set email = ? where email = ?", array($new_email, $this->email));
44 daniel-mar 59
        }
60
 
115 daniel-mar 61
        public function register_ra($new_password) {
430 daniel-mar 62
                if (is_null($new_password)) {
63
                        // Invalid password (used for LDAP/OAuth)
64
                        $s_salt = '';
65
                        $calc_authkey = '';
66
                } else {
67
                        list($s_salt, $calc_authkey) = OIDplus::authUtils()->raGeneratePassword($new_password);
68
                }
69
 
329 daniel-mar 70
                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, "", "", "", "", "", "", "", "", "", ""));
2 daniel-mar 71
        }
72
 
453 daniel-mar 73
        public function getAuthInfo() {
261 daniel-mar 74
                $ra_res = OIDplus::db()->query("select authkey, salt from ###ra where email = ?", array($this->email));
251 daniel-mar 75
                if ($ra_res->num_rows() == 0) return false; // User not found
236 daniel-mar 76
                $ra_row = $ra_res->fetch_array();
2 daniel-mar 77
 
453 daniel-mar 78
                return array($ra_row['salt'], $ra_row['authkey']);
79
        }
2 daniel-mar 80
 
453 daniel-mar 81
        public function checkPassword($password) {
82
                return OIDplus::authUtils()->raCheckPassword($this->email, $password);
2 daniel-mar 83
        }
84
 
115 daniel-mar 85
        public function delete() {
261 daniel-mar 86
                OIDplus::db()->query("delete from ###ra where email = ?", array($this->email));
2 daniel-mar 87
        }
88
 
115 daniel-mar 89
        public function setRaName($ra_name) {
261 daniel-mar 90
                OIDplus::db()->query("update ###ra set ra_name = ? where email = ?", array($ra_name, $this->email));
2 daniel-mar 91
        }
433 daniel-mar 92
 
93
        public function isPasswordLess() {
453 daniel-mar 94
                $salt = null;
95
                $authkey = null;
96
                list($salt, $authkey) = $this->getAuthInfo();
97
                return $authkey === '';
433 daniel-mar 98
        }
99
}