account.html 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <html>
  2. <head>
  3. <title>User Account</title>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0 user-scalable=no">
  6. <link rel="stylesheet" href="../../script/semantic/semantic.min.css">
  7. <script type="text/javascript" src="../../script/jquery.min.js"></script>
  8. <script type="text/javascript" src="../../script/semantic/semantic.min.js"></script>
  9. </head>
  10. <body>
  11. <div class="ui container">
  12. <div class="ui basic segment">
  13. <div class="ui header">
  14. <i class="user circle icon"></i>
  15. <div class="content">
  16. My Account
  17. <div class="sub header">Manage your account information and password</div>
  18. </div>
  19. </div>
  20. </div>
  21. <div class="ui stackable grid">
  22. <div class="six wide column">
  23. <div class="ui card">
  24. <div class="image">
  25. <img id="profileIcon" src="../users/img/user.svg">
  26. </div>
  27. <div class="content">
  28. <a id="username" class="header"></a>
  29. <div class="meta">
  30. <p><i class="ui envelope icon"></i><span id="email" class="date"></span><br>
  31. <i class="ui user circle icon"></i><span id="usergroup" class="date"></span></p>
  32. </div>
  33. </div>
  34. </div>
  35. </div>
  36. <div class="ten wide column">
  37. <h4 class="ui header">
  38. Change Profile Picture
  39. </h4>
  40. <button class="ui blue button" onclick="handleProfilePic();">Upload</button>
  41. <div class="ui divider"></div>
  42. <h4 class="ui header">
  43. Change Contact Email
  44. </h4>
  45. <form class="ui form" onsubmit="handleEmailChange(event);">
  46. <div class="field">
  47. <label>New Email</label>
  48. <input id="newemail" type="text" placeholder="New Email">
  49. </div>
  50. <button class="ui blue button" type="submit">Update</button>
  51. </form>
  52. <div class="ui divider"></div>
  53. <h4 class="ui header">
  54. Change Password
  55. </h4>
  56. <form class="ui form" onsubmit="handleSubmit(event);">
  57. <div class="field">
  58. <label>Old Password</label>
  59. <input id="opw" type="password" placeholder="Old Password">
  60. </div>
  61. <div class="field">
  62. <label>New password</label>
  63. <input id="npw" type="password" placeholder="New Password">
  64. </div>
  65. <div class="field">
  66. <label>Confirm New Password</label>
  67. <input id="cpw" type="password" placeholder="Confirm New Password">
  68. </div>
  69. <button class="ui blue button" type="submit">Update</button>
  70. </form>
  71. <div id="msgbox" class="ui green message" style="display:none;">
  72. <i class="close icon"></i>
  73. <div class="header">
  74. Welcome back!
  75. </div>
  76. <p class="message">This is a special notification which you can dismiss if you're bored with it.</p>
  77. </div>
  78. </div>
  79. </div>
  80. </div>
  81. <script>
  82. //Initiate user information
  83. $.get("../../system/users/userinfo",function(data){
  84. if (data.error !== undefined){
  85. //Not logged in?
  86. }else{
  87. if (data.Icondata == ""){
  88. $("#profileIcon").attr('src', "../users/img/noprofileicon.svg");
  89. }else{
  90. $("#profileIcon").attr('src', data.Icondata);
  91. }
  92. $("#username").text(data.Username);
  93. console.log(data.Usergroup);
  94. $("#usergroup").text(data.Usergroup.join(" / "));
  95. }
  96. });
  97. function initUserEmail(){
  98. $.get("../../system/register/email", function(data){
  99. if (data == ""){
  100. //Not set
  101. $("#email").text("( Not Configured )");
  102. }else{
  103. $("#email").text(data);
  104. }
  105. });
  106. }
  107. initUserEmail();
  108. //Handle change password form submit
  109. function handleSubmit(event){
  110. event.preventDefault();
  111. //Check if new password and confirm matches
  112. var oldPassword = $("#opw").val();
  113. var newPassword = $("#npw").val();
  114. var confirmPassword = $("#cpw").val();
  115. if (newPassword != confirmPassword){
  116. $("#cpw").parent().addClass("error");
  117. return;
  118. }else{
  119. $("#cpw").parent().removeClass("error");
  120. }
  121. //OK to proceed.
  122. $.ajax({
  123. url: "../../system/users/userinfo",
  124. method: "POST",
  125. data: {opr: "changepw", oldpw: oldPassword, newpw: newPassword},
  126. success: function(data){
  127. if (data.error != undefined){
  128. msgbox("Update Failed", data.error);
  129. }else{
  130. //Updated suceed.
  131. msgbox("Update Succeed", "Your password has been updated.");
  132. }
  133. }
  134. });
  135. }
  136. function handleEmailChange(e){
  137. e.preventDefault();
  138. var newEmail = $("#newemail").val();
  139. $.ajax({
  140. url: "../../system/register/email",
  141. data: {email: newEmail},
  142. success: function(data){
  143. if (data.error !== undefined){
  144. alert(data.error);
  145. }else{
  146. msgbox("Update Succeed", "Your email has been updated.");
  147. initUserEmail();
  148. }
  149. }
  150. });
  151. }
  152. function handleProfilePic(){
  153. ao_module_selectFiles(function(files){
  154. if (FileReader && files && files.length) {
  155. var fr = new FileReader();
  156. fr.onload = function () {
  157. //Update the database for the new image
  158. var fullImageDatapath = fr.result;
  159. $.ajax({
  160. url: "../../system/users/userinfo",
  161. method: "POST",
  162. data: {opr: "changeprofilepic", picdata: fullImageDatapath},
  163. success: function(data){
  164. if (data.error !== undefined){
  165. console.log(data.error);
  166. }else{
  167. //Load the image into the src div
  168. document.getElementById("profileIcon").src = fullImageDatapath;
  169. }
  170. }
  171. })
  172. }
  173. fr.readAsDataURL(files[0]);
  174. }
  175. },"file", ".png",false);
  176. }
  177. function msgbox(header, message){
  178. $("#msgbox").fadeIn('fast');
  179. $("#msgbox").find(".header").text(header);
  180. $("#msgbox").find(".message").text(message);
  181. }
  182. //Hook close msgbox event
  183. $('.message .close')
  184. .on('click', function() {
  185. $(this).parent().fadeOut('fast');
  186. });
  187. </script>
  188. </body>
  189. </html>