Subversion Repositories oidplus

Rev

Rev 1267 | 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 array $params email
  31.          * @return array
  32.          * @throws OIDplusException
  33.          */
  34.         private function action_Delete(array $params): array {
  35.                 _CheckParamExists($params, 'email');
  36.  
  37.                 $email = $params['email'];
  38.  
  39.                 $ra_logged_in = OIDplus::authUtils()->isRaLoggedIn($email);
  40.  
  41.                 if (!OIDplus::authUtils()->isAdminLoggedIn() && !$ra_logged_in) {
  42.                         throw new OIDplusException(_L('Authentication error. Please log in.'), null, 401);
  43.                 }
  44.  
  45.                 if ($ra_logged_in) OIDplus::authUtils()->raLogout($email);
  46.  
  47.                 $ra = new OIDplusRA($email);
  48.                 if (!$ra->existing()) {
  49.                         throw new OIDplusException(_L('RA "%1" does not exist.',$email));
  50.                 }
  51.                 $ra->delete();
  52.                 $ra = null;
  53.  
  54.                 OIDplus::logger()->log("V2:[OK/WARN]RA(%1)+[OK/INFO]A", "RA '%1' deleted", $email);
  55.  
  56.                 return array("status" => 0);
  57.         }
  58.  
  59.         /**
  60.          * @param string $actionID
  61.          * @param array $params
  62.          * @return array
  63.          * @throws OIDplusException
  64.          */
  65.         public function action(string $actionID, array $params): array {
  66.                 if ($actionID == 'delete_ra') {
  67.                         return $this->action_Delete($params);
  68.                 } else {
  69.                         return parent::action($actionID, $params);
  70.                 }
  71.         }
  72.  
  73.         /**
  74.          * @param bool $html
  75.          * @return void
  76.          * @throws OIDplusException
  77.          */
  78.         public function init(bool $html=true) {
  79.                 // Will be used by: plugins admin-130, public-091, public-200, ra-092, ra-101
  80.                 OIDplus::config()->prepareConfigKey('ra_min_password_length', 'Minimum length for RA passwords', '6', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
  81.                         if (!is_numeric($value) || ($value < 1)) {
  82.                                 throw new OIDplusException(_L('Please enter a valid password length.'));
  83.                         }
  84.                 });
  85.         }
  86.  
  87.         /**
  88.          * @param string $id
  89.          * @param array $out
  90.          * @param bool $handled
  91.          * @return void
  92.          */
  93.         public function gui(string $id, array &$out, bool &$handled) {
  94.         }
  95.  
  96.         /**
  97.          * @param array $out
  98.          * @return void
  99.          */
  100.         public function publicSitemap(array &$out) {
  101.         }
  102.  
  103.         /**
  104.          * @param array $json
  105.          * @param string|null $ra_email
  106.          * @param bool $nonjs
  107.          * @param string $req_goto
  108.          * @return bool
  109.          */
  110.         public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool {
  111.                 return false;
  112.         }
  113.  
  114.         /**
  115.          * @param string $request
  116.          * @return array|false
  117.          */
  118.         public function tree_search(string $request) {
  119.                 return false;
  120.         }
  121. }
  122.