settings.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <?php
  2. require_once($_SERVER['DOCUMENT_ROOT'] . "/modules/core/header.php");
  3. $gabim = "";
  4. $change_pass = false;
  5. $change_email = false;
  6. $authorizeURL = 'https://discordapp.com/api/oauth2/authorize';
  7. $tokenURL = 'https://discordapp.com/api/oauth2/token';
  8. $apiURLBase = 'https://discordapp.com/api/users/@me';
  9. $revokeURL = 'https://discordapp.com/api/oauth2/token/revoke';
  10. define('OAUTH2_CLIENT_ID', '');
  11. define('OAUTH2_CLIENT_SECRET', '');
  12. if(isset($_GET['forum']) && isset($_GET['user']))
  13. {
  14. if(!isset($link))
  15. {
  16. $link = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
  17. if($link === false)
  18. {
  19. die("ERROR: Could not connect.");
  20. }
  21. }
  22. $forum_name = $_GET['forum'];
  23. $ucp_name = $_GET['user'];
  24. if($username == $ucp_name)
  25. {
  26. $user_check_query = "UPDATE `accounts` SET `Forum` = '$forum_name' WHERE `ID` = '$playersqlid' LIMIT 1";
  27. $result = mysqli_query($link, $user_check_query);
  28. $_SESSION['forum_auth'] = $forum_name;
  29. $forum_auth = $forum_name;
  30. mysqli_free_result($result);
  31. }
  32. }
  33. if(isset($_GET['test']))
  34. {
  35. if($_GET['test'] == "revoke_discord")
  36. {
  37. if(!isset($link))
  38. {
  39. $link = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
  40. if($link === false)
  41. {
  42. die("ERROR: Could not connect.");
  43. }
  44. }
  45. apiRequest($revokeURL, array(
  46. 'token' => $discord_auth,
  47. 'client_id' => OAUTH2_CLIENT_ID,
  48. 'client_secret' => OAUTH2_CLIENT_SECRET,
  49. ));
  50. $_SESSION['discord_auth'] = "";
  51. $discord_auth = "";
  52. $user_check_query = "UPDATE `accounts` SET `Discord` = '' WHERE `ID` = '$playersqlid' LIMIT 1";
  53. $result = mysqli_query($link, $user_check_query);
  54. mysqli_free_result($result);
  55. }
  56. if($_GET['test'] == "revoke_forum")
  57. {
  58. if(!isset($link))
  59. {
  60. $link = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
  61. if($link === false)
  62. {
  63. die("ERROR: Could not connect.");
  64. }
  65. }
  66. $_SESSION['forum_auth'] = "";
  67. $forum_auth = "";
  68. $user_check_query = "UPDATE `accounts` SET `Forum` = '' WHERE `ID` = '$playersqlid' LIMIT 1";
  69. $result = mysqli_query($link, $user_check_query);
  70. mysqli_free_result($result);
  71. }
  72. }
  73. if(isset($_GET['code']))
  74. {
  75. $code = $_GET['code'];
  76. if(!isset($link))
  77. {
  78. $link = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
  79. if($link === false)
  80. {
  81. die("ERROR: Could not connect.");
  82. }
  83. }
  84. $token = apiRequest($tokenURL, array(
  85. "grant_type" => "authorization_code",
  86. 'client_id' => OAUTH2_CLIENT_ID,
  87. 'client_secret' => OAUTH2_CLIENT_SECRET,
  88. 'redirect_uri' => './panel/settings',
  89. 'code' => $code
  90. ));
  91. $_SESSION['discord_auth'] = $token->access_token;
  92. $discord_auth = $_SESSION['discord_auth'];
  93. $user_check_query = "UPDATE `accounts` SET `Discord` = '$discord_auth' WHERE `ID` = '$playersqlid' LIMIT 1";
  94. $result = mysqli_query($link, $user_check_query);
  95. mysqli_free_result($result);
  96. }
  97. // Processing form data when form is submitted
  98. if($_SERVER["REQUEST_METHOD"] == "POST")
  99. {
  100. $email = $_POST["email"];
  101. $password = $_POST['password'];
  102. $password_confirm = $_POST['password_confirm'];
  103. if(!isset($link))
  104. {
  105. $link = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
  106. if($link === false)
  107. {
  108. die("ERROR: Could not connect.");
  109. }
  110. }
  111. if((!empty($password) && empty($password_confirm)) || (empty($password) && !empty($password_confirm)))
  112. {
  113. $gabim = "Re-confirm the password by entering it.";
  114. }
  115. else if(!empty($password) && !empty($password_confirm))
  116. {
  117. if($password == $password_confirm)
  118. {
  119. $password = mysqli_real_escape_string($link, $password);
  120. $hashed_pas = hash('whirlpool', $password);
  121. $hashed_pas = strtoupper($hashed_pas);
  122. $user_check_query = "UPDATE `accounts` SET `Password` = '$hashed_pas' WHERE `ID` = '$playersqlid' LIMIT 1";
  123. $result = mysqli_query($link, $user_check_query);
  124. $change_pass = true;
  125. }
  126. else $gabim = "Password does not match.";
  127. }
  128. if(!empty($email) && $playeremail != $email)
  129. {
  130. if(valid_email($email) && $email != $playeremail) //if(containsWord($email, '@'))
  131. {
  132. $email = mysqli_real_escape_string($link, $email);
  133. $user_check_query = "SELECT `Email` FROM `accounts` WHERE `Email` = '$email' LIMIT 1";
  134. $result = mysqli_query($link, $user_check_query);
  135. $rowcount = $result->num_rows;
  136. if($rowcount == 0)
  137. {
  138. $_SESSION['playeremail'] = $email;
  139. $playeremail = $email;
  140. $user_check_query = "UPDATE `accounts` SET email = '$email' WHERE `ID` = '$playersqlid' LIMIT 1";
  141. $result = mysqli_query($link, $user_check_query);
  142. $change_email = true;
  143. }
  144. else $gabim = "This email is already in use.";
  145. }
  146. else $gabim = "Invalid email specified.";
  147. }
  148. if($change_pass == true && $change_email == true) $gabim = "Password & Email updated.";
  149. else if($change_pass == true && $change_email == false) $gabim = "Password updated.";
  150. else if($change_pass == false && $change_email == true) $gabim = "Email updated.";
  151. }
  152. if(isset($link))
  153. {
  154. mysqli_close($link);
  155. }
  156. ?>
  157. <router-outlet _ngcontent-tnh-c136="" class="router-outlet"></router-outlet>
  158. <app-settings _nghost-tnh-c144="">
  159. <div _ngcontent-tnh-c144="" class="content-header">
  160. <h3 _ngcontent-tnh-c144="" style="display: inline;">Settings</h3>
  161. <app-panel-tabs _ngcontent-tnh-c144="" _nghost-tnh-c149="">
  162. <ul _ngcontent-tnh-c149="" class="tabs">
  163. <li _ngcontent-tnh-c149="" routerlinkactive="selected" tabindex="0" class="selected">Accounts</li>
  164. </ul>
  165. </app-panel-tabs>
  166. </div>
  167. <div _ngcontent-tnh-c144="" class="content">
  168. <section _ngcontent-tnh-c144="" class="transparent grid-newline cs-1 form nopadding">
  169. <router-outlet _ngcontent-tnh-c144=""></router-outlet>
  170. <app-accounts _nghost-tnh-c174="">
  171. <section _ngcontent-tnh-c174="" class="grid grid-gap-20 transparent nopadding">
  172. <app-settings-personal _ngcontent-tnh-c174="" class="cshalf" _nghost-tnh-c189="">
  173. <div _ngcontent-tnh-c189="" class="card">
  174. <div _ngcontent-tnh-c189="" class="card-title"> Personal Information </div>
  175. <form action="./panel/settings" method="post" id="formulari">
  176. <app-input-text _ngcontent-tnh-c189="" placeholder="E-mail account" _nghost-tnh-c217="">
  177. <div _ngcontent-tnh-c217="" class="wrapper hasValue" id="email">
  178. <!----><label _ngcontent-tnh-c217="" for="input">E-mail account</label>
  179. <input _ngcontent-tnh-c217="" value="<?php echo $playeremail; ?>" id="input" name="email" type="text" class="ng-untouched ng-pristine ng-valid" oninput="onValueChange(this, 'email')">
  180. </div>
  181. </app-input-text>
  182. <div _ngcontent-tnh-c189="" class="margin-top-10">
  183. <app-input-text _ngcontent-tnh-c189="" type="password" placeholder="Password - leave blank to keep unchanged" _nghost-tnh-c217="">
  184. <div _ngcontent-tnh-c217="" class="wrapper" id="password">
  185. <!----><label _ngcontent-tnh-c217="" for="input">Password - leave blank to keep unchanged</label>
  186. <input _ngcontent-tnh-c217="" value="" name="password" id="input" type="password" class="ng-untouched ng-pristine ng-valid" oninput="onValueChange(this, 'password')">
  187. </div>
  188. </app-input-text>
  189. </div>
  190. <div _ngcontent-tnh-c189="" class="margin-top-10">
  191. <app-input-text _ngcontent-tnh-c189="" type="password" placeholder="Repeat password" _nghost-tnh-c217="">
  192. <div _ngcontent-tnh-c217="" class="wrapper" id="repeat-password">
  193. <!----><label _ngcontent-tnh-c217="" for="input">Repeat password</label>
  194. <input _ngcontent-tnh-c217="" value="" id="input" name="password_confirm" type="password" class="ng-untouched ng-pristine ng-valid" oninput="onValueChange(this, 'repeat-password')">
  195. </div>
  196. </app-input-text>
  197. </div>
  198. </form>
  199. <app-button _ngcontent-tnh-c189="" icon="fa fa-save" caption="Save" class="blue margin-top-20" _nghost-tnh-c216="" onclick="document.getElementById('formulari').submit();">
  200. <div _ngcontent-tnh-c216="" class="btn-wrapper">
  201. <div _ngcontent-tnh-c216="" class="button">
  202. <div _ngcontent-tnh-c216="" class="icon"><i _ngcontent-tnh-c216="" class="fa fa-save"></i></div>
  203. <!---->
  204. <div _ngcontent-tnh-c216="" class="caption">Save</div>
  205. <!---->
  206. </div>
  207. <!---->
  208. </div>
  209. </app-button>
  210. </div>
  211. <!---->
  212. </app-settings-personal>
  213. </section>
  214. <!---->
  215. </app-accounts>
  216. <!---->
  217. </section>
  218. </div>
  219. </app-settings>
  220. <!---->