authreq.html 5.6 KB

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