Advertisement
Guest User

Untitled

a guest
Feb 25th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.73 KB | None | 0 0
  1. <?php
  2. namespace xcode;
  3. class registerUser {
  4. private $conn;
  5. private $escapeObj;
  6. private $id;
  7.  
  8. private $name;
  9. private $usename;
  10. private $email;
  11. private $password;
  12. private $gender;
  13. private $birthday = '';
  14. private $location = '';
  15. private $hometown = '';
  16. private $about = '';
  17.  
  18. private $allowedGenders = array('male', 'female');
  19.  
  20. function __construct()
  21. {
  22. global $conn;
  23. $this->conn = $conn;
  24. $this->escapeObj = new xcodeEscape();
  25. return $this;
  26. }
  27.  
  28. public function setConnection(mysqli $conn)
  29. {
  30. $this->conn = $conn;
  31. return $this;
  32. }
  33.  
  34. protected function getConnection()
  35. {
  36. return $this->conn;
  37. }
  38.  
  39. public function register()
  40. {
  41. if (! empty ($this->name) &&
  42. ! empty ($this->username) &&
  43. ! empty ($this->email) &&
  44. ! empty ($this->password) &&
  45. ! empty ($this->gender))
  46. {
  47. $query = $this->getConnection()->query("INSERT INTO " . DB_ACCOUNTS . " (active,about,cover_id,email,email_verification_key,name,password,time,type,username) VALUES (1,'" . $this->about . "',0,'" . $this->email . "','" . md5(generateKey()) . "','" . $this->name . "','" . $this->password . "'," . time() . ",'user','" . $this->username . "')");
  48.  
  49. if ($query)
  50. {
  51. $this->id = $this->getConnection()->insert_id;
  52. $query2 = $this->getConnection()->query("INSERT INTO " . DB_USERS . " (id,birthday,gender,current_city,hometown) VALUES (" . $this->id . ",'" . $this->birthday . "','" . $this->gender . "','" . $this->location . "','" . $this->hometown . "')");
  53.  
  54. if ($query2)
  55. {
  56. $timelineObj = new xcodeUser();
  57. $timelineObj->setId($this->id);
  58. $get = $timelineObj->getRows();
  59. return $get;
  60. }
  61. }
  62. }
  63. }
  64.  
  65. private function validateUsername($u)
  66. {
  67. if (strlen($u) > 3 && ! is_numeric($u) && preg_match('/^[A-Za-z0-9_]+$/', $u))
  68. {
  69. return true;
  70. }
  71. }
  72.  
  73. public function setName($n)
  74. {
  75. if (! empty($n))
  76. {
  77. $this->name = $this->escapeObj->stringEscape($n);
  78. }
  79. }
  80.  
  81. public function setUsername($u)
  82. {
  83. if ($this->validateUsername($u))
  84. {
  85. $this->username = $this->escapeObj->stringEscape($u);
  86. }
  87. }
  88.  
  89. public function setEmail($e)
  90. {
  91. if (filter_var($e, FILTER_VALIDATE_EMAIL))
  92. {
  93. $this->email = $this->escapeObj->stringEscape($e);
  94. }
  95. }
  96.  
  97. public function setPassword($p)
  98. {
  99. if (! empty($p))
  100. {
  101. $hashpass = password_hash('$p', PASSWORD_DEFAULT);
  102. $this->password = $hashpass;
  103. }
  104. }
  105.  
  106. public function setGender($g)
  107. {
  108. if (in_array($g, $this->allowedGenders))
  109. {
  110. $this->gender = $g;
  111. }
  112. }
  113.  
  114. public function setBirthday($b)
  115. {
  116. if (is_array($b))
  117. {
  118. $b = implode('-', $b);
  119. $regex = '/^([0-9]{1,2})-([0-9]{1,2})-([0-9]{4})$/';
  120.  
  121. if (preg_match($regex, $b))
  122. {
  123. $this->birthday = $b;
  124. }
  125. }
  126. }
  127.  
  128. public function setLocation($l)
  129. {
  130. if (! empty($l))
  131. {
  132. $this->location = $this->escapeObj->stringEscape($l);
  133. }
  134. }
  135.  
  136. public function setHometown($h)
  137. {
  138. if (! empty($h))
  139. {
  140. $this->hometown = $this->escapeObj->stringEscape($h);
  141. }
  142. }
  143.  
  144. public function setAbout($a)
  145. {
  146. if (! empty($a))
  147. {
  148. $this->about = $this->escapeObj->stringEscape($a);
  149. }
  150. }
  151. }
  152.  
  153. <?php
  154. $data['error_message'] = $lang['error_empty_login'];
  155.  
  156. $loginId = $escapeObj->stringEscape($_POST['login_id']);
  157. $hash = password_hash($_POST['login_password'], PASSWORD_DEFAULT);
  158. $cr_pass = password_verify($_POST['login_password'], $hash);
  159.  
  160. $userId = getUserId($conn, $loginId);
  161.  
  162. if ($userId)
  163. {
  164. $query = $conn->query("SELECT id,username,email_verified FROM " . DB_ACCOUNTS . " WHERE id=$userId AND password='$cr_pass' AND type='user' AND active=1");
  165. $data['error_message'] = $lang['error_bad_login'];
  166.  
  167. if ($query->num_rows == 1)
  168. {
  169. $fetch = $query->fetch_array(MYSQLI_ASSOC);
  170. $continue = true;
  171.  
  172. if ($config['email_verification'] == 1 && $fetch['email_verified'] == 0)
  173. {
  174. $continue = false;
  175. $data['error_message'] = $lang['error_verify_email'];
  176. }
  177.  
  178. if ($continue == true)
  179. {
  180. $_SESSION['user_id'] = $fetch['id'];
  181. $_SESSION['user_pass'] = $cr_pass;
  182.  
  183. if (isset($_POST['keep_logged_in']) && $_POST['keep_logged_in'] == true)
  184. {
  185. setcookie('sk_u_i', $_SESSION['user_id'], time() + (60 * 60 * 24 * 7));
  186. setcookie('sk_u_p', $_SESSION['user_pass'], time() + (60 * 60 * 24 * 7));
  187. }
  188.  
  189. $data['status'] = 200;
  190. $data['redirect_url'] = smoothLink('index.php?tab1=home');
  191. }
  192. }
  193. else
  194. {
  195. $data['error_message'] = $lang['incorrect_password'];
  196. }
  197. }
  198. else
  199. {
  200. $data['error_message'] = $lang['no_user_found'];
  201. }
  202. header("Content-type: application/json; charset=utf-8");
  203. echo json_encode($data);
  204. $conn->close();
  205. exit();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement