Advertisement
Guest User

Untitled

a guest
Jul 17th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.68 KB | None | 0 0
  1. <?php
  2.  
  3. class Index_Model extends Model
  4. {
  5.  
  6. public function __construct()
  7. {
  8. parent::__construct();
  9. }
  10.  
  11. public function convertToNumericEntities($string) {
  12. $convmap = array(0x80, 0x10ffff, 0, 0xffffff);
  13. return mb_encode_numericentity($string, $convmap, "UTF-8");
  14. }
  15.  
  16. function run()
  17. {
  18. if (isset($_POST['loginForm_default_password']) && isset($_POST['loginForm_default_username']))
  19. {
  20. $sth = $this->db->prepare("SELECT id, username FROM users WHERE username = :username AND password= :password");
  21.  
  22.  
  23. $username = $this->convertToNumericEntities(htmlentities($_POST['loginForm_default_username']));
  24. $sth->execute(array(
  25. ':username' => $username,
  26. ':password' => md5($_POST['loginForm_default_password'])
  27. ));
  28.  
  29. $data = $sth->fetchAll();
  30.  
  31. // $data = $sth->fetchAll();
  32. $count = $sth->rowCount();
  33.  
  34. if ($count > 0)
  35. {
  36. $sth = $this->db->prepare("SELECT is_ban, ban_reason FROM users WHERE id = :id");
  37. $sth->execute(array(':id' => $data[0]['id']));
  38.  
  39. $data2 = $sth->fetchAll();
  40.  
  41. if ($data2[0]['is_ban'] == 1)
  42. {
  43. echo json_encode(array('result' => $data2[0]['ban_reason'].'!!'));
  44. }
  45. else if ($data2[0]['is_ban'] == 0)
  46. {
  47. // login
  48. Session::init();
  49. Session::set('loggedIn', true);
  50. Session::set('account_ID', $data[0]['id']);
  51. echo json_encode(array('result' => 'logged'));
  52. }
  53. }
  54.  
  55. else
  56. {
  57. echo json_encode(array('result' => 'La combinaison entre le pseudonyme et le mot de passe est inconnue.<br>Veuillez vérifier vos données et réessayez.'));
  58. // header('location: /index');
  59. }
  60. }
  61. }
  62.  
  63.  
  64. function add_to_db_generator($id, $item_id)
  65. {
  66. $sql =
  67. '
  68. INSERT INTO `users_items`(`player_id`, `item_id`)
  69. VALUES
  70. (:player_id,:item_id),
  71. (:player_id,:item_id),
  72. (:player_id,:item_id),
  73. (:player_id,:item_id),
  74. (:player_id,:item_id),
  75. (:player_id,:item_id),
  76. (:player_id,:item_id),
  77. (:player_id,:item_id),
  78. (:player_id,:item_id),
  79. (:player_id,:item_id),
  80. (:player_id,:item_id),
  81. (:player_id,:item_id),
  82. (:player_id,:item_id),
  83. (:player_id,:item_id),
  84. (:player_id,:item_id);
  85. ';
  86.  
  87. $req = $this->db->prepare($sql);
  88. $req->execute(array('player_id' => $id, 'item_id' => $item_id));
  89. }
  90.  
  91. function add_to_db_laser($id, $item_id)
  92. {
  93. $sql =
  94. '
  95. INSERT INTO `users_items`(`player_id`, `item_id`)
  96. VALUES
  97. (:player_id,:item_id),
  98. (:player_id,:item_id),
  99. (:player_id,:item_id),
  100. (:player_id,:item_id),
  101. (:player_id,:item_id),
  102. (:player_id,:item_id),
  103. (:player_id,:item_id),
  104. (:player_id,:item_id),
  105. (:player_id,:item_id),
  106. (:player_id,:item_id),
  107. (:player_id,:item_id),
  108. (:player_id,:item_id),
  109. (:player_id,:item_id),
  110. (:player_id,:item_id),
  111. (:player_id,:item_id),
  112. (:player_id,:item_id),
  113. (:player_id,:item_id),
  114. (:player_id,:item_id),
  115. (:player_id,:item_id),
  116. (:player_id,:item_id),
  117. (:player_id,:item_id),
  118. (:player_id,:item_id),
  119. (:player_id,:item_id),
  120. (:player_id,:item_id),
  121. (:player_id,:item_id),
  122. (:player_id,:item_id),
  123. (:player_id,:item_id),
  124. (:player_id,:item_id),
  125. (:player_id,:item_id),
  126. (:player_id,:item_id),
  127. (:player_id,:item_id);
  128. ';
  129.  
  130. $req = $this->db->prepare($sql);
  131. $req->execute(array('player_id' => $id, 'item_id' => $item_id));
  132. }
  133.  
  134. function add_to_db_drone($id, $item_id)
  135. {
  136. $sql =
  137. '
  138. INSERT INTO `users_items`(`player_id`, `item_id`)
  139. VALUES
  140. (:player_id,:item_id),
  141. (:player_id,:item_id),
  142. (:player_id,:item_id),
  143. (:player_id,:item_id),
  144. (:player_id,:item_id),
  145. (:player_id,:item_id),
  146. (:player_id,:item_id),
  147. (:player_id,:item_id);
  148. ';
  149.  
  150. $req = $this->db->prepare($sql);
  151. $req->execute(array('player_id' => $id, 'item_id' => $item_id));
  152. }
  153.  
  154.  
  155. function add_user_config($playerid, $configid, $current_shield, $max_shield, $ship_speed)
  156. {
  157. $req = $this->db->prepare('INSERT INTO `player_config`(`player_id`, `config_id`, `current_shield`, `max_shield`, `ship_speed`) VALUES (:playerid, :configid, :current_shield, :max_shield, :ship_speed)');
  158. $req->execute(
  159. array('playerid' => $playerid,
  160. 'configid' => $configid,
  161. 'current_shield' => $current_shield,
  162. 'max_shield' => $max_shield,
  163. 'ship_speed' => $ship_speed
  164. ));
  165. }
  166.  
  167.  
  168. function register()
  169. {
  170. try
  171. {
  172. $form = new Form();
  173.  
  174. $form ->post('signup_username')
  175. ->val('verifyUsername')
  176. ->post('signup_passwordRepeat')
  177. ->post('signup_password')
  178. ->val('verifyPassword', 'signup_passwordRepeat')
  179. ->post('signup_email')
  180. ->val('emailIsValid')
  181. ->post('signup_company')
  182. ->val('verifyFirm');
  183.  
  184. $form ->submit();
  185. $data = $form->fetch();
  186.  
  187. $this->db->insert('users', array(
  188. 'username' => $data['signup_username'],
  189. 'password' => md5($data['signup_password']),
  190. 'email' => $data['signup_email'],
  191. 'factionid' => $data['signup_company']
  192. ));
  193.  
  194. $sth = $this->db->prepare("SELECT id FROM users WHERE username = :username AND password= :password");
  195.  
  196.  
  197. $sth->execute(array(
  198. ':username' => $data['signup_username'],
  199. ':password' => md5($data['signup_password'])
  200. ));
  201.  
  202. $result = $sth->fetchAll();
  203.  
  204. $this->db->insert('users_settings', array(
  205. 'playerid' => $result[0]['id']
  206. ));
  207.  
  208. $this->add_to_db_laser($result[0]['id'], 1);
  209. $this->add_to_db_generator($result[0]['id'], 2);
  210. $this->add_to_db_generator($result[0]['id'], 2);
  211. $this->add_to_db_generator($result[0]['id'], 4);
  212. $this->add_to_db_drone($result[0]['id'], 3);
  213. $this->add_user_config($result[0]['id'], 1, 0, 0, 300);
  214. $this->add_user_config($result[0]['id'], 2, 0, 0, 300);
  215.  
  216. echo json_encode(array('result' => 'You have been registered. You can now login '.$data['signup_username'].' !'.Session::get('aleat_nbr')));
  217.  
  218.  
  219. }
  220. catch (Exception $e)
  221. {
  222. echo $e->getMessage();
  223. }
  224. }
  225.  
  226. function captcha()
  227. {
  228. // On définit la configuration :
  229. $nbr_chiffres = 6; // Nombre de chiffres qui formeront le nombre
  230.  
  231. ##### Ici on crée la variable qui contiendra le nombre aléatoire #####
  232. $i = 0;
  233. while($i < $nbr_chiffres) {
  234. $chiffre = mt_rand(0, 9); // On génère le nombre aléatoire
  235. $chiffres[$i] = $chiffre;
  236. $i++;
  237. }
  238. $nombre = null;
  239. // On explore le tableau $chiffres afin d'y afficher toutes les entrées qui s'y trouvent
  240. foreach ($chiffres as $caractere) {
  241. $nombre .= $caractere;
  242. }
  243. ##### On a fini de créer le nombre aléatoire, on le rentre maintenant dans une variable de session #####
  244. Session::set('aleat_nbr', $nombre);
  245.  
  246. // Là, on définit le header de la page pour la transformer en image
  247. // header ("Content-type: image/png");
  248. // Là, on crée notre image
  249. $_img = imagecreatefrompng(URL.'util/fond_verif_img.png');
  250.  
  251. // On définit maintenant les couleurs
  252. // Couleur de fond :
  253. $arriere_plan = imagecolorallocate($_img, 0, 0, 0); // Au cas où on n'utiliserait pas d'image de fond, on utilise cette couleur-là.
  254. // Autres couleurs :
  255. $avant_plan = imagecolorallocate($_img, 255, 255, 255); // Couleur des chiffres
  256.  
  257. // On détruit les variables inutiles :
  258. unset($chiffre);
  259. unset($i);
  260. unset($caractere);
  261. unset($chiffres);
  262.  
  263. imagestring($_img, 5, 18, 8, $nombre, $avant_plan);
  264. $red = imagecolorallocate($_img, 0, 255, 0);
  265. imagesetthickness($_img, 1);
  266. imageline($_img, 0, 10, 100, 20, $red);
  267. // imageline(image, x1, y1, x2, y2, color);
  268.  
  269. imagepng($_img);
  270. }
  271.  
  272. }
  273.  
  274. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement