Guest User

Untitled

a guest
Feb 8th, 2018
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 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)
  30. {
  31. try
  32. {
  33. $password = md5($upass);
  34. $stmt = $this->conn->prepare("INSERT INTO tbl_users(userName,userEmail,userPass,tokenCode)
  35. VALUES(:user_name, :user_mail, :user_pass, :active_code)");
  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->execute();
  41. return $stmt;
  42. }
  43. catch(PDOException $ex)
  44. {
  45. echo $ex->getMessage();
  46. }
  47. }
  48.  
  49. public function login($email,$upass)
  50. {
  51. try
  52. {
  53. $stmt = $this->conn->prepare("SELECT * FROM tbl_users WHERE userEmail=:email_id");
  54. $stmt->execute(array(":email_id"=>$email));
  55. $userRow=$stmt->fetch(PDO::FETCH_ASSOC);
  56.  
  57. if($stmt->rowCount() == 1)
  58. {
  59. if($userRow['userStatus']=="Y")
  60. {
  61. if($userRow['userPass']==md5($upass))
  62. {
  63. $_SESSION['userSession'] = $userRow['userID'];
  64. return true;
  65. }
  66. else
  67. {
  68. header("Location: index.php?error");
  69. exit;
  70. }
  71. }
  72. else
  73. {
  74. header("Location: index.php?inactive");
  75. exit;
  76. }
  77. }
  78. else
  79. {
  80. header("Location: index.php?error");
  81. exit;
  82. }
  83. }
  84. catch(PDOException $ex)
  85. {
  86. echo $ex->getMessage();
  87. }
  88. }
  89.  
  90.  
  91. public function is_logged_in()
  92. {
  93. if(isset($_SESSION['userSession']))
  94. {
  95. return true;
  96. }
  97. }
  98.  
  99. public function redirect($url)
  100. {
  101. header("Location: $url");
  102. }
  103.  
  104. public function logout()
  105. {
  106. session_destroy();
  107. $_SESSION['userSession'] = false;
  108. }
  109.  
  110. function send_mail($email,$message,$subject)
  111. {
  112. require_once('mailer/class.phpmailer.php');
  113. $mail = new PHPMailer();
  114. $mail->IsSMTP();
  115. $mail->SMTPDebug = 0;
  116. $mail->SMTPAuth = true;
  117. $mail->SMTPSecure = "ssl";
  118. $mail->Host = "smtp.gmail.com";
  119. $mail->Port = 465;
  120. $mail->AddAddress($email);
  121. $mail->Username="yourgmailid@gmail.com";
  122. $mail->Password="yourgmailpassword";
  123. $mail->SetFrom('you@yourdomain.com','Coding Cage');
  124. $mail->AddReplyTo("you@yourdomain.com","Coding Cage");
  125. $mail->Subject = $subject;
  126. $mail->MsgHTML($message);
  127. $mail->Send();
  128. }
  129. }
Add Comment
Please, Sign In to add comment