Subversion Repositories oidplus

Rev

Rev 424 | Go to most recent revision | View as "text/javascript" | Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * OIDplus 2.0
  3.  * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17.  
  18. /* RA */
  19.  
  20. function raLogout(email) {
  21.         if(!window.confirm(_L("Are you sure that you want to logout?"))) return false;
  22.  
  23.         $.ajax({
  24.                 url:"ajax.php",
  25.                 method:"POST",
  26.                 data: {
  27.                         csrf_token:csrf_token,
  28.                         plugin:"1.3.6.1.4.1.37476.2.5.2.4.1.90",
  29.                         action:"ra_logout",
  30.                         email:email,
  31.                 },
  32.                 error:function(jqXHR, textStatus, errorThrown) {
  33.                         alert(_L("Error: %1",errorThrown));
  34.                 },
  35.                 success:function(data) {
  36.                         if ("error" in data) {
  37.                                 alert(_L("Error: %1",data.error));
  38.                         } else if (data.status >= 0) {
  39.                                 window.location.href = '?goto=oidplus:system';
  40.                                 // reloadContent();
  41.                         } else {
  42.                                 alert(_L("Error: %1",data));
  43.                         }
  44.                 }
  45.         });
  46. }
  47.  
  48. function raLogin(email, password) {
  49.         $.ajax({
  50.                 url:"ajax.php",
  51.                 method:"POST",
  52.                 data: {
  53.                         csrf_token:csrf_token,
  54.                         plugin:"1.3.6.1.4.1.37476.2.5.2.4.1.90",
  55.                         action:"ra_login",
  56.                         email:email,
  57.                         password:password,
  58.                         captcha: document.getElementsByClassName('g-recaptcha').length > 0 ? grecaptcha.getResponse() : null
  59.                 },
  60.                 error:function(jqXHR, textStatus, errorThrown) {
  61.                         alert(_L("Error: %1",errorThrown));
  62.                         if (document.getElementsByClassName('g-recaptcha').length > 0) grecaptcha.reset();
  63.                 },
  64.                 success:function(data) {
  65.                         if ("error" in data) {
  66.                                 alert(_L("Error: %1",data.error));
  67.                                 if (document.getElementsByClassName('g-recaptcha').length > 0) grecaptcha.reset();
  68.                         } else if (data.status >= 0) {
  69.                                 window.location.href = '?goto=oidplus:system';
  70.                                 // reloadContent();
  71.                         } else {
  72.                                 alert(_L("Error: %1",data));
  73.                                 if (document.getElementsByClassName('g-recaptcha').length > 0) grecaptcha.reset();
  74.                         }
  75.                 }
  76.         });
  77. }
  78.  
  79. function raLoginOnSubmit() {
  80.         raLogin(document.getElementById("raLoginEMail").value, document.getElementById("raLoginPassword").value);
  81.         return false;
  82. }
  83.  
  84. /* Admin */
  85.  
  86. function adminLogin(password) {
  87.         $.ajax({
  88.                 url:"ajax.php",
  89.                 method:"POST",
  90.                 data: {
  91.                         csrf_token:csrf_token,
  92.                         plugin:"1.3.6.1.4.1.37476.2.5.2.4.1.90",
  93.                         action:"admin_login",
  94.                         password:password,
  95.                         captcha: document.getElementsByClassName('g-recaptcha').length > 0 ? grecaptcha.getResponse() : null
  96.                 },
  97.                 error:function(jqXHR, textStatus, errorThrown) {
  98.                         alert(_L("Error: %1",errorThrown));
  99.                         if (document.getElementsByClassName('g-recaptcha').length > 0) grecaptcha.reset();
  100.                 },
  101.                 success:function(data) {
  102.                         if ("error" in data) {
  103.                                 alert(_L("Error: %1",data.error));
  104.                                 if (document.getElementsByClassName('g-recaptcha').length > 0) grecaptcha.reset();
  105.                         } else if (data.status >= 0) {
  106.                                 window.location.href = '?goto=oidplus:system';
  107.                                 // reloadContent();
  108.                         } else {
  109.                                 alert(_L("Error: %1",data));
  110.                                 if (document.getElementsByClassName('g-recaptcha').length > 0) grecaptcha.reset();
  111.                         }
  112.                 }
  113.         });
  114. }
  115.  
  116. function adminLogout() {
  117.         if(!window.confirm(_L("Are you sure that you want to logout?"))) return false;
  118.  
  119.         $.ajax({
  120.                 url:"ajax.php",
  121.                 method:"POST",
  122.                 data: {
  123.                         csrf_token:csrf_token,
  124.                         plugin:"1.3.6.1.4.1.37476.2.5.2.4.1.90",
  125.                         action:"admin_logout",
  126.                 },
  127.                 error:function(jqXHR, textStatus, errorThrown) {
  128.                         alert(_L("Error: %1",errorThrown));
  129.                 },
  130.                 success:function(data) {
  131.                         if ("error" in data) {
  132.                                 alert(_L("Error: %1",data.error));
  133.                         } else if (data.status >= 0) {
  134.                                 window.location.href = '?goto=oidplus:system';
  135.                                 // reloadContent();
  136.                         } else {
  137.                                 alert(_L("Error: %1",data));
  138.                         }
  139.                 }
  140.         });
  141. }
  142.  
  143. function adminLoginOnSubmit() {
  144.         adminLogin(document.getElementById("adminLoginPassword").value);
  145.         return false;
  146. }