Advertisement
Guest User

Untitled

a guest
Sep 21st, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.25 KB | None | 0 0
  1. <?php
  2. class register_class extends database_class {
  3.  
  4. // Class constructor
  5. function __construct($username, $password, $password_comfirm, $email, $pin, $gender){
  6. $this->username = $username;
  7. $this->password = $password;
  8. $this->password_comfirm = $password_comfirm;
  9. $this->email = $email;
  10. $this->pin = $pin;
  11. $this->gender = $gender;
  12. $this->salt = 'xxx';
  13. $this->hashed_password = md5($this->salt.$this->password);
  14. $this->key = $this->create_verify_code();
  15. }
  16.  
  17. // Function to create the verify link
  18. function create_verify_code(){
  19. $chars = array(0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
  20. $verify_code = '';
  21. $max = count($chars)-1;
  22. for($i = 0; $i < 20; $i++){
  23. $verify_code .= (!($i % 5) && $i ? '-' : '') . $chars[rand(0, $max)];
  24. }
  25.  
  26. return $verify_code;
  27. }
  28.  
  29. // Function to check if a username already exists in our database
  30. function check_username(){
  31. $this->connect();
  32. $userrname_check = $this->execute_query("SELECT * FROM Users WHERE username = '" . $this->username . "'");
  33. if($userrname_check && mysqli_num_rows($userrname_check) > 0){
  34. return true;
  35. }else{
  36. return false;
  37. }
  38. }
  39.  
  40. // Function to register the account
  41. function register_account(){
  42. $this->connect();
  43. $register_account = $this->execute_query("INSERT INTO Users (username, password, email, gender, ip, pin, activate_key) VALUES ('" . $this->username . "', '" . $this->hashed_password . "', '" . $this->email . "', '" . $this->gender . "', '" . $_SERVER['REMOTE_ADDR'] . "', '" . $this->pin . "', '" . $this->key . "')");
  44. return $register_account;
  45. }
  46.  
  47. // Function to send registration mail to user
  48. function send_registration_mail(){
  49. $subject = 'Signup | Verification';
  50. $message = '
  51.  
  52. Thanks for signing up! Your account has been created, you can login with the following credentials after you have activated your account by pressing the url below.
  53.  
  54. ------------------------
  55. username: ' . $this->username . '
  56. Password: ' . $this->password . '
  57. ------------------------
  58.  
  59. Please click this link to activate your account:
  60. http://www.pr0b.com/verify.php?key='. $this->key .'
  61. ';
  62.  
  63. $headers = 'From: noreply@pr0b.com' . "rn";
  64. mail($this->email, $subject, $message, $headers);
  65. }
  66.  
  67. // Function to create the outfit xml file
  68. function create_outfit_json(){
  69. if (!file_exists('../user/' . $this->username)) {
  70. mkdir('../user/' . $this->username, 0777, true);
  71. }
  72.  
  73. $json['outfits']['0'] = [
  74. 'outfit' => [
  75. 'url' => 'placeholder',
  76. 'default' => 1,
  77. 'name' => 'New outfit',
  78. 'c' => '#bb9977',
  79. 'mood' => 3,
  80. 'species' => 'male'
  81. ]
  82. ];
  83.  
  84. $fp = fopen('../user/' . $this->username . '/outfits.json', 'w');
  85. fwrite($fp, json_encode($json));
  86. fclose($fp);
  87.  
  88. if (file_exists('../user/' . $this->username . '/outfits.json')) {
  89. return true;
  90. }else{
  91. return false;
  92. }
  93. }
  94.  
  95. // Function to create the purchase xml file
  96. function create_purchased_json(){
  97. if (!file_exists('../user/' . $this->username)) {
  98. mkdir('../user/' . $this->username, 0777, true);
  99. }
  100.  
  101. $json['purchased'] = [
  102. 'item' => [
  103. 'url' => 'placeholder',
  104. 'name' => 'placeholder',
  105. 'category' => 'placeholder',
  106. 'c' => 'placeholder',
  107. 'c2' => 'placeholder',
  108. 'species' => 'placeholder'
  109. ]
  110. ];
  111.  
  112. $fp = fopen('../user/' . $this->username . '/purchased.json', 'w');
  113. fwrite($fp, json_encode($json));
  114. fclose($fp);
  115.  
  116. if (file_exists('../user/' . $this->username . '/purchased.json')) {
  117. return true;
  118. }else{
  119. return false;
  120. }
  121. }
  122.  
  123. // Function to create current outfit xml file
  124. function create_current_outfit_json(){
  125. if (!file_exists('../user/' . $this->username)) {
  126. mkdir('../user/' . $this->username, 0777, true);
  127. }
  128.  
  129. $json['outfit'] = [];
  130. $json['outfit'] = [
  131. 'outfit' => [
  132. 'url' => 'placeholder',
  133. 'default' => 1,
  134. 'name' => 'New outfit',
  135. 'c' => '#bb9977',
  136. 'mood' => 3,
  137. 'species' => 'male'
  138.  
  139. ],
  140. 'head' => [
  141. 'url' => 'placeholder',
  142. 'c' => '#bb9977',
  143. 'c2' => '#bb9977',
  144. 'z' => 1
  145. ],
  146. 'face' => [
  147. 'url' => 'placeholder',
  148. 'c' => '#bb9977',
  149. 'c2' => '#bb9977',
  150. 'z' => 1
  151. ],
  152. 'midsection' => [
  153. 'url' => 'placeholder',
  154. 'c' => '#bb9977',
  155. 'c2' => '#bb9977',
  156. 'z' => 1
  157. ],
  158. 'leg' => [
  159. 'url' => 'placeholder',
  160. 'c' => '#bb9977',
  161. 'c2' => '#bb9977',
  162. 'z' => 1
  163. ],
  164. 'hair' => [
  165. 'url' => 'placeholder',
  166. 'c' => '#bb9977',
  167. 'c2' => '#bb9977',
  168. 'z' => 1
  169. ],
  170. 'shirt' => [
  171. 'url' => 'placeholder',
  172. 'c' => '#bb9977',
  173. 'c2' => '#bb9977',
  174. 'z' => 1
  175. ],
  176. 'jacket' => [
  177. 'url' => 'placeholder',
  178. 'c' => '#bb9977',
  179. 'c2' => '#bb9977',
  180. 'z' => 1
  181. ],
  182. 'bottom' => [
  183. 'url' => 'placeholder',
  184. 'c' => '#bb9977',
  185. 'c2' => '#bb9977',
  186. 'z' => 1
  187. ],
  188. 'electronic' => [
  189. 'url' => 'placeholder',
  190. 'c' => '#bb9977',
  191. 'c2' => '#bb9977',
  192. 'z' => 1
  193. ],
  194. 'hat' => [
  195. 'url' => 'placeholder',
  196. 'c' => '#bb9977',
  197. 'c2' => '#bb9977',
  198. 'z' => 1
  199. ],
  200. 'earrings' => [
  201. 'url' => 'placeholder',
  202. 'c' => '#bb9977',
  203. 'c2' => '#bb9977',
  204. 'z' => 1
  205. ],
  206. 'belt' => [
  207. 'url' => 'placeholder',
  208. 'c' => '#bb9977',
  209. 'c2' => '#bb9977',
  210. 'z' => 1
  211. ],
  212. 'bracelet' => [
  213. 'url' => 'placeholder',
  214. 'c' => '#bb9977',
  215. 'c2' => '#bb9977',
  216. 'z' => 1
  217. ],
  218. 'necklace' => [
  219. 'url' => 'placeholder',
  220. 'c' => '#bb9977',
  221. 'c2' => '#bb9977',
  222. 'z' => 1
  223. ],
  224. 'facialhair' => [
  225. 'url' => 'placeholder',
  226. 'c' => '#bb9977',
  227. 'c2' => '#bb9977',
  228. 'z' => 1
  229. ],
  230. 'food' => [
  231. 'url' => 'placeholder',
  232. 'c' => '#bb9977',
  233. 'c2' => '#bb9977',
  234. 'z' => 1
  235. ],
  236. 'facialdecorations' => [
  237. 'url' => 'placeholder',
  238. 'c' => '#bb9977',
  239. 'c2' => '#bb9977',
  240. 'z' => 1
  241. ]
  242. ];
  243.  
  244. $fp = fopen('../user/' . $this->username . '/currentOutfit.json', 'w');
  245. fwrite($fp, json_encode($json));
  246. fclose($fp);
  247.  
  248. if (file_exists('../user/' . $this->username . '/currentOutfit.json')) {
  249. return true;
  250. }else{
  251. return false;
  252. }
  253. }
  254.  
  255. // Function to execute the class
  256. function class_handler(){
  257. if(!$this->username){
  258. return 'Error: username is required. Please enter a valid username.';
  259. }else if(!$this->password){
  260. return 'Error: Password is required. Please enter a valid password.';
  261. }else if($this->password !== $this->password_comfirm){
  262. return 'Error: The Passwords doesnt match. Please try again.';
  263. }else if(!$this->email){
  264. return 'Error: Email is required. Please enter a valid email.';
  265. }else if(!$this->pin){
  266. return 'Error: Pin is required. Please enter a pin code.';
  267. }else{
  268. $username_check = $this->check_username();
  269. if($username_check == true){
  270. return 'The username: ' . $this->username . ' is already in use. Please pick another username.';
  271. }else{
  272. $register_account = $this->register_account();
  273. if($register_account == false){
  274. return 'Error: The following account could not be created: ' . $this->username . '. Please try later again.';
  275. }else{
  276. $this->send_registration_mail();
  277. $create_outfit_json = $this->create_outfit_json();
  278. $create_purchased_json = $this->create_purchased_json();
  279. $create_current_outfit_json = $this->create_current_outfit_json();
  280.  
  281. if($create_outfit_json == true || $create_purchased_json == true || $create_current_outfit_json == true){
  282. return 'The following account was succesful created: ' . $this->username;
  283. }else {
  284. return 'Error: The following account could not be created: ' . $this->username . '. Please try later again.';
  285. }
  286. }
  287. }
  288. }
  289. }
  290.  
  291. }
  292. ?>
  293.  
  294. <?php
  295. if (!file_exists('../user/testusername')) {
  296. mkdir('../user/testusername', 0777, true);
  297. }
  298.  
  299. $json['outfits']['0'] = [
  300. 'outfit' => [
  301. 'url' => 'placeholder',
  302. 'default' => 1,
  303. 'name' => 'New outfit',
  304. 'c' => '#bb9977',
  305. 'mood' => 3,
  306. 'species' => 'male'
  307. ]
  308. ];
  309.  
  310. $fp = fopen('../user/testusername/outfits.json', 'w');
  311. fwrite($fp, json_encode($json));
  312. fclose($fp);
  313. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement