authreq.html 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. }
  64. ao_module_newfw({
  65. url: "SystemAO/security/authreq.html#" + encodeURIComponent(JSON.stringify(apiObject)),
  66. width: 480,
  67. height: 300,
  68. appicon: "SystemAO/security/img/lock.svg",
  69. title: "Authentication Required",
  70. parent: ao_module_windowID,
  71. callback: "handleAuthCallback"
  72. });
  73. */
  74. ao_module_setFixedWindowSize();
  75. ao_module_setWindowSize(420, 260);
  76. var actionObject = {};
  77. var method = "GET";
  78. if (window.location.hash.length > 1){
  79. var object = JSON.parse(decodeURIComponent(window.location.hash.substr(1)));
  80. console.log(object);
  81. if (typeof(object.title) != "undefined"){
  82. $("#title").html(object.title);
  83. }
  84. if (typeof(object.desc) != "undefined"){
  85. $("#desc").html(object.desc);
  86. }
  87. if (typeof(object.thisuser) != "undefined" && object.thisuser == true){
  88. //Load user info from server side
  89. $.get("../../system/desktop/user", function(data){
  90. $("#username").val(data.Username);
  91. $("#username").attr("readonly","true");
  92. $("#username").parent().addClass("disabled");
  93. });
  94. }
  95. if (typeof(object.method) != "undefined" && object.method != ""){
  96. method = object.method;
  97. }
  98. actionObject = object;
  99. }else{
  100. //Invalid usage
  101. }
  102. function confirm(){
  103. $("password").parent().removeClass("error");
  104. var payload = actionObject.data;
  105. //Append custom payload to the original payload
  106. payload.username = $("#username").val();
  107. payload.password = $("#password").val();
  108. //Request endpoint
  109. $.ajax({
  110. url: "../../" + actionObject.api,
  111. data: payload,
  112. method: method,
  113. success: function(data){
  114. if (data.error != undefined){
  115. $("#password").parent().addClass("error");
  116. if ($("#username").parent().hasClass("disabled") == false){
  117. $("#username").parent().addClass("error");
  118. }
  119. }else{
  120. if (ao_module_hasParentCallback()){
  121. ao_module_parentCallback(data);
  122. }
  123. ao_module_close();
  124. }
  125. }
  126. })
  127. }
  128. function cancel(){
  129. if (ao_module_hasParentCallback()){
  130. ao_module_parentCallback(false);
  131. }
  132. ao_module_close();
  133. }
  134. </script>
  135. </body>
  136. </html>