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