Guest User

c,lass.usr.php

a guest
Oct 16th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.69 KB | None | 0 0
  1. <?php
  2.  
  3. require_once 'dbconfig.php';
  4.  
  5. class USER
  6. {
  7.  
  8. private $conn;
  9.  
  10. public function __construct()
  11. {
  12. $database = new Database();
  13. $db = $database->dbConnection();
  14. $this->conn = $db;
  15. }
  16.  
  17. public function runQuery($sql)
  18. {
  19. $stmt = $this->conn->prepare($sql);
  20. return $stmt;
  21. }
  22.  
  23. public function lasdID()
  24. {
  25. $stmt = $this->conn->lastInsertId();
  26. return $stmt;
  27. }
  28.  
  29. public function register($uname,$email,$upass, $code, $phone, $street_address, $street_address_2 , $city , $state , $zip_code , $country)
  30. {
  31. try
  32. {
  33. $password = md5($upass);
  34. $stmt = $this->conn->prepare("INSERT INTO tbl_users(userName,userEmail,userPass, tokenCode, phone, street_address, street_address_2 , city , state , zip_code , country)
  35. VALUES(:user_name, :user_mail, :user_pass, :active_code, :phone , :street_address, :street_address_2 , :city , :state , :zip_code , :country)");
  36. $stmt->bindparam(":user_name",$uname);
  37. $stmt->bindparam(":user_mail",$email);
  38. $stmt->bindparam(":user_pass",$password);
  39. $stmt->bindparam(":active_code",$code);
  40. $stmt->bindparam(":phone",$phone);
  41. $stmt->bindparam(":street_address",$street_address);
  42. $stmt->bindparam(":street_address_2",$street_address_2);
  43. $stmt->bindparam(":city",$city);
  44. $stmt->bindparam(":state",$state);
  45. $stmt->bindparam(":zip_code",$zip_code);
  46. $stmt->bindparam(":country",$country);
  47. $stmt->execute();
  48. return $stmt;
  49. }
  50. catch(PDOException $ex)
  51. {
  52. echo $ex->getMessage();
  53. }
  54. }
  55.  
  56. /* php */
  57.  
  58. public function update($uname,$email,$phone) {
  59. try {
  60. $stmt = $this->conn->prepare('UPDATE tbl_users SET userName = ?, userEmail = ?, phone = ? WHERE userID = ? ');
  61. $stmt->execute(array($uname,$email,$phone,$_SESSION['userSession']));
  62. return $stmt->fetch();
  63. } catch(PDOException $e) {
  64. echo '<p class="bg-danger">'.$e->getMessage().'</p>';
  65. }
  66. }
  67.  
  68. /*php end */
  69.  
  70.  
  71.  
  72. public function login($email,$upass)
  73. {
  74. try
  75. {
  76. $stmt = $this->conn->prepare("SELECT * FROM tbl_users WHERE userEmail=:email_id");
  77. $stmt->execute(array(":email_id"=>$email));
  78. $userRow=$stmt->fetch(PDO::FETCH_ASSOC);
  79.  
  80. if($stmt->rowCount() == 1)
  81. {
  82. if($userRow['userStatus']=="Y")
  83. {
  84. if($userRow['userPass']==md5($upass))
  85. {
  86. $_SESSION['userSession'] = $userRow['userID'];
  87. return true;
  88. }
  89. else
  90. {
  91. header("Location: index.php?error");
  92. exit;
  93. }
  94. }
  95. else
  96. {
  97. header("Location: index.php?inactive");
  98. exit;
  99. }
  100. }
  101. else
  102. {
  103. header("Location: index.php?error");
  104. exit;
  105. }
  106. }
  107. catch(PDOException $ex)
  108. {
  109. echo $ex->getMessage();
  110. }
  111. }
  112.  
  113.  
  114. public function is_logged_in()
  115. {
  116. if(isset($_SESSION['userSession']))
  117. {
  118. return true;
  119. }
  120. }
  121.  
  122. public function redirect($url)
  123. {
  124. header("Location: $url");
  125. }
  126.  
  127. public function logout()
  128. {
  129. session_destroy();
  130. $_SESSION['userSession'] = false;
  131. }
  132.  
  133. function send_mail($email,$message,$subject)
  134. {
  135. require_once('mailer/class.phpmailer.php');
  136. $mail = new PHPMailer();
  137. $mail->IsSMTP();
  138. $mail->SMTPDebug = 0;
  139. $mail->SMTPAuth = true;
  140. $mail->SMTPSecure = "ssl";
  141. $mail->Host = "smtp.gmail.com";
  142. $mail->Port = 465;
  143. $mail->AddAddress($email);
  144. $mail->Username="kidsdial5@gmail.com";
  145. $mail->Password="5dialkids";
  146. $mail->SetFrom('kidsdial5@gmail.com','stylebaby1');
  147. $mail->AddReplyTo("kidsdial5@gmail.com","stylebaby2");
  148. $mail->Subject = $subject;
  149. $mail->MsgHTML($message);
  150. $mail->Send();
  151. }
  152. }
Add Comment
Please, Sign In to add comment