user.system 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  6. <title>ArozOS - Users</title>
  7. <link rel="stylesheet" href="script/tocas/tocas.css">
  8. <link rel="stylesheet" href="script/ao.css">
  9. <script type="application/javascript" src="script/tocas/tocas.js"></script>
  10. <script type="application/javascript" src="script/jquery.min.js"></script>
  11. <script type="application/javascript" src="script/ao_module.js"></script>
  12. <style>
  13. body{
  14. background-color:white;
  15. }
  16. .themebackground{
  17. background-color:#588ce0 !important;
  18. color:white !important;
  19. background-image: url("/img/public/slate.png") !important;
  20. background-repeat: no-repeat !important;
  21. background-attachment: fixed !important;
  22. }
  23. .required{
  24. color:red;
  25. }
  26. .actionbtns{
  27. text-align:right;
  28. }
  29. </style>
  30. </head>
  31. <body>
  32. <div class="ts heading fluid padded slate themebackground" >
  33. <span class="header"><i class="add icon"></i> New User</span>
  34. <span class="description">Fill in the following user information to proceed.</span>
  35. </div>
  36. <br><br>
  37. <div class="ts container">
  38. <div class="ts horizontal form">
  39. <div class="field">
  40. <label>Username <span class="required">*</span></label>
  41. <input id="username" type="text">
  42. </div>
  43. <!--
  44. <div class="field">
  45. <label>Description</label>
  46. <input id="desc" type="text">
  47. </div>
  48. -->
  49. <div class="field">
  50. <label>Password <span class="required">*</span></label>
  51. <input id="magic" type="password">
  52. </div>
  53. <div class="field">
  54. <label>Confirm Password <span class="required">*</span></label>
  55. <input id="repeatMagic" type="password">
  56. </div>
  57. <div class="field">
  58. <label>User Group</label>
  59. <select id="usergroups">
  60. <option>Loading...</option>
  61. </select>
  62. </div>
  63. </div>
  64. <br>
  65. <p><span class="required">*</span> This field is required.</p>
  66. <div class="ts negative segment" id="err" style="display:none;">
  67. <p><i class="remove icon"></i> <span id="errmsg"></span></p>
  68. </div>
  69. <div class="ts section divider"></div>
  70. <div id="actionbtns" align="right">
  71. <button class="ts primary button" onclick="createUser();">Create</button>
  72. <button id="cancelbtn" class="ts button" onclick="cancel();">Cancel</button>
  73. </div>
  74. </div>
  75. <script>
  76. //Initiate the form items
  77. //Get usergroups and list them in the usergroup list
  78. $.get("system/permission/listgroup",function(data){
  79. $("#usergroups").html("");
  80. for(var i = 0; i < data.length; i++){
  81. $("#usergroups").append(`<option>${data[i]}</option>`);
  82. }
  83. });
  84. //Detect on enter keypress
  85. $("input").on("keydown",function(event){
  86. if (event.keyCode === 13) {
  87. event.preventDefault();
  88. createUser();
  89. }
  90. });
  91. //Hide the cancel button if not in VDI
  92. if ((!(!parent.isDesktopMode)) == false){
  93. $("#cancelbtn").hide();
  94. }
  95. //Create the new user
  96. function createUser(){
  97. var username = $("#username").val();
  98. var password = $("#magic").val();
  99. var usergroup = $("#usergroups").val();
  100. var valud = true;
  101. //Clear previous error record
  102. $("#magic").parent().removeClass("error");
  103. $("#repeatMagic").parent().removeClass("error");
  104. $("#username").parent().removeClass("error");
  105. //Check if the username is correct
  106. if (username == ""){
  107. $("#username").parent().addClass("error");
  108. valud = false;
  109. }
  110. //Check if the password match with the confirm
  111. if (password != $("#repeatMagic").val()){
  112. //Confirm password not match
  113. $("#repeatMagic").parent().addClass("error");
  114. valud = false;
  115. }
  116. if (password == ""){
  117. //Password cannot be empty
  118. $("#magic").parent().addClass("error");
  119. $("#repeatMagic").parent().addClass("error");
  120. valud = false;
  121. }
  122. if (!valud){
  123. //Current input is invalid.
  124. return;
  125. }
  126. //Create post reqest for user registering
  127. $.post("system/auth/register",{username: username, password: password, group:usergroup}).done(function(data){
  128. console.log(data);
  129. if (data.includes("Error") == false){
  130. //Everyhing is ok
  131. //Check if user already logged in. If no, redirect to login interface
  132. $.get("system/auth/checkLogin",function(data){
  133. if (data == true){
  134. if (!(!parent.isDesktopMode)){
  135. //Perform a parent callback to check if there are any functions that requires update
  136. ao_module_parentCallback(true);
  137. parent.closeFwProcess($(window.frameElement).parent().parent().attr("windowId"));
  138. }else{
  139. //Tell the user to close this UI
  140. window.location.href = "SystemAO/closeTabInsturction.html"
  141. }
  142. }else{
  143. window.location.href = "/login.system";
  144. }
  145. });
  146. }else{
  147. //There are errors.
  148. $("#errmsg").text(data);
  149. $("#err").slideDown('fast');
  150. }
  151. });
  152. }
  153. function cancel(){
  154. if (!(!parent.isDesktopMode)){
  155. parent.closeFwProcess($(window.frameElement).parent().parent().attr("windowId"));
  156. }
  157. }
  158. </script>
  159. </body>
  160. </html>