Guest User

nnnn

a guest
Nov 2nd, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.14 KB | None | 0 0
  1. <?php
  2.  
  3. require_once 'dbconfig.php';
  4. const PATH_PHOTOS = '/var/www/html/sbdev2/php/site3/upload/';
  5. global $_FILES;
  6.  
  7. class USER
  8. {
  9.  
  10. private $conn;
  11.  
  12. public function __construct()
  13. {
  14. $database = new Database();
  15. $db = $database->dbConnection();
  16. $this->conn = $db;
  17. }
  18.  
  19. public function runQuery($sql)
  20. {
  21. $stmt = $this->conn->prepare($sql);
  22. return $stmt;
  23. }
  24.  
  25. public function lasdID()
  26. {
  27. $stmt = $this->conn->lastInsertId();
  28. return $stmt;
  29. }
  30.  
  31. public function register($uname, $email, $upass, $code, $phone, $street_address, $street_address_2, $city, $state, $zip_code, $country , $portfolio)
  32. {
  33. try {
  34. // $password = md5($upass);
  35. $password = $_POST["upass"];
  36. // $hash = password_hash($upass, PASSWORD_DEFAULT);
  37. $password = password_hash('upass', PASSWORD_DEFAULT);
  38. $stmt = $this->conn->prepare("INSERT INTO tbl_users(userName,userEmail,userPass, tokenCode, phone, street_address, street_address_2 , city , state , zip_code , country , portfolio)
  39. VALUES(:user_name, :user_mail, :user_pass, :active_code, :phone , :street_address, :street_address_2 , :city , :state , :zip_code , :country, :portfolio) ;");
  40. $stmt->execute(array(
  41. ":user_name" => $uname,
  42. ":user_mail" => $email,
  43. ":user_pass" => $password,
  44. ":active_code" => $code,
  45. ":phone" => $phone,
  46. ":street_address" => $street_address,
  47. ":street_address_2" => $street_address_2,
  48. ":city" => $city,
  49. ":state" => $state,
  50. ":zip_code" => $zip_code,
  51. ":country" => $country,
  52. ":portfolio" => $portfolio
  53. ));
  54. return $stmt;
  55. } catch (PDOException $ex) {
  56. echo $ex->getMessage();
  57. }
  58. }
  59.  
  60. /* php */
  61.  
  62. public function update($uname, $email, $phone, $street_address, $street_address_2, $city, $state, $zip_code, $country, $sold_by,
  63. $portfolio, $paypal_email_id, $account_holder_name, $account_number, $branch_name, $bank_name, $ifsc_code)
  64. {
  65. try {
  66. $stmt = $this->conn->prepare('UPDATE tbl_users SET userName = ?, userEmail = ?, phone = ?, street_address = ? , street_address_2 = ?
  67. , city = ? , state = ? , zip_code = ? , country = ? , sold_by = ? , portfolio = ? , paypal_email_id = ? , account_holder_name = ? ,
  68. account_number = ?, branch_name = ? , bank_name =? , ifsc_code =? WHERE userID = ? ');
  69. return $stmt->execute(array($uname, $email, $phone, $street_address, $street_address_2, $city, $state, $zip_code, $country, $sold_by,
  70. $portfolio, $paypal_email_id, $account_holder_name, $account_number, $branch_name, $bank_name, $ifsc_code, $_SESSION['userSession']));
  71. } catch (PDOException $e) {
  72. echo '<p class="bg-danger">' . $e->getMessage() . '</p>';
  73. }
  74. }
  75.  
  76. /*php end */
  77.  
  78.  
  79. const PATH_PHOTOS = '/var/www/html/sbdev2/php/site3/upload/';
  80. const BASE_URL = 'http://sbdev2.kidsdial.com:81/php/site3/';
  81.  
  82. public function add_photo($file)
  83. {
  84. $ext = pathinfo($file['name'], PATHINFO_EXTENSION);
  85. $file['new_name'] = uniqid(rand(), true) . ".$ext";
  86. if (!$this->_upload_file($file))
  87. return false;
  88. return $this->_remove_previous_photo()->_add_file_to_db(self::PATH_PHOTOS . basename($file['new_name']));
  89. }
  90.  
  91. protected function _remove_previous_photo()
  92. {
  93. $photo = $this->get_photo();
  94. if ($photo)
  95. unlink($photo);
  96. return $this;
  97. }
  98.  
  99. public function get_photo()
  100. {
  101. global $_SESSION;
  102. $stmt = $this->conn->prepare('SELECT photo FROM tbl_users WHERE userID = ? ');
  103. $stmt->execute(array($_SESSION['userSession']));
  104. $result = $stmt->fetch();
  105. return reset($result);
  106. }
  107.  
  108. public function get_photo_url()
  109. {
  110. $pathInfo = pathinfo($this->get_photo());
  111. $last_dir = end(explode(DIRECTORY_SEPARATOR, $pathInfo['dirname']));
  112. return self::BASE_URL . "$last_dir/" . basename($this->get_photo());
  113. }
  114.  
  115. protected function _upload_file($file)
  116. {
  117. $uploadfile = self::PATH_PHOTOS . $file['new_name'];
  118. return move_uploaded_file($file['tmp_name'], $uploadfile);
  119. }
  120.  
  121. protected function _add_file_to_db($file_path)
  122. {
  123. try {
  124. $stmt = $this->conn->prepare('UPDATE tbl_users SET photo = ? WHERE userID = ? ');
  125. return $stmt->execute(array($file_path, $_SESSION['userSession']));
  126. } catch (PDOException $e) {
  127. echo '<p class="bg-danger">' . $e->getMessage() . '</p>';
  128. }
  129. }
  130.  
  131.  
  132. public function login($email, $upass)
  133. {
  134. try {
  135. $stmt = $this->conn->prepare("SELECT * FROM tbl_users WHERE userEmail=:email_id");
  136. $stmt->execute(array(":email_id" => $email));
  137. $userRow = $stmt->fetch(PDO::FETCH_ASSOC);
  138.  
  139. if ($stmt->rowCount() == 1) {
  140. if ($userRow['userStatus'] == "Y") {
  141. // if ($userRow['userPass'] == md5($upass)) {
  142. if ($userRow['userPass'] == $_POST["upass"])
  143. $password = $_POST["upass"];
  144.  
  145. $password = password_hash('upass', PASSWORD_DEFAULT);
  146.  
  147. {
  148.  
  149. $_SESSION['userSession'] = $userRow['userID'];
  150. return true;
  151. } else {
  152. header("Location: index.php?error");
  153. exit;
  154. }
  155. } else {
  156. header("Location: index.php?inactive");
  157. exit;
  158. }
  159. } else {
  160. header("Location: index.php?error");
  161. exit;
  162. }
  163. } catch (PDOException $ex) {
  164. echo $ex->getMessage();
  165. }
  166. }
  167.  
  168.  
  169. public function checkCredentials($username, $password)
  170. {
  171. $user = $this->getUserByUsername($username);
  172. if (!$user) {
  173. // No user found with provided username
  174. return false;
  175. }
  176. // if (!password_verify($password, $user['password'])) {
  177. // Password does not match
  178. // return false;
  179. // }
  180.  
  181. if(password_verify('txtpass', $password)) {
  182. echo "Passwords match";
  183. }
  184. if (password_needs_rehash($user['password'], PASSWORD_DEFAULT)) {
  185. // This password was hashed using an older algorithm, update with new hash.
  186. $this->updatePassword($user['id'], $password);
  187. }
  188. // The password is no longer needed from the user data
  189. unset($user['password']);
  190. return $user;
  191. }
  192.  
  193.  
  194. public function is_logged_in()
  195. {
  196. if (isset($_SESSION['userSession'])) {
  197. return true;
  198. }
  199. }
  200.  
  201. public function redirect($url)
  202. {
  203. header("Location: $url");
  204. }
  205.  
  206. public function logout()
  207. {
  208. session_destroy();
  209. $_SESSION['userSession'] = false;
  210. }
  211.  
  212. function send_mail($email, $message, $subject)
  213. {
  214. require_once('mailer/class.phpmailer.php');
  215. $mail = new PHPMailer();
  216. $mail->IsSMTP();
  217. $mail->SMTPDebug = 0;
  218. $mail->SMTPAuth = true;
  219. $mail->SMTPSecure = "ssl";
  220. $mail->Host = "smtp.gmail.com";
  221. $mail->Port = 465;
  222. $mail->AddAddress($email);
  223. $mail->Username = "kidsdial5@gmail.com";
  224. $mail->Password = "5dialkids";
  225. $mail->SetFrom('kidsdial5@gmail.com', 'stylebaby1');
  226. $mail->AddReplyTo("kidsdial5@gmail.com", "stylebaby2");
  227. $mail->Subject = $subject;
  228. $mail->MsgHTML($message);
  229. $mail->Send();
  230. }
  231. }
Add Comment
Please, Sign In to add comment