Subversion Repositories oidplus

Rev

Rev 1116 | Rev 1199 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. /*
  4.  * OIDplus 2.0
  5.  * Copyright 2019 - 2023 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. namespace ViaThinkSoft\OIDplus;
  21.  
  22. // TODO: should this be a different plugin type? A page without gui is weird!
  23. // phpcs:disable PSR1.Files.SideEffects
  24. \defined('INSIDE_OIDPLUS') or die;
  25. // phpcs:enable PSR1.Files.SideEffects
  26.  
  27. class OIDplusPagePublicRaBaseUtils extends OIDplusPagePluginPublic {
  28.  
  29.         /**
  30.          * @param string $actionID
  31.          * @param array $params
  32.          * @return array
  33.          * @throws OIDplusException
  34.          */
  35.         public function action(string $actionID, array $params): array {
  36.  
  37.                 // Action:     delete_ra
  38.                 // Method:     POST
  39.                 // Parameters: email
  40.                 // Outputs:    Text
  41.                 if ($actionID == 'delete_ra') {
  42.                         _CheckParamExists($params, 'email');
  43.  
  44.                         $email = $params['email'];
  45.  
  46.                         $ra_logged_in = OIDplus::authUtils()->isRaLoggedIn($email);
  47.  
  48.                         if (!OIDplus::authUtils()->isAdminLoggedIn() && !$ra_logged_in) {
  49.                                 throw new OIDplusException(_L('Authentication error. Please log in.'));
  50.                         }
  51.  
  52.                         if ($ra_logged_in) OIDplus::authUtils()->raLogout($email);
  53.  
  54.                         $ra = new OIDplusRA($email);
  55.                         if (!$ra->existing()) {
  56.                                 throw new OIDplusException(_L('RA "%1" does not exist.',$email));
  57.                         }
  58.                         $ra->delete();
  59.                         $ra = null;
  60.  
  61.                         OIDplus::logger()->log("[?WARN/!OK]RA($email)!/[?INFO/!OK]A?", "RA '$email' deleted");
  62.  
  63.                         return array("status" => 0);
  64.                 } else {
  65.                         return parent::action($actionID, $params);
  66.                 }
  67.  
  68.         }
  69.  
  70.         /**
  71.          * @param bool $html
  72.          * @return void
  73.          * @throws OIDplusException
  74.          */
  75.         public function init(bool $html=true) {
  76.                 // Will be used by: plugins admin-130, public-091, public-200, ra-092, ra-101
  77.                 OIDplus::config()->prepareConfigKey('ra_min_password_length', 'Minimum length for RA passwords', '6', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
  78.                         if (!is_numeric($value) || ($value < 1)) {
  79.                                 throw new OIDplusException(_L('Please enter a valid password length.'));
  80.                         }
  81.                 });
  82.         }
  83.  
  84.         /**
  85.          * @param string $id
  86.          * @param array $out
  87.          * @param bool $handled
  88.          * @return void
  89.          */
  90.         public function gui(string $id, array &$out, bool &$handled) {
  91.         }
  92.  
  93.         /**
  94.          * @param array $out
  95.          * @return void
  96.          */
  97.         public function publicSitemap(array &$out) {
  98.         }
  99.  
  100.         /**
  101.          * @param array $json
  102.          * @param string|null $ra_email
  103.          * @param bool $nonjs
  104.          * @param string $req_goto
  105.          * @return bool
  106.          */
  107.         public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool {
  108.                 return false;
  109.         }
  110.  
  111.         /**
  112.          * @param string $request
  113.          * @return array|false
  114.          */
  115.         public function tree_search(string $request) {
  116.                 return false;
  117.         }
  118. }
  119.