profile.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <?php
  2. /**
  3. * User profile view.
  4. *
  5. * Contains the view layout and ome code to present the data.
  6. *
  7. * @category View
  8. * @var Profile_Page $page The page model.
  9. * @var int $UID Player ID.
  10. */
  11. ?>
  12. <!DOCTYPE html>
  13. <html lang='en'>
  14. <head>
  15. <meta content='text/html; charset=utf-8' http-equiv='content-type'/>
  16. <meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1'/>
  17. <title><?=$page->title?></title>
  18. <link rel='shortcut icon' href='<?=$page->favicon?>'/>
  19. <!-- CSS files -->
  20. <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
  21. <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>profile.css'/>
  22. <!-- Meta tags -->
  23. <link rel='canonical' href='<?=$page->canonical?>'/>
  24. <link rel='author' href='<?=$page->author?>'/>
  25. <link rel='publisher' href='<?=$page->author?>'/>
  26. <meta name='description' content='<?=$page->description?>'/>
  27. <meta property='og:title' content='<?=$page->title?>'/>
  28. <meta property='og:url' content='<?=$page->canonical?>'/>
  29. <meta property='og:description' content='<?=$page->description?>'/>
  30. <meta property='og:image' content='<?=$page->icon?>'/>
  31. <meta property='og:site_name' content='<?=$page->name?>'/>
  32. <meta property='og:type' content='website'/>
  33. <meta property='og:locale' content='en'/>
  34. <meta name='twitter:card' content='summary'/>
  35. <meta name='twitter:title' content='<?=$page->title?>'/>
  36. <meta name='twitter:description' content='<?=$page->description?>'/>
  37. <meta name='twitter:image' content='<?=$page->icon?>'/>
  38. <meta name='twitter:url' content='<?=$page->canonical?>'/>
  39. <meta name='robots' content='index follow'/>
  40. <script>
  41. /**
  42. * Redirects to the logout action.
  43. */
  44. function logout(){
  45. window.location = '/action/logout/';
  46. }
  47. /**
  48. * Shows an error window.
  49. *
  50. * @param msg Error message
  51. */
  52. function showError(msg){
  53. document.getElementById('error_window').style.display = 'block';
  54. document.getElementById('error_msg').innerHTML = msg;
  55. }
  56. /**
  57. * Closes the error window.
  58. */
  59. function closeError(){
  60. document.getElementById('error_window').style.display = 'none';
  61. document.getElementById('error_msg').innerHTML = ' ';
  62. }
  63. /**
  64. * Shows the mail change form.
  65. */
  66. function changeMail(){
  67. document.getElementById('static_mail').style.display = 'none';
  68. document.getElementById('change_mail').style.display = 'none';
  69. document.getElementById('edit_mail').style.display = 'block';
  70. document.getElementById('save_mail').style.display = 'block';
  71. }
  72. /**
  73. * Saves an email change.
  74. *
  75. * Validates the new email format and makes an AJAX request. If
  76. * succesfull, hides the email change form.
  77. */
  78. function saveMail(){
  79. var http = new XMLHttpRequest();
  80. var mail = document.getElementById('edit_mail').value;
  81. if (mail.length < 1){
  82. showError('Please enter a new email.');
  83. return;
  84. }
  85. if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mail) == false){
  86. showError('Invalid email');
  87. return;
  88. }
  89. http.open('POST', '/action/edit_profile', true);
  90. http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
  91. http.onreadystatechange = function(){
  92. if (this.readyState == 4){
  93. if (this.status == 200 || this.status == 204){
  94. document.getElementById('static_mail').innerHTML = mail;
  95. document.getElementById('static_mail').style.display = 'block';
  96. document.getElementById('change_mail').style.display = 'block';
  97. document.getElementById('edit_mail').style.display = 'none';
  98. document.getElementById('save_mail').style.display = 'none';
  99. }
  100. else{
  101. showError('An error ocurred: ' + this.responseText + ' (' + this.status + ').');
  102. }
  103. }
  104. }
  105. http.send('uid=<?=$UID?>&mail=' + mail);
  106. }
  107. /**
  108. * Shows the password change form.
  109. */
  110. function changePass(){
  111. document.getElementById('static_pass').style.display = 'none';
  112. document.getElementById('change_pass').style.display = 'none';
  113. document.getElementById('edit_pass_current').value = '';
  114. document.getElementById('edit_pass_current').value = '';
  115. document.getElementById('edit_pass_new').value = '';
  116. document.getElementById('edit_pass_repeat').style.display = 'block';
  117. document.getElementById('edit_pass_new').style.display = 'block';
  118. document.getElementById('edit_pass_repeat').style.display = 'block';
  119. document.getElementById('save_pass').style.display = 'block';
  120. }
  121. /**
  122. * Saves a password change.
  123. *
  124. * Validates the new password and makes an AJAX request. If
  125. * succesfull, hides the password change form.
  126. */
  127. function savePass(){
  128. var http = new XMLHttpRequest();
  129. var pass = document.getElementById('edit_pass_new').value;
  130. var currentPass = document.getElementById('edit_pass_current').value;
  131. var repeatPass = document.getElementById('edit_pass_repeat').value;
  132. if (pass.length < 1){
  133. showError('Please enter a new password.');
  134. return;
  135. }
  136. if (mail.length < 6){
  137. showError('Minimum password length is 6 characters.');
  138. return;
  139. }
  140. if (currentPass.length < 1){
  141. showError('Please enter your current password.');
  142. return;
  143. }
  144. if (pass != repeatPass){
  145. showError('Entered passwords do not match.');
  146. return;
  147. }
  148. http.open('POST', '/action/edit_profile', true);
  149. http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
  150. http.onreadystatechange = function(){
  151. if (this.readyState == 4){
  152. if (this.status == 200 || this.status == 204){
  153. document.getElementById('static_pass').style.display = 'block';
  154. document.getElementById('change_pass').style.display = 'block';
  155. document.getElementById('edit_pass_current').style.display = 'none';
  156. document.getElementById('edit_pass_new').style.display = 'none';
  157. document.getElementById('edit_pass_repeat').style.display = 'none';
  158. document.getElementById('save_pass').style.display = 'none';
  159. }
  160. else{
  161. showError('An error ocurred: ' + this.responseText + ' (' + this.status + ').');
  162. }
  163. }
  164. }
  165. http.send('uid=<?=$UID?>&pass=' + pass + '&currentPass=' + currentPass);
  166. }
  167. /**
  168. * Generates a new random API key.
  169. *
  170. * Makes a request. On success, updates the API in the UI.
  171. */
  172. function regenerateApi(){
  173. var http = new XMLHttpRequest();
  174. http.open('POST', '/action/edit_profile', true);
  175. http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
  176. http.onreadystatechange = function(){
  177. if (this.readyState == 4){
  178. if (this.status == 200 || this.status == 204){
  179. document.getElementById('api_key').innerHTML = this.responseText;
  180. }
  181. else{
  182. showError('An error ocurred: ' + this.responseText + ' (' + this.status + ').');
  183. }
  184. }
  185. }
  186. http.send('uid=<?=$UID?>&api=1');
  187. }
  188. </script>
  189. </head>
  190. <body>
  191. <?php
  192. include __DIR__ . "/inc/header.php";
  193. ?>
  194. <aside>
  195. <h2>
  196. <?=$page->name?>
  197. </h2>
  198. <p>
  199. Edit your profile settings
  200. </p>
  201. </aside>
  202. <main>
  203. <section class='content'>
  204. <h2>
  205. <?=$page->name?>
  206. </h2>
  207. <article>
  208. <table id='profile'>
  209. <tr>
  210. <td class='title'>
  211. Username:
  212. </td>
  213. <td class='value'>
  214. <span>
  215. <?=$page->name?>
  216. </span>
  217. </td>
  218. <td class='action'>
  219. <input onclick='logout();' type='button' value='Logout'/>
  220. </td>
  221. </tr>
  222. <tr>
  223. <td class='title'>
  224. eMail:
  225. </td>
  226. <td class='value'>
  227. <span id='static_mail'>
  228. <?=$page->mail?>
  229. </span>
  230. <input id='edit_mail' type='text' value='<?=$page->mail?>'/>
  231. </td>
  232. <td class='action'>
  233. <input id='change_mail' onclick='changeMail();' type='button' value='Change'/>
  234. <input id='save_mail' onclick='saveMail();' type='button' value='Save'/>
  235. </td>
  236. </tr>
  237. <tr>
  238. <td class='title'>
  239. API key:
  240. </td>
  241. <td class='value'>
  242. <span id='api_key'>
  243. <?=$page->api_key?>
  244. </span>
  245. </td>
  246. <td class='action'>
  247. <input id='regenerate_api' onclick='regenerateApi();' type='button' value='Regenerate'/>
  248. </td>
  249. </tr>
  250. <tr>
  251. <td class='title'>
  252. Password:
  253. </td>
  254. <td class='value'>
  255. <span id='static_pass'>
  256. ********
  257. </span>
  258. <input id='edit_pass_current' type='password' placeholder='Currrent password'/>
  259. <input id='edit_pass_new' type='password' placeholder='New password'/>
  260. <input id='edit_pass_repeat' type='password' placeholder='Repeat password'/>
  261. </td>
  262. <td class='action'>
  263. <input id='change_pass' onclick='changePass();' type='button' value='Change'/>
  264. <input id='save_pass' onclick='savePass();' type='button' value='Save'/>
  265. </td>
  266. </tr>
  267. <tr>
  268. <td class='title'>
  269. Visibility:
  270. </td>
  271. <td id='visibility'>
  272. <input type='checkbox' name='visible' onChange='toggleVisibility(this.value);'/>
  273. <label for='filter_defeat'>Public profile</label>
  274. <div class='help_tooltip'>
  275. <p>
  276. When checked, other users can view you game data. This includes:
  277. <span>Units</span>
  278. <span>Teams</span>
  279. <span>Runes, artifacts and enchantments</span>
  280. <span>Your guild name</span>
  281. <span>Records</span>
  282. <span>Building levels</span>
  283. <span>Guild name</span>
  284. This data will never be shown to other players:
  285. <span>Personal data (email, password...)</span>
  286. <span>Run logs</span>
  287. <span>Statistics</span>
  288. <span>Guild member list</span>
  289. <span>Inventory</span>
  290. <span>Building levels</span>
  291. <span>Guild name</span>
  292. </p>
  293. </div>
  294. </td>
  295. </tr>
  296. </table>
  297. </article>
  298. </section>
  299. </main>
  300. <div id='error_window'>
  301. <section class='content'>
  302. <h2>
  303. <span>
  304. Error
  305. </span>
  306. </h2>
  307. <article>
  308. <p id='error_msg'>
  309. </p>
  310. <input type='button' value='Close' onclick='closeError();'/>
  311. </article>
  312. </section>
  313. </div>
  314. <?php
  315. include __DIR__ . "/inc/footer.php";
  316. ?>
  317. </body>
  318. </html>