profile.php 15 KB

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