Guest User

class.usr.php

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