authreq.html 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title locale="page/title">Authentication Required</title>
  5. <meta charset="UTF-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0 user-scalable=no">
  7. <link rel="stylesheet" href="../../script/semantic/semantic.min.css">
  8. <script type="text/javascript" src="../../script/jquery.min.js"></script>
  9. <script type="text/javascript" src="../../script/semantic/semantic.min.js"></script>
  10. <script type="text/javascript" src="../../script/ao_module.js"></script>
  11. <script type="text/javascript" src="../../script/applocale.js"></script>
  12. <style>
  13. .topSlate{
  14. background-image: url("img/auth_slate.png");
  15. background-repeat: no-repeat;
  16. background-repeat: no-repeat !important;
  17. background-size: 100% auto;
  18. background-attachment: fixed !important;
  19. background-color: #1a1a1a;
  20. height: 70px;
  21. margin-bottom: 4px;
  22. }
  23. .whitefont{
  24. color: white !important;
  25. }
  26. </style>
  27. </head>
  28. <body>
  29. <div class="topSlate">
  30. <div class="ui container">
  31. <h3 class="ui header" style="padding-top: 12px;">
  32. <div class="content whitefont">
  33. <span id="title">Authentication Required</span>
  34. <div id="desc" class="sub header whitefont">in order to proceed this operation</div>
  35. </div>
  36. </h3>
  37. </div>
  38. </div>
  39. <div class="ui container">
  40. <div class="ui left icon small fluid input" style="margin-top: 12px;">
  41. <input id="username" type="text" placeholder="Username">
  42. <i class="user icon"></i>
  43. </div>
  44. <div class="ui left icon fluid input" style="margin-top: 12px;">
  45. <input id="password" type="password" placeholder="Password">
  46. <i class="key icon"></i>
  47. </div>
  48. <br>
  49. <div align="right">
  50. <button class="ui black button" locale="button/confirm" onclick="confirm()">Confirm</button>
  51. <button class="ui button" locale="button/cancel" onclick="cancel()">Cancel</button>
  52. </div>
  53. </div>
  54. <script>
  55. /*
  56. Usage Example:
  57. var apiObject = {
  58. api: "system/myfunction",
  59. data: {message: "Hello World"},
  60. title: "<i class='red exclamation triangle icon'></i> Danger Operation <i class='red exclamation triangle icon'></i>",
  61. desc: "Please enter your password to confirm operation.",
  62. thisuser: true, //This username as default, set to false for allowing other user name to be entered
  63. method: "GET",
  64. success: "systemAO/myfunction/succ.html" //Redirection if success
  65. }
  66. ao_module_newfw({
  67. url: "SystemAO/security/authreq.html#" + encodeURIComponent(JSON.stringify(apiObject)),
  68. width: 480,
  69. height: 300,
  70. appicon: "SystemAO/security/img/lock.svg",
  71. title: "Authentication Required",
  72. parent: ao_module_windowID,
  73. callback: "handleAuthCallback"
  74. });
  75. */
  76. ao_module_setFixedWindowSize();
  77. ao_module_setWindowSize(420, 260);
  78. var actionObject = {};
  79. var method = "GET";
  80. if (window.location.hash.length > 1){
  81. var object = JSON.parse(decodeURIComponent(window.location.hash.substr(1)));
  82. console.log(object);
  83. if (typeof(object.title) != "undefined"){
  84. $("#title").html(object.title);
  85. }
  86. if (typeof(object.desc) != "undefined"){
  87. $("#desc").html(object.desc);
  88. }
  89. if (typeof(object.thisuser) != "undefined" && object.thisuser == true){
  90. //Load user info from server side
  91. $.get("../../system/desktop/user", function(data){
  92. $("#username").val(data.Username);
  93. $("#username").attr("readonly","true");
  94. $("#username").parent().addClass("disabled");
  95. });
  96. }
  97. if (typeof(object.method) != "undefined" && object.method != ""){
  98. method = object.method;
  99. }
  100. actionObject = object;
  101. }else{
  102. //Invalid usage
  103. }
  104. function confirm(){
  105. $("password").parent().removeClass("error");
  106. var payload = actionObject.data;
  107. //Append custom payload to the original payload
  108. payload.username = $("#username").val();
  109. payload.password = $("#password").val();
  110. //Request endpoint
  111. $.ajax({
  112. url: "../../" + actionObject.api,
  113. data: payload,
  114. method: method,
  115. success: function(data){
  116. if (data.error != undefined){
  117. $("#password").parent().addClass("error");
  118. if ($("#username").parent().hasClass("disabled") == false){
  119. $("#username").parent().addClass("error");
  120. }
  121. }else{
  122. if (ao_module_hasParentCallback()){
  123. ao_module_parentCallback(data);
  124. }
  125. if (actionObject.success != undefined){
  126. window.top.location = "../../" + actionObject.success;
  127. }
  128. ao_module_close();
  129. }
  130. }
  131. })
  132. }
  133. function cancel(){
  134. if (ao_module_hasParentCallback()){
  135. ao_module_parentCallback(false);
  136. }
  137. ao_module_close();
  138. }
  139. if (applocale){
  140. //Applocale found. Do localization
  141. applocale.init("../locale/authreq.json", function(){
  142. applocale.translate();
  143. });
  144. }else{
  145. //Applocale not found. Is this a trim down version of ArozOS?
  146. var applocale = {
  147. getString: function(key, original){
  148. return original;
  149. }
  150. }
  151. }
  152. </script>
  153. </body>
  154. </html>