Subversion Repositories oidplus

Rev

Rev 1266 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1266 Rev 1267
1
<?php
1
<?php
2
 
2
 
3
/*
3
/*
4
 * OIDplus 2.0
4
 * OIDplus 2.0
5
 * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft
5
 * Copyright 2019 - 2023 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
namespace ViaThinkSoft\OIDplus;
20
namespace ViaThinkSoft\OIDplus;
21
 
21
 
22
// TODO: should this be a different plugin type? A page without gui is weird!
22
// TODO: should this be a different plugin type? A page without gui is weird!
23
// phpcs:disable PSR1.Files.SideEffects
23
// phpcs:disable PSR1.Files.SideEffects
24
\defined('INSIDE_OIDPLUS') or die;
24
\defined('INSIDE_OIDPLUS') or die;
25
// phpcs:enable PSR1.Files.SideEffects
25
// phpcs:enable PSR1.Files.SideEffects
26
 
26
 
27
class OIDplusPagePublicRaBaseUtils extends OIDplusPagePluginPublic {
27
class OIDplusPagePublicRaBaseUtils extends OIDplusPagePluginPublic {
28
 
28
 
29
        /**
29
        /**
30
         * @param string $actionID
30
         * @param string $actionID
31
         * @param array $params
31
         * @param array $params
32
         * @return array
32
         * @return array
33
         * @throws OIDplusException
33
         * @throws OIDplusException
34
         */
34
         */
35
        public function action(string $actionID, array $params): array {
35
        public function action(string $actionID, array $params): array {
36
 
36
 
37
                // Action:     delete_ra
37
                // Action:     delete_ra
38
                // Method:     POST
38
                // Method:     POST
39
                // Parameters: email
39
                // Parameters: email
40
                // Outputs:    Text
40
                // Outputs:    Text
41
                if ($actionID == 'delete_ra') {
41
                if ($actionID == 'delete_ra') {
42
                        _CheckParamExists($params, 'email');
42
                        _CheckParamExists($params, 'email');
43
 
43
 
44
                        $email = $params['email'];
44
                        $email = $params['email'];
45
 
45
 
46
                        $ra_logged_in = OIDplus::authUtils()->isRaLoggedIn($email);
46
                        $ra_logged_in = OIDplus::authUtils()->isRaLoggedIn($email);
47
 
47
 
48
                        if (!OIDplus::authUtils()->isAdminLoggedIn() && !$ra_logged_in) {
48
                        if (!OIDplus::authUtils()->isAdminLoggedIn() && !$ra_logged_in) {
49
                                throw new OIDplusException(_L('Authentication error. Please log in.'), null, 401);
49
                                throw new OIDplusException(_L('Authentication error. Please log in.'), null, 401);
50
                        }
50
                        }
51
 
51
 
52
                        if ($ra_logged_in) OIDplus::authUtils()->raLogout($email);
52
                        if ($ra_logged_in) OIDplus::authUtils()->raLogout($email);
53
 
53
 
54
                        $ra = new OIDplusRA($email);
54
                        $ra = new OIDplusRA($email);
55
                        if (!$ra->existing()) {
55
                        if (!$ra->existing()) {
56
                                throw new OIDplusException(_L('RA "%1" does not exist.',$email));
56
                                throw new OIDplusException(_L('RA "%1" does not exist.',$email));
57
                        }
57
                        }
58
                        $ra->delete();
58
                        $ra->delete();
59
                        $ra = null;
59
                        $ra = null;
60
 
60
 
61
                        OIDplus::logger()->log("[?WARN/!OK]RA(%1)!/[?INFO/!OK]A?", "RA '%1' deleted", $email);
61
                        OIDplus::logger()->log("V2:[OK/WARN]RA(%1)+[OK/INFO]A", "RA '%1' deleted", $email);
62
 
62
 
63
                        return array("status" => 0);
63
                        return array("status" => 0);
64
                } else {
64
                } else {
65
                        return parent::action($actionID, $params);
65
                        return parent::action($actionID, $params);
66
                }
66
                }
67
 
67
 
68
        }
68
        }
69
 
69
 
70
        /**
70
        /**
71
         * @param bool $html
71
         * @param bool $html
72
         * @return void
72
         * @return void
73
         * @throws OIDplusException
73
         * @throws OIDplusException
74
         */
74
         */
75
        public function init(bool $html=true) {
75
        public function init(bool $html=true) {
76
                // Will be used by: plugins admin-130, public-091, public-200, ra-092, ra-101
76
                // Will be used by: plugins admin-130, public-091, public-200, ra-092, ra-101
77
                OIDplus::config()->prepareConfigKey('ra_min_password_length', 'Minimum length for RA passwords', '6', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
77
                OIDplus::config()->prepareConfigKey('ra_min_password_length', 'Minimum length for RA passwords', '6', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
78
                        if (!is_numeric($value) || ($value < 1)) {
78
                        if (!is_numeric($value) || ($value < 1)) {
79
                                throw new OIDplusException(_L('Please enter a valid password length.'));
79
                                throw new OIDplusException(_L('Please enter a valid password length.'));
80
                        }
80
                        }
81
                });
81
                });
82
        }
82
        }
83
 
83
 
84
        /**
84
        /**
85
         * @param string $id
85
         * @param string $id
86
         * @param array $out
86
         * @param array $out
87
         * @param bool $handled
87
         * @param bool $handled
88
         * @return void
88
         * @return void
89
         */
89
         */
90
        public function gui(string $id, array &$out, bool &$handled) {
90
        public function gui(string $id, array &$out, bool &$handled) {
91
        }
91
        }
92
 
92
 
93
        /**
93
        /**
94
         * @param array $out
94
         * @param array $out
95
         * @return void
95
         * @return void
96
         */
96
         */
97
        public function publicSitemap(array &$out) {
97
        public function publicSitemap(array &$out) {
98
        }
98
        }
99
 
99
 
100
        /**
100
        /**
101
         * @param array $json
101
         * @param array $json
102
         * @param string|null $ra_email
102
         * @param string|null $ra_email
103
         * @param bool $nonjs
103
         * @param bool $nonjs
104
         * @param string $req_goto
104
         * @param string $req_goto
105
         * @return bool
105
         * @return bool
106
         */
106
         */
107
        public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool {
107
        public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool {
108
                return false;
108
                return false;
109
        }
109
        }
110
 
110
 
111
        /**
111
        /**
112
         * @param string $request
112
         * @param string $request
113
         * @return array|false
113
         * @return array|false
114
         */
114
         */
115
        public function tree_search(string $request) {
115
        public function tree_search(string $request) {
116
                return false;
116
                return false;
117
        }
117
        }
118
}
118
}
119
 
119