Subversion Repositories oidplus

Rev

Rev 257 | 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
5
 * Copyright 2019 Daniel Marschall, ViaThinkSoft
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
 
20
if (!defined('IN_OIDPLUS')) die();
21
 
256 daniel-mar 22
class OIDplusPageAdminCreateRa extends OIDplusPagePluginAdmin {
23
 
222 daniel-mar 24
        public static function getPluginInformation() {
25
                $out = array();
26
                $out['name'] = 'Create RA';
27
                $out['author'] = 'ViaThinkSoft';
28
                $out['version'] = null;
29
                $out['descriptionHTML'] = null;
30
                return $out;
31
        }
32
 
153 daniel-mar 33
        public function priority() {
34
                return 130;
35
        }
36
 
37
        public function action(&$handled) {
38
                if (isset($_POST["action"]) && ($_POST["action"] == "create_ra")) {
39
                        $handled = true;
40
 
41
                        if (!OIDplus::authUtils()::isAdminLoggedIn()) {
42
                                $out['icon'] = 'img/error_big.png';
250 daniel-mar 43
                                $out['text'] = '<p>You need to <a '.OIDplus::gui()->link('oidplus:login').'>log in</a> as administrator.</p>';
153 daniel-mar 44
                                return $out;
45
                        }
46
 
47
                        $email = $_POST['email'];
48
                        $password1 = $_POST['password1'];
49
                        $password2 = $_POST['password2'];
50
 
250 daniel-mar 51
                        if (!OIDplus::mailUtils()->validMailAddress($email)) {
52
                                throw new OIDplusException('eMail address is invalid.');
153 daniel-mar 53
                        }
54
 
261 daniel-mar 55
                        $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 56
                        if ($res->num_rows() > 0) {
250 daniel-mar 57
                                throw new OIDplusException('RA does already exist');
153 daniel-mar 58
                        }
59
 
60
                        if ($password1 !== $password2) {
250 daniel-mar 61
                                throw new OIDplusException('Passwords are not equal');
153 daniel-mar 62
                        }
63
 
257 daniel-mar 64
                        if (strlen($password1) < OIDplus::config()->getValue('ra_min_password_length')) {
65
                                throw new OIDplusException('Password is too short. Minimum password length: '.OIDplus::config()->getValue('ra_min_password_length'));
153 daniel-mar 66
                        }
67
 
68
                        OIDplus::logger()->log("RA($email)!/A?", "RA '$email' was created by the admin, without email address verification or invitation");
69
 
70
                        $ra = new OIDplusRA($email);
71
                        $ra->register_ra($password1);
72
 
73
                        echo json_encode(array("status" => 0));
74
                }
75
        }
76
 
77
        public function init($html=true) {
78
                // Nothing
79
        }
80
 
81
        public function cfgSetValue($name, $value) {
82
                // Nothing
83
        }
84
 
85
        public function gui($id, &$out, &$handled) {
86
                if ($id == 'oidplus:create_ra') {
87
                        $handled = true;
88
                        $out['title'] = 'Manual creation of a RA';
241 daniel-mar 89
                        $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? OIDplus::webpath(__DIR__).'icon_big.png' : '';
153 daniel-mar 90
 
91
                        if (!OIDplus::authUtils()::isAdminLoggedIn()) {
92
                                $out['icon'] = 'img/error_big.png';
250 daniel-mar 93
                                $out['text'] = '<p>You need to <a '.OIDplus::gui()->link('oidplus:login').'>log in</a> as administrator.</p>';
153 daniel-mar 94
                                return $out;
95
                        }
224 daniel-mar 96
 
153 daniel-mar 97
                        $out['text'] .= '<form id="adminCreateRaFrom" onsubmit="return adminCreateRaFormOnSubmit();">';
98
                        $out['text'] .= '<div><label class="padding_label">E-Mail:</label><input type="text" id="email" value=""></div>';
99
                        $out['text'] .= '<div><label class="padding_label">Password:</label><input type="password" id="password1" value=""/></div>';
100
                        $out['text'] .= '<div><label class="padding_label">Repeat:</label><input type="password" id="password2" value=""/></div>';
101
                        $out['text'] .= '<br><input type="submit" value="Create"></form>';
102
                }
103
        }
104
 
105
        public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
106
                if (file_exists(__DIR__.'/treeicon.png')) {
241 daniel-mar 107
                        $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png';
153 daniel-mar 108
                } else {
109
                        $tree_icon = null; // default icon (folder)
110
                }
111
 
112
                $json[] = array(
113
                        'id' => 'oidplus:create_ra',
114
                        'icon' => $tree_icon,
115
                        'text' => 'Create RA manually'
116
                );
117
 
118
                return true;
119
        }
120
 
121
        public function tree_search($request) {
122
                return false;
123
        }
124
}