Subversion Repositories oidplus

Rev

Rev 428 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
153 daniel-mar 1
<?php
2
 
3
/*
4
 * OIDplus 2.0
511 daniel-mar 5
 * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft
153 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
 
511 daniel-mar 20
if (!defined('INSIDE_OIDPLUS')) die();
21
 
256 daniel-mar 22
class OIDplusPageAdminCreateRa extends OIDplusPagePluginAdmin {
23
 
321 daniel-mar 24
        public function action($actionID, $params) {
25
                if ($actionID == 'create_ra') {
153 daniel-mar 26
                        if (!OIDplus::authUtils()::isAdminLoggedIn()) {
360 daniel-mar 27
                                throw new OIDplusException(_L('You need to log in as administrator.'));
153 daniel-mar 28
                        }
29
 
321 daniel-mar 30
                        $email = $params['email'];
31
                        $password1 = $params['password1'];
32
                        $password2 = $params['password2'];
153 daniel-mar 33
 
250 daniel-mar 34
                        if (!OIDplus::mailUtils()->validMailAddress($email)) {
360 daniel-mar 35
                                throw new OIDplusException(_L('eMail address is invalid.'));
153 daniel-mar 36
                        }
37
 
261 daniel-mar 38
                        $res = OIDplus::db()->query("select * from ###ra where email = ?", array($email)); // TODO: this should be a static function in the RA class
236 daniel-mar 39
                        if ($res->num_rows() > 0) {
360 daniel-mar 40
                                throw new OIDplusException(_L('RA does already exist'));
153 daniel-mar 41
                        }
42
 
43
                        if ($password1 !== $password2) {
360 daniel-mar 44
                                throw new OIDplusException(_L('Passwords do not match'));
153 daniel-mar 45
                        }
46
 
257 daniel-mar 47
                        if (strlen($password1) < OIDplus::config()->getValue('ra_min_password_length')) {
360 daniel-mar 48
                                $minlen = OIDplus::config()->getValue('ra_min_password_length');
49
                                throw new OIDplusException(_L('Password is too short. Need at least %1 characters',$minlen));
153 daniel-mar 50
                        }
51
 
288 daniel-mar 52
                        OIDplus::logger()->log("[INFO]RA($email)!/A?", "RA '$email' was created by the admin, without email address verification or invitation");
153 daniel-mar 53
 
54
                        $ra = new OIDplusRA($email);
55
                        $ra->register_ra($password1);
56
 
328 daniel-mar 57
                        return array("status" => 0);
321 daniel-mar 58
                } else {
360 daniel-mar 59
                        throw new OIDplusException(_L('Unknown action ID'));
153 daniel-mar 60
                }
61
        }
62
 
63
        public function init($html=true) {
64
                // Nothing
65
        }
66
 
67
        public function gui($id, &$out, &$handled) {
68
                if ($id == 'oidplus:create_ra') {
69
                        $handled = true;
360 daniel-mar 70
                        $out['title'] = _L('Manual creation of a RA');
241 daniel-mar 71
                        $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? OIDplus::webpath(__DIR__).'icon_big.png' : '';
153 daniel-mar 72
 
73
                        if (!OIDplus::authUtils()::isAdminLoggedIn()) {
74
                                $out['icon'] = 'img/error_big.png';
360 daniel-mar 75
                                $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login')).'</p>';
281 daniel-mar 76
                                return;
153 daniel-mar 77
                        }
224 daniel-mar 78
 
428 daniel-mar 79
                        $out['text'] .= '<form id="adminCreateRaFrom" action="javascript:void(0);" onsubmit="return adminCreateRaFormOnSubmit();">';
360 daniel-mar 80
                        $out['text'] .= '<div><label class="padding_label">'._L('E-Mail').':</label><input type="text" id="email" value=""></div>';
81
                        $out['text'] .= '<div><label class="padding_label">'._L('Password').':</label><input type="password" id="password1" value=""/></div>';
82
                        $out['text'] .= '<div><label class="padding_label">'._L('Repeat').':</label><input type="password" id="password2" value=""/></div>';
83
                        $out['text'] .= '<br><input type="submit" value="'._L('Create').'"></form>';
153 daniel-mar 84
                }
85
        }
86
 
87
        public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
281 daniel-mar 88
                if (!OIDplus::authUtils()::isAdminLoggedIn()) return false;
360 daniel-mar 89
 
153 daniel-mar 90
                if (file_exists(__DIR__.'/treeicon.png')) {
241 daniel-mar 91
                        $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png';
153 daniel-mar 92
                } else {
93
                        $tree_icon = null; // default icon (folder)
94
                }
95
 
96
                $json[] = array(
97
                        'id' => 'oidplus:create_ra',
98
                        'icon' => $tree_icon,
360 daniel-mar 99
                        'text' => _L('Create RA manually')
153 daniel-mar 100
                );
101
 
102
                return true;
103
        }
104
 
105
        public function tree_search($request) {
106
                return false;
107
        }
360 daniel-mar 108
}