Subversion Repositories oidplus

Rev

Rev 1050 | Rev 1116 | 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
 
1086 daniel-mar 22
// phpcs:disable PSR1.Files.SideEffects
23
\defined('INSIDE_OIDPLUS') or die;
24
// phpcs:enable PSR1.Files.SideEffects
25
 
635 daniel-mar 26
class OIDplusPageAdminCreateRa extends OIDplusPagePluginAdmin {
27
 
28
        public function action($actionID, $params) {
29
                if ($actionID == 'create_ra') {
30
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
31
                                throw new OIDplusException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')));
32
                        }
33
 
34
                        _CheckParamExists($params, 'email');
35
                        _CheckParamExists($params, 'password1');
36
                        _CheckParamExists($params, 'password2');
37
 
38
                        $email = $params['email'];
39
                        $password1 = $params['password1'];
40
                        $password2 = $params['password2'];
41
 
42
                        if (!OIDplus::mailUtils()->validMailAddress($email)) {
43
                                throw new OIDplusException(_L('eMail address is invalid.'));
44
                        }
45
 
46
                        $res = OIDplus::db()->query("select * from ###ra where email = ?", array($email)); // TODO: this should be a static function in the RA class
790 daniel-mar 47
                        if ($res->any()) {
635 daniel-mar 48
                                throw new OIDplusException(_L('RA does already exist'));
49
                        }
50
 
51
                        if ($password1 !== $password2) {
52
                                throw new OIDplusException(_L('Passwords do not match'));
53
                        }
54
 
55
                        if (strlen($password1) < OIDplus::config()->getValue('ra_min_password_length')) {
56
                                $minlen = OIDplus::config()->getValue('ra_min_password_length');
57
                                throw new OIDplusException(_L('Password is too short. Need at least %1 characters',$minlen));
58
                        }
59
 
60
                        OIDplus::logger()->log("[INFO]RA($email)!/A?", "RA '$email' was created by the admin, without email address verification or invitation");
61
 
62
                        $ra = new OIDplusRA($email);
63
                        $ra->register_ra($password1);
64
 
65
                        return array("status" => 0);
66
                } else {
67
                        throw new OIDplusException(_L('Unknown action ID'));
68
                }
69
        }
70
 
71
        public function init($html=true) {
72
                // Nothing
73
        }
74
 
75
        public function gui($id, &$out, &$handled) {
676 daniel-mar 76
                $parts = explode('$',$id);
77
                $id = $parts[0];
78
 
635 daniel-mar 79
                if ($id == 'oidplus:create_ra') {
80
                        $handled = true;
676 daniel-mar 81
                        $email = isset($parts[1]) ? $parts[1] : '';
635 daniel-mar 82
                        $out['title'] = _L('Manual creation of a RA');
801 daniel-mar 83
                        $out['icon'] = file_exists(__DIR__.'/img/main_icon.png') ? OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png' : '';
635 daniel-mar 84
 
85
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
800 daniel-mar 86
                                $out['icon'] = 'img/error.png';
635 daniel-mar 87
                                $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')).'</p>';
88
                                return;
89
                        }
90
 
91
                        $out['text'] .= '<form id="adminCreateRaFrom" action="javascript:void(0);" onsubmit="return OIDplusPageAdminCreateRa.adminCreateRaFormOnSubmit();">';
676 daniel-mar 92
                        $out['text'] .= '<div><label class="padding_label">'._L('E-Mail').':</label><input type="text" id="email" value="'.htmlentities($email).'"></div>';
635 daniel-mar 93
                        $out['text'] .= '<div><label class="padding_label">'._L('Password').':</label><input type="password" id="password1" value=""/></div>';
94
                        $out['text'] .= '<div><label class="padding_label">'._L('Repeat').':</label><input type="password" id="password2" value=""/></div>';
95
                        $out['text'] .= '<br><input type="submit" value="'._L('Create').'"></form>';
96
                }
97
        }
98
 
99
        public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
100
                if (!OIDplus::authUtils()->isAdminLoggedIn()) return false;
101
 
800 daniel-mar 102
                if (file_exists(__DIR__.'/img/main_icon16.png')) {
801 daniel-mar 103
                        $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png';
635 daniel-mar 104
                } else {
105
                        $tree_icon = null; // default icon (folder)
106
                }
107
 
108
                $json[] = array(
109
                        'id' => 'oidplus:create_ra',
110
                        'icon' => $tree_icon,
111
                        'text' => _L('Create RA manually')
112
                );
113
 
114
                return true;
115
        }
116
 
117
        public function tree_search($request) {
118
                return false;
119
        }
120
}