Subversion Repositories oidplus

Rev

Rev 1267 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1267 Rev 1293
Line 24... Line 24...
24
// phpcs:enable PSR1.Files.SideEffects
24
// phpcs:enable PSR1.Files.SideEffects
25
 
25
 
26
class OIDplusPageRaChangePassword extends OIDplusPagePluginRa {
26
class OIDplusPageRaChangePassword extends OIDplusPagePluginRa {
27
 
27
 
28
        /**
28
        /**
29
         * @param string $actionID
-
 
30
         * @param array $params
29
         * @param array $params
31
         * @return array
30
         * @return array
32
         * @throws OIDplusException
31
         * @throws OIDplusException
33
         */
32
         */
34
        public function action(string $actionID, array $params): array {
33
        private function action_Update(array $params): array {
35
                if ($actionID == 'change_ra_password') {
-
 
36
                        _CheckParamExists($params, 'email');
34
                _CheckParamExists($params, 'email');
37
 
35
 
38
                        $email = $params['email'];
36
                $email = $params['email'];
39
 
37
 
40
                        $res = OIDplus::db()->query("select * from ###ra where email = ?", array($email));
38
                $res = OIDplus::db()->query("select * from ###ra where email = ?", array($email));
41
                        if (!$res->any()) {
39
                if (!$res->any()) {
42
                                throw new OIDplusException(_L('RA does not exist'));
40
                        throw new OIDplusException(_L('RA does not exist'));
43
                        }
41
                }
44
 
42
 
45
                        if (!OIDplus::authUtils()->isRaLoggedIn($email) && !OIDplus::authUtils()->isAdminLoggedIn()) {
43
                if (!OIDplus::authUtils()->isRaLoggedIn($email) && !OIDplus::authUtils()->isAdminLoggedIn()) {
46
                                throw new OIDplusException(_L('Authentication error. Please log in as admin, or as the RA to update its data.'), null, 401);
44
                        throw new OIDplusException(_L('Authentication error. Please log in as admin, or as the RA to update its data.'), null, 401);
47
                        }
45
                }
48
 
46
 
49
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
47
                if (!OIDplus::authUtils()->isAdminLoggedIn()) {
50
                                _CheckParamExists($params, 'old_password');
48
                        _CheckParamExists($params, 'old_password');
51
                                $old_password = $params['old_password'];
49
                        $old_password = $params['old_password'];
52
                        } else {
50
                } else {
53
                                $old_password = '';
51
                        $old_password = '';
54
                        }
52
                }
55
 
53
 
56
                        _CheckParamExists($params, 'new_password1');
54
                _CheckParamExists($params, 'new_password1');
57
                        _CheckParamExists($params, 'new_password2');
55
                _CheckParamExists($params, 'new_password2');
58
 
56
 
59
                        $password1 = $params['new_password1'];
57
                $password1 = $params['new_password1'];
60
                        $password2 = $params['new_password2'];
58
                $password2 = $params['new_password2'];
61
 
59
 
62
                        if ($password1 !== $password2) {
60
                if ($password1 !== $password2) {
63
                                throw new OIDplusException(_L('Passwords do not match'));
61
                        throw new OIDplusException(_L('Passwords do not match'));
64
                        }
62
                }
65
 
63
 
66
                        if (strlen($password1) < OIDplus::config()->getValue('ra_min_password_length')) {
64
                if (strlen($password1) < OIDplus::config()->getValue('ra_min_password_length')) {
67
                                $minlen = OIDplus::config()->getValue('ra_min_password_length');
65
                        $minlen = OIDplus::config()->getValue('ra_min_password_length');
68
                                throw new OIDplusException(_L('New password is too short. Minimum password length: %1',$minlen));
66
                        throw new OIDplusException(_L('New password is too short. Minimum password length: %1',$minlen));
69
                        }
67
                }
70
 
68
 
71
                        $ra = new OIDplusRA($email);
69
                $ra = new OIDplusRA($email);
72
                        if (!$ra->isPasswordLess()) {
70
                if (!$ra->isPasswordLess()) {
73
                                if (!OIDplus::authUtils()->isAdminLoggedIn()) {
71
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
74
                                        if (!$ra->checkPassword($old_password)) {
72
                                if (!$ra->checkPassword($old_password)) {
75
                                                throw new OIDplusException(_L('Old password incorrect'));
73
                                        throw new OIDplusException(_L('Old password incorrect'));
76
                                        }
-
 
77
                                }
74
                                }
78
                                OIDplus::logger()->log("V2:[OK/WARN]RA(%1)+[OK/INFO]A", "Password of RA '%1' changed", $email);
-
 
79
                        } else {
-
 
80
                                OIDplus::logger()->log("V2:[OK/WARN]RA(%1)+[OK/INFO]A", "Password of RA '%1' created", $email);
-
 
81
                        }
75
                        }
-
 
76
                        OIDplus::logger()->log("V2:[OK/WARN]RA(%1)+[OK/INFO]A", "Password of RA '%1' changed", $email);
-
 
77
                } else {
-
 
78
                        OIDplus::logger()->log("V2:[OK/WARN]RA(%1)+[OK/INFO]A", "Password of RA '%1' created", $email);
-
 
79
                }
82
                        $ra->change_password($password1);
80
                $ra->change_password($password1);
83
 
81
 
84
                        return array("status" => 0);
82
                return array("status" => 0);
-
 
83
        }
-
 
84
 
-
 
85
        /**
-
 
86
         * @param string $actionID
-
 
87
         * @param array $params
-
 
88
         * @return array
-
 
89
         * @throws OIDplusException
-
 
90
         */
-
 
91
        public function action(string $actionID, array $params): array {
-
 
92
                if ($actionID == 'change_ra_password') {
-
 
93
                        return $this->action_Update($params);
85
                } else {
94
                } else {
86
                        return parent::action($actionID, $params);
95
                        return parent::action($actionID, $params);
87
                }
96
                }
88
        }
97
        }
89
 
98