Subversion Repositories oidplus

Rev

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

Rev 1278 Rev 1293
Line 23... Line 23...
23
\defined('INSIDE_OIDPLUS') or die;
23
\defined('INSIDE_OIDPLUS') or die;
24
// phpcs:enable PSR1.Files.SideEffects
24
// phpcs:enable PSR1.Files.SideEffects
25
 
25
 
26
class OIDplusPageAdminCreateRa extends OIDplusPagePluginAdmin {
26
class OIDplusPageAdminCreateRa extends OIDplusPagePluginAdmin {
27
 
27
 
-
 
28
 
28
        /**
29
        /**
29
         * @param string $actionID
-
 
30
         * @param array $params
30
         * @param array $params
31
         * @return array
31
         * @return array
32
         * @throws OIDplusException
32
         * @throws OIDplusException
33
         */
33
         */
34
        public function action(string $actionID, array $params): array {
34
        private function action_Create(array $params): array {
35
                if ($actionID == 'create_ra') {
-
 
36
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
35
                if (!OIDplus::authUtils()->isAdminLoggedIn()) {
37
                                throw new OIDplusHtmlException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')), null, 401);
36
                        throw new OIDplusHtmlException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')), null, 401);
38
                        }
37
                }
39
 
38
 
40
                        _CheckParamExists($params, 'email');
39
                _CheckParamExists($params, 'email');
41
                        _CheckParamExists($params, 'password1');
40
                _CheckParamExists($params, 'password1');
42
                        _CheckParamExists($params, 'password2');
41
                _CheckParamExists($params, 'password2');
43
 
42
 
44
                        $email = $params['email'];
43
                $email = $params['email'];
45
                        $password1 = $params['password1'];
44
                $password1 = $params['password1'];
46
                        $password2 = $params['password2'];
45
                $password2 = $params['password2'];
47
 
46
 
48
                        if (!OIDplus::mailUtils()->validMailAddress($email)) {
47
                if (!OIDplus::mailUtils()->validMailAddress($email)) {
49
                                throw new OIDplusException(_L('eMail address is invalid.'));
48
                        throw new OIDplusException(_L('eMail address is invalid.'));
50
                        }
49
                }
51
 
50
 
52
                        $res = OIDplus::db()->query("select * from ###ra where email = ?", array($email)); // TODO: this should be a static function in the RA class
51
                $res = OIDplus::db()->query("select * from ###ra where email = ?", array($email)); // TODO: this should be a static function in the RA class
53
                        if ($res->any()) {
52
                if ($res->any()) {
54
                                throw new OIDplusException(_L('RA does already exist'));
53
                        throw new OIDplusException(_L('RA does already exist'));
55
                        }
54
                }
56
 
55
 
57
                        if ($password1 !== $password2) {
56
                if ($password1 !== $password2) {
58
                                throw new OIDplusException(_L('Passwords do not match'));
57
                        throw new OIDplusException(_L('Passwords do not match'));
59
                        }
-
 
60
 
-
 
61
                        if (strlen($password1) < OIDplus::config()->getValue('ra_min_password_length')) {
-
 
62
                                $minlen = OIDplus::config()->getValue('ra_min_password_length');
-
 
63
                                throw new OIDplusException(_L('Password is too short. Need at least %1 characters',$minlen));
-
 
64
                        }
58
                }
65
 
59
 
-
 
60
                if (strlen($password1) < OIDplus::config()->getValue('ra_min_password_length')) {
-
 
61
                        $minlen = OIDplus::config()->getValue('ra_min_password_length');
-
 
62
                        throw new OIDplusException(_L('Password is too short. Need at least %1 characters',$minlen));
-
 
63
                }
-
 
64
 
66
                        OIDplus::logger()->log("V2:[INFO]RA(%1)+[OK/INFO]A", "RA '%1' was created by the admin, without email address verification or invitation", $email);
65
                OIDplus::logger()->log("V2:[INFO]RA(%1)+[OK/INFO]A", "RA '%1' was created by the admin, without email address verification or invitation", $email);
-
 
66
 
-
 
67
                $ra = new OIDplusRA($email);
-
 
68
                $ra->register_ra($password1);
67
 
69
 
68
                        $ra = new OIDplusRA($email);
-
 
69
                        $ra->register_ra($password1);
70
                return array("status" => 0);
-
 
71
        }
70
 
72
 
-
 
73
        /**
-
 
74
         * @param string $actionID
-
 
75
         * @param array $params
-
 
76
         * @return array
-
 
77
         * @throws OIDplusException
-
 
78
         */
-
 
79
        public function action(string $actionID, array $params): array {
-
 
80
                if ($actionID == 'create_ra') {
71
                        return array("status" => 0);
81
                        return $this->action_Create($params);
72
                } else {
82
                } else {
73
                        return parent::action($actionID, $params);
83
                        return parent::action($actionID, $params);
74
                }
84
                }
75
        }
85
        }
76
 
86