Subversion Repositories oidplus

Rev

Rev 328 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

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