Subversion Repositories oidplus

Rev

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

Rev 1283 Rev 1293
Line 24... Line 24...
24
// phpcs:enable PSR1.Files.SideEffects
24
// phpcs:enable PSR1.Files.SideEffects
25
 
25
 
26
class OIDplusPagePublicForgotPassword extends OIDplusPagePluginPublic {
26
class OIDplusPagePublicForgotPassword extends OIDplusPagePluginPublic {
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
         * @throws OIDplusMailException
32
         * @throws OIDplusMailException
34
         */
33
         */
35
        public function action(string $actionID, array $params): array {
34
        private function action_Request(array $params): array {
36
                if ($actionID == 'forgot_password') {
-
 
37
                        _CheckParamExists($params, 'email');
35
                _CheckParamExists($params, 'email');
38
                        $email = $params['email'];
36
                $email = $params['email'];
39
 
37
 
40
                        if (!OIDplus::mailUtils()->validMailAddress($email)) {
38
                if (!OIDplus::mailUtils()->validMailAddress($email)) {
41
                                throw new OIDplusException(_L('Invalid email address'));
39
                        throw new OIDplusException(_L('Invalid email address'));
42
                        }
40
                }
43
 
41
 
44
                        OIDplus::getActiveCaptchaPlugin()->captchaVerify($params, 'captcha');
42
                OIDplus::getActiveCaptchaPlugin()->captchaVerify($params, 'captcha');
45
 
43
 
46
                        OIDplus::logger()->log("V2:[WARN]RA(%1)", "A new password for '%1' was requested (forgot password)", $email);
44
                OIDplus::logger()->log("V2:[WARN]RA(%1)", "A new password for '%1' was requested (forgot password)", $email);
47
 
45
 
48
                        $activate_url = OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL) . '?goto='.urlencode('oidplus:reset_password$'.$email.'$'.OIDplus::authUtils()->makeAuthKey(['93a16dbe-f4fb-11ed-b67e-3c4a92df8582',$email]));
46
                $activate_url = OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL) . '?goto='.urlencode('oidplus:reset_password$'.$email.'$'.OIDplus::authUtils()->makeAuthKey(['93a16dbe-f4fb-11ed-b67e-3c4a92df8582',$email]));
49
 
47
 
50
                        $message = $this->getForgotPasswordText($params['email']);
48
                $message = $this->getForgotPasswordText($params['email']);
51
                        $message = str_replace('{{ACTIVATE_URL}}', $activate_url, $message);
49
                $message = str_replace('{{ACTIVATE_URL}}', $activate_url, $message);
52
 
50
 
53
                        OIDplus::mailUtils()->sendMail($email, OIDplus::config()->getValue('system_title').' - Password reset request', $message);
51
                OIDplus::mailUtils()->sendMail($email, OIDplus::config()->getValue('system_title').' - Password reset request', $message);
54
 
52
 
55
                        return array("status" => 0);
53
                return array("status" => 0);
-
 
54
        }
56
 
55
 
-
 
56
        /**
-
 
57
         * @param array $params
-
 
58
         * @return array
-
 
59
         * @throws OIDplusException
-
 
60
         * @throws OIDplusMailException
-
 
61
         */
-
 
62
        private function action_Activate(array $params): array {
-
 
63
                _CheckParamExists($params, 'password1');
57
                } else if ($actionID == 'reset_password') {
64
                _CheckParamExists($params, 'password2');
-
 
65
                _CheckParamExists($params, 'email');
-
 
66
                _CheckParamExists($params, 'auth');
-
 
67
 
-
 
68
                $password1 = $params['password1'];
-
 
69
                $password2 = $params['password2'];
-
 
70
                $email = $params['email'];
-
 
71
                $auth = $params['auth'];
58
 
72
 
59
                        _CheckParamExists($params, 'password1');
-
 
60
                        _CheckParamExists($params, 'password2');
-
 
61
                        _CheckParamExists($params, 'email');
-
 
62
                        _CheckParamExists($params, 'auth');
-
 
63
 
-
 
64
                        $password1 = $params['password1'];
-
 
65
                        $password2 = $params['password2'];
-
 
66
                        $email = $params['email'];
-
 
67
                        $auth = $params['auth'];
-
 
68
 
-
 
69
                        if (!OIDplus::authUtils()->validateAuthKey(['93a16dbe-f4fb-11ed-b67e-3c4a92df8582',$email], $auth, OIDplus::config()->getValue('max_ra_pwd_reset_time',-1))) {
73
                if (!OIDplus::authUtils()->validateAuthKey(['93a16dbe-f4fb-11ed-b67e-3c4a92df8582',$email], $auth, OIDplus::config()->getValue('max_ra_pwd_reset_time',-1))) {
70
                                throw new OIDplusException(_L('Invalid or expired authentication key'));
74
                        throw new OIDplusException(_L('Invalid or expired authentication key'));
71
                        }
-
 
72
 
-
 
73
                        if ($password1 !== $password2) {
-
 
74
                                throw new OIDplusException(_L('Passwords do not match'));
-
 
75
                        }
-
 
76
 
-
 
77
                        if (strlen($password1) < OIDplus::config()->getValue('ra_min_password_length')) {
-
 
78
                                $minlen = OIDplus::config()->getValue('ra_min_password_length');
-
 
79
                                throw new OIDplusException(_L('Password is too short. Need at least %1 characters',$minlen));
-
 
80
                        }
75
                }
81
 
76
 
-
 
77
                if ($password1 !== $password2) {
82
                        OIDplus::logger()->log("V2:[INFO]RA(%1)", "RA '%1' has reset his password (forgot passwort)", $email);
78
                        throw new OIDplusException(_L('Passwords do not match'));
-
 
79
                }
83
 
80
 
84
                        $ra = new OIDplusRA($email);
81
                if (strlen($password1) < OIDplus::config()->getValue('ra_min_password_length')) {
85
                        $ra->change_password($password1);
82
                        $minlen = OIDplus::config()->getValue('ra_min_password_length');
-
 
83
                        throw new OIDplusException(_L('Password is too short. Need at least %1 characters',$minlen));
-
 
84
                }
86
 
85
 
-
 
86
                OIDplus::logger()->log("V2:[INFO]RA(%1)", "RA '%1' has reset his password (forgot passwort)", $email);
-
 
87
 
-
 
88
                $ra = new OIDplusRA($email);
-
 
89
                $ra->change_password($password1);
-
 
90
 
87
                        return array("status" => 0);
91
                return array("status" => 0);
-
 
92
        }
-
 
93
 
-
 
94
        /**
-
 
95
         * @param string $actionID
-
 
96
         * @param array $params
-
 
97
         * @return array
-
 
98
         * @throws OIDplusException
-
 
99
         * @throws OIDplusMailException
-
 
100
         */
-
 
101
        public function action(string $actionID, array $params): array {
-
 
102
                if ($actionID == 'forgot_password') {
-
 
103
                        return $this->action_Request($params);
-
 
104
                } else if ($actionID == 'reset_password') {
-
 
105
                        return $this->action_Activate($params);
88
                } else {
106
                } else {
89
                        return parent::action($actionID, $params);
107
                        return parent::action($actionID, $params);
90
                }
108
                }
91
        }
109
        }
92
 
110