Rev 801 | Rev 1086 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 801 | Rev 1050 | ||
---|---|---|---|
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | /* |
3 | /* |
4 | * OIDplus 2.0 |
4 | * OIDplus 2.0 |
5 | * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft |
5 | * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft |
6 | * |
6 | * |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | * you may not use this file except in compliance with 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 |
9 | * You may obtain a copy of the License at |
10 | * |
10 | * |
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
12 | * |
12 | * |
13 | * Unless required by applicable law or agreed to in writing, software |
13 | * Unless required by applicable law or agreed to in writing, software |
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | * See the License for the specific language governing permissions and |
16 | * See the License for the specific language governing permissions and |
17 | * limitations under the License. |
17 | * limitations under the License. |
18 | */ |
18 | */ |
19 | 19 | ||
20 | if (!defined('INSIDE_OIDPLUS')) die(); |
20 | namespace ViaThinkSoft\OIDplus; |
21 | 21 | ||
22 | class OIDplusPageAdminCreateRa extends OIDplusPagePluginAdmin { |
22 | class OIDplusPageAdminCreateRa extends OIDplusPagePluginAdmin { |
23 | 23 | ||
24 | public function action($actionID, $params) { |
24 | public function action($actionID, $params) { |
25 | if ($actionID == 'create_ra') { |
25 | if ($actionID == 'create_ra') { |
26 | if (!OIDplus::authUtils()->isAdminLoggedIn()) { |
26 | if (!OIDplus::authUtils()->isAdminLoggedIn()) { |
27 | throw new OIDplusException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin'))); |
27 | throw new OIDplusException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin'))); |
28 | } |
28 | } |
29 | 29 | ||
30 | _CheckParamExists($params, 'email'); |
30 | _CheckParamExists($params, 'email'); |
31 | _CheckParamExists($params, 'password1'); |
31 | _CheckParamExists($params, 'password1'); |
32 | _CheckParamExists($params, 'password2'); |
32 | _CheckParamExists($params, 'password2'); |
33 | 33 | ||
34 | $email = $params['email']; |
34 | $email = $params['email']; |
35 | $password1 = $params['password1']; |
35 | $password1 = $params['password1']; |
36 | $password2 = $params['password2']; |
36 | $password2 = $params['password2']; |
37 | 37 | ||
38 | if (!OIDplus::mailUtils()->validMailAddress($email)) { |
38 | if (!OIDplus::mailUtils()->validMailAddress($email)) { |
39 | throw new OIDplusException(_L('eMail address is invalid.')); |
39 | throw new OIDplusException(_L('eMail address is invalid.')); |
40 | } |
40 | } |
41 | 41 | ||
42 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($email)); // TODO: this should be a static function in the RA class |
42 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($email)); // TODO: this should be a static function in the RA class |
43 | if ($res->any()) { |
43 | if ($res->any()) { |
44 | throw new OIDplusException(_L('RA does already exist')); |
44 | throw new OIDplusException(_L('RA does already exist')); |
45 | } |
45 | } |
46 | 46 | ||
47 | if ($password1 !== $password2) { |
47 | if ($password1 !== $password2) { |
48 | throw new OIDplusException(_L('Passwords do not match')); |
48 | throw new OIDplusException(_L('Passwords do not match')); |
49 | } |
49 | } |
50 | 50 | ||
51 | if (strlen($password1) < OIDplus::config()->getValue('ra_min_password_length')) { |
51 | if (strlen($password1) < OIDplus::config()->getValue('ra_min_password_length')) { |
52 | $minlen = OIDplus::config()->getValue('ra_min_password_length'); |
52 | $minlen = OIDplus::config()->getValue('ra_min_password_length'); |
53 | throw new OIDplusException(_L('Password is too short. Need at least %1 characters',$minlen)); |
53 | throw new OIDplusException(_L('Password is too short. Need at least %1 characters',$minlen)); |
54 | } |
54 | } |
55 | 55 | ||
56 | OIDplus::logger()->log("[INFO]RA($email)!/A?", "RA '$email' was created by the admin, without email address verification or invitation"); |
56 | OIDplus::logger()->log("[INFO]RA($email)!/A?", "RA '$email' was created by the admin, without email address verification or invitation"); |
57 | 57 | ||
58 | $ra = new OIDplusRA($email); |
58 | $ra = new OIDplusRA($email); |
59 | $ra->register_ra($password1); |
59 | $ra->register_ra($password1); |
60 | 60 | ||
61 | return array("status" => 0); |
61 | return array("status" => 0); |
62 | } else { |
62 | } else { |
63 | throw new OIDplusException(_L('Unknown action ID')); |
63 | throw new OIDplusException(_L('Unknown action ID')); |
64 | } |
64 | } |
65 | } |
65 | } |
66 | 66 | ||
67 | public function init($html=true) { |
67 | public function init($html=true) { |
68 | // Nothing |
68 | // Nothing |
69 | } |
69 | } |
70 | 70 | ||
71 | public function gui($id, &$out, &$handled) { |
71 | public function gui($id, &$out, &$handled) { |
72 | $parts = explode('$',$id); |
72 | $parts = explode('$',$id); |
73 | $id = $parts[0]; |
73 | $id = $parts[0]; |
74 | 74 | ||
75 | if ($id == 'oidplus:create_ra') { |
75 | if ($id == 'oidplus:create_ra') { |
76 | $handled = true; |
76 | $handled = true; |
77 | $email = isset($parts[1]) ? $parts[1] : ''; |
77 | $email = isset($parts[1]) ? $parts[1] : ''; |
78 | $out['title'] = _L('Manual creation of a RA'); |
78 | $out['title'] = _L('Manual creation of a RA'); |
79 | $out['icon'] = file_exists(__DIR__.'/img/main_icon.png') ? OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png' : ''; |
79 | $out['icon'] = file_exists(__DIR__.'/img/main_icon.png') ? OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png' : ''; |
80 | 80 | ||
81 | if (!OIDplus::authUtils()->isAdminLoggedIn()) { |
81 | if (!OIDplus::authUtils()->isAdminLoggedIn()) { |
82 | $out['icon'] = 'img/error.png'; |
82 | $out['icon'] = 'img/error.png'; |
83 | $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')).'</p>'; |
83 | $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')).'</p>'; |
84 | return; |
84 | return; |
85 | } |
85 | } |
86 | 86 | ||
87 | $out['text'] .= '<form id="adminCreateRaFrom" action="javascript:void(0);" onsubmit="return OIDplusPageAdminCreateRa.adminCreateRaFormOnSubmit();">'; |
87 | $out['text'] .= '<form id="adminCreateRaFrom" action="javascript:void(0);" onsubmit="return OIDplusPageAdminCreateRa.adminCreateRaFormOnSubmit();">'; |
88 | $out['text'] .= '<div><label class="padding_label">'._L('E-Mail').':</label><input type="text" id="email" value="'.htmlentities($email).'"></div>'; |
88 | $out['text'] .= '<div><label class="padding_label">'._L('E-Mail').':</label><input type="text" id="email" value="'.htmlentities($email).'"></div>'; |
89 | $out['text'] .= '<div><label class="padding_label">'._L('Password').':</label><input type="password" id="password1" value=""/></div>'; |
89 | $out['text'] .= '<div><label class="padding_label">'._L('Password').':</label><input type="password" id="password1" value=""/></div>'; |
90 | $out['text'] .= '<div><label class="padding_label">'._L('Repeat').':</label><input type="password" id="password2" value=""/></div>'; |
90 | $out['text'] .= '<div><label class="padding_label">'._L('Repeat').':</label><input type="password" id="password2" value=""/></div>'; |
91 | $out['text'] .= '<br><input type="submit" value="'._L('Create').'"></form>'; |
91 | $out['text'] .= '<br><input type="submit" value="'._L('Create').'"></form>'; |
92 | } |
92 | } |
93 | } |
93 | } |
94 | 94 | ||
95 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
95 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
96 | if (!OIDplus::authUtils()->isAdminLoggedIn()) return false; |
96 | if (!OIDplus::authUtils()->isAdminLoggedIn()) return false; |
97 | 97 | ||
98 | if (file_exists(__DIR__.'/img/main_icon16.png')) { |
98 | if (file_exists(__DIR__.'/img/main_icon16.png')) { |
99 | $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png'; |
99 | $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png'; |
100 | } else { |
100 | } else { |
101 | $tree_icon = null; // default icon (folder) |
101 | $tree_icon = null; // default icon (folder) |
102 | } |
102 | } |
103 | 103 | ||
104 | $json[] = array( |
104 | $json[] = array( |
105 | 'id' => 'oidplus:create_ra', |
105 | 'id' => 'oidplus:create_ra', |
106 | 'icon' => $tree_icon, |
106 | 'icon' => $tree_icon, |
107 | 'text' => _L('Create RA manually') |
107 | 'text' => _L('Create RA manually') |
108 | ); |
108 | ); |
109 | 109 | ||
110 | return true; |
110 | return true; |
111 | } |
111 | } |
112 | 112 | ||
113 | public function tree_search($request) { |
113 | public function tree_search($request) { |
114 | return false; |
114 | return false; |
115 | } |
115 | } |
116 | } |
116 | } |
117 | 117 |