Guest User

class

a guest
Oct 16th, 2016
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 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->_db->prepare('UPDATE tbl_users SET userName = ?, userEmail = ?, phone = ? WHERE userID = ? ');
  61. // $stmt = $this->db->prepare('UPDATE tbl_users SET userName = ?, userEmail = ?, phone = ? WHERE userID = ? ');
  62. $stmt = $this->conn->prepare('UPDATE tbl_users SET userName = ?, userEmail = ?, phone = ? WHERE userID = ? ');
  63. $stmt->execute(array($uname,$email,$phone,$_SESSION['userID']));
  64. return $stmt->fetch();
  65. } catch(PDOException $e) {
  66. echo '<p class="bg-danger">'.$e->getMessage().'</p>';
  67. }
  68. }
  69.  
  70. /*php end */
  71.  
  72.  
  73.  
  74. public function login($email,$upass)
  75. {
  76. try
  77. {
  78. $stmt = $this->conn->prepare("SELECT * FROM tbl_users WHERE userEmail=:email_id");
  79. $stmt->execute(array(":email_id"=>$email));
  80. $userRow=$stmt->fetch(PDO::FETCH_ASSOC);
  81.  
  82. if($stmt->rowCount() == 1)
  83. {
  84. if($userRow['userStatus']=="Y")
  85. {
  86. if($userRow['userPass']==md5($upass))
  87. {
  88. $_SESSION['userSession'] = $userRow['userID'];
  89. return true;
  90. }
  91. else
  92. {
  93. header("Location: index.php?error");
  94. exit;
  95. }
  96. }
  97. else
  98. {
  99. header("Location: index.php?inactive");
  100. exit;
  101. }
  102. }
  103. else
  104. {
  105. header("Location: index.php?error");
  106. exit;
  107. }
  108. }
  109. catch(PDOException $ex)
  110. {
  111. echo $ex->getMessage();
  112. }
  113. }
  114.  
  115.  
  116. public function is_logged_in()
  117. {
  118. if(isset($_SESSION['userSession']))
  119. {
  120. return true;
  121. }
  122. }
  123.  
  124. public function redirect($url)
  125. {
  126. header("Location: $url");
  127. }
  128.  
  129. public function logout()
  130. {
  131. session_destroy();
  132. $_SESSION['userSession'] = false;
  133. }
  134.  
  135. function send_mail($email,$message,$subject)
  136. {
  137. require_once('mailer/class.phpmailer.php');
  138. $mail = new PHPMailer();
  139. $mail->IsSMTP();
  140. $mail->SMTPDebug = 0;
  141. $mail->SMTPAuth = true;
  142. $mail->SMTPSecure = "ssl";
  143. $mail->Host = "smtp.gmail.com";
  144. $mail->Port = 465;
  145. $mail->AddAddress($email);
  146. $mail->Username="kidsdial5@gmail.com";
  147. $mail->Password="5dialkids";
  148. $mail->SetFrom('kidsdial5@gmail.com','stylebaby1');
  149. $mail->AddReplyTo("kidsdial5@gmail.com","stylebaby2");
  150. $mail->Subject = $subject;
  151. $mail->MsgHTML($message);
  152. $mail->Send();
  153. }
  154. }
Add Comment
Please, Sign In to add comment