Subversion Repositories oidplus

Rev

Rev 1116 | Rev 1199 | Go to most recent revision | 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
        /**
30
         * @param string $actionID
31
         * @param array $params
1143 daniel-mar 32
         * @return array
1116 daniel-mar 33
         * @throws OIDplusException
34
         */
35
        public function action(string $actionID, array $params): array {
635 daniel-mar 36
 
37
                // Action:     delete_ra
38
                // Method:     POST
39
                // Parameters: email
40
                // Outputs:    Text
41
                if ($actionID == 'delete_ra') {
42
                        _CheckParamExists($params, 'email');
43
 
44
                        $email = $params['email'];
45
 
46
                        $ra_logged_in = OIDplus::authUtils()->isRaLoggedIn($email);
47
 
48
                        if (!OIDplus::authUtils()->isAdminLoggedIn() && !$ra_logged_in) {
49
                                throw new OIDplusException(_L('Authentication error. Please log in.'));
50
                        }
51
 
52
                        if ($ra_logged_in) OIDplus::authUtils()->raLogout($email);
53
 
54
                        $ra = new OIDplusRA($email);
55
                        if (!$ra->existing()) {
56
                                throw new OIDplusException(_L('RA "%1" does not exist.',$email));
57
                        }
58
                        $ra->delete();
59
                        $ra = null;
60
 
61
                        OIDplus::logger()->log("[?WARN/!OK]RA($email)!/[?INFO/!OK]A?", "RA '$email' deleted");
62
 
63
                        return array("status" => 0);
64
                } else {
1116 daniel-mar 65
                        return parent::action($actionID, $params);
635 daniel-mar 66
                }
67
 
68
        }
69
 
1116 daniel-mar 70
        /**
71
         * @param bool $html
72
         * @return void
73
         * @throws OIDplusException
74
         */
75
        public function init(bool $html=true) {
635 daniel-mar 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) {
78
                        if (!is_numeric($value) || ($value < 1)) {
79
                                throw new OIDplusException(_L('Please enter a valid password length.'));
80
                        }
81
                });
82
        }
83
 
1116 daniel-mar 84
        /**
85
         * @param string $id
86
         * @param array $out
87
         * @param bool $handled
88
         * @return void
89
         */
90
        public function gui(string $id, array &$out, bool &$handled) {
635 daniel-mar 91
        }
92
 
1116 daniel-mar 93
        /**
94
         * @param array $out
95
         * @return void
96
         */
97
        public function publicSitemap(array &$out) {
635 daniel-mar 98
        }
99
 
1116 daniel-mar 100
        /**
101
         * @param array $json
102
         * @param string|null $ra_email
103
         * @param bool $nonjs
104
         * @param string $req_goto
105
         * @return bool
106
         */
107
        public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool {
108
                return false;
635 daniel-mar 109
        }
110
 
1116 daniel-mar 111
        /**
112
         * @param string $request
113
         * @return array|false
114
         */
115
        public function tree_search(string $request) {
635 daniel-mar 116
                return false;
117
        }
1116 daniel-mar 118
}