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