Guest User

class.user.php

a guest
Oct 26th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.56 KB | None | 0 0
  1. <?php
  2.  
  3. require_once 'dbconfig.php';
  4.  
  5. $dbConn = new Database();
  6. $dbConn->dbConnection();
  7.  
  8. $user_home = new USER();
  9.  
  10. class USER
  11. {
  12.  
  13. private $conn;
  14.  
  15. public function __construct()
  16. {
  17. $database = new Database();
  18. $db = $database->dbConnection();
  19. $this->conn = $db;
  20. }
  21.  
  22. public function runQuery($sql)
  23. {
  24. $stmt = $this->conn->prepare($sql);
  25. return $stmt;
  26. }
  27.  
  28. public function lasdID()
  29. {
  30. $stmt = $this->conn->lastInsertId();
  31. return $stmt;
  32. }
  33.  
  34. public function register($uname,$email,$upass, $code, $phone, $street_address, $street_address_2 , $city , $state , $zip_code , $country)
  35. {
  36. try
  37. {
  38. $password = md5($upass);
  39. $stmt = $this->conn->prepare("INSERT INTO tbl_users(userName,userEmail,userPass, tokenCode, phone, street_address, street_address_2 , city , state , zip_code , country)
  40. VALUES(:user_name, :user_mail, :user_pass, :active_code, :phone , :street_address, :street_address_2 , :city , :state , :zip_code , :country ");
  41. $stmt->bindparam(":user_name",$uname);
  42. $stmt->bindparam(":user_mail",$email);
  43. $stmt->bindparam(":user_pass",$password);
  44. $stmt->bindparam(":active_code",$code);
  45. $stmt->bindparam(":phone",$phone);
  46. $stmt->bindparam(":street_address",$street_address);
  47. $stmt->bindparam(":street_address_2",$street_address_2);
  48. $stmt->bindparam(":city",$city);
  49. $stmt->bindparam(":state",$state);
  50. $stmt->bindparam(":zip_code",$zip_code);
  51. $stmt->bindparam(":country",$country);
  52. $stmt->execute();
  53. return $stmt;
  54. }
  55. catch(PDOException $ex)
  56. {
  57. echo $ex->getMessage();
  58. }
  59. }
  60.  
  61. /* php */
  62.  
  63. public function update($uname,$email, $phone, $street_address,$street_address_2 , $city , $state , $zip_code , $country ,$sold_by ,
  64. $portfolio , $paypal_email_id, $account_holder_name, $account_number , $branch_name , $bank_name , $ifsc_code , $tax)
  65. {
  66. try {
  67. $stmt = $this->conn->prepare('UPDATE tbl_users SET userName = ?, userEmail = ?, phone = ?, street_address = ? , street_address_2 = ?
  68. , city = ? , state = ? , zip_code = ? , country = ? , sold_by = ? , portfolio = ? , paypal_email_id = ? , account_holder_name = ? ,
  69. account_number = ?, branch_name = ? , bank_name =? , ifsc_code =?, tax =? WHERE userID = ? ');
  70. $stmt->execute(array($uname,$email, $phone, $street_address, $street_address_2 , $city , $state , $zip_code , $country, $sold_by,
  71. $portfolio , $paypal_email_id, $account_holder_name, $account_number , $branch_name , $bank_name , $ifsc_code , $tax , $_SESSION['userSession']));
  72. return $stmt->fetch();
  73. } catch(PDOException $e) {
  74. echo '<p class="bg-danger">'.$e->getMessage().'</p>';
  75. }
  76. }
  77.  
  78. /*php end.... */
  79.  
  80.  
  81.  
  82. //$dbConn = new Database();
  83. //$dbConn->dbConnection();
  84.  
  85. //$user_home = new USER();
  86.  
  87. public function uploadUserPhoto($uid) {
  88. if(isset($_FILES["photo"]["error"])) {
  89. if($_FILES["photo"]["error"] > 0) {
  90. echo "Error: " . $_FILES["photo"]["error"] . "<br>";
  91.  
  92. } else {
  93. $allowed = array("jpg" => "image/jpg", "jpeg" => "image/jpeg", "gif" => "image/gif", "png" => "image/png");
  94. $filename = $_FILES["photo"]["name"];
  95. $filetype = $_FILES["photo"]["type"];
  96. $filesize = $_FILES["photo"]["size"];
  97.  
  98. $userDir = $uid;
  99.  
  100. // Verify file extension
  101. $ext = pathinfo($filename, PATHINFO_EXTENSION);
  102. if(!array_key_exists($ext, $allowed)) die("Error: Please select a valid file format.");
  103.  
  104. // Verify file size - 5MB maximum
  105. $maxsize = 5 * 1024 * 1024;
  106. if($filesize > $maxsize) die("Error: File size is larger than the allowed limit.");
  107.  
  108. // Verify MYME type of the file
  109. if(in_array($filetype, $allowed)) {
  110. if(!is_dir('upload/'.$uid)) {
  111. mkdir('upload/'.$uid);
  112. }
  113.  
  114. $photoname = time().$uid.'_photo'.'.'.$ext;
  115.  
  116. // delete all the files in this directory
  117. $files = glob('upload/'.$uid.'/*'); // get all file names
  118. foreach($files as $file){ // iterate files
  119. if(is_file($file))
  120. unlink($file); // delete file
  121. }
  122.  
  123. // Upload the photo
  124. move_uploaded_file($_FILES["photo"]["tmp_name"], "upload/" . $uid . '/'. $photoname);
  125.  
  126. $updateData = array(':userID' => $uid, ':photo' => $photoname);
  127. $stmt = $this->conn->prepare("UPDATE tbl_users SET photo=:photo WHERE userID=:uid");
  128. $stmt->execute($updateData);
  129.  
  130. echo "Your file was uploaded successfully.";
  131. } else {
  132. echo "Error: There was a problem uploading your file - please try again.";
  133. }
  134. }
  135. } else {
  136. echo "";
  137. }
  138. }
  139.  
  140.  
  141.  
  142. public function login($email,$upass)
  143. {
  144. try
  145. {
  146. $stmt = $this->conn->prepare("SELECT * FROM tbl_users WHERE userEmail=:email_id");
  147. $stmt->execute(array(":email_id"=>$email));
  148. $userRow=$stmt->fetch(PDO::FETCH_ASSOC);
  149.  
  150. if($stmt->rowCount() == 1)
  151. {
  152. if($userRow['userStatus']=="Y")
  153. {
  154. if($userRow['userPass']==md5($upass))
  155. {
  156. $_SESSION['userSession'] = $userRow['userID'];
  157. return true;
  158. }
  159. else
  160. {
  161. header("Location: index.php?error");
  162. exit;
  163. }
  164. }
  165. else
  166. {
  167. header("Location: index.php?inactive");
  168. exit;
  169. }
  170. }
  171. else
  172. {
  173. header("Location: index.php?error");
  174. exit;
  175. }
  176. }
  177. catch(PDOException $ex)
  178. {
  179. echo $ex->getMessage();
  180. }
  181. }
  182.  
  183.  
  184. public function is_logged_in()
  185. {
  186. if(isset($_SESSION['userSession']))
  187. {
  188. return true;
  189. }
  190. }
  191.  
  192. public function redirect($url)
  193. {
  194. header("Location: $url");
  195. }
  196.  
  197. public function logout()
  198. {
  199. session_destroy();
  200. $_SESSION['userSession'] = false;
  201. }
  202.  
  203. function send_mail($email,$message,$subject)
  204. {
  205. require_once('mailer/class.phpmailer.php');
  206. $mail = new PHPMailer();
  207. $mail->IsSMTP();
  208. $mail->SMTPDebug = 0;
  209. $mail->SMTPAuth = true;
  210. $mail->SMTPSecure = "ssl";
  211. $mail->Host = "smtp.gmail.com";
  212. $mail->Port = 465;
  213. $mail->AddAddress($email);
  214. $mail->Username="kidsdial5@gmail.com";
  215. $mail->Password="5dialkids";
  216. $mail->SetFrom('kidsdial5@gmail.com','stylebaby1');
  217. $mail->AddReplyTo("kidsdial5@gmail.com","stylebaby2");
  218. $mail->Subject = $subject;
  219. $mail->MsgHTML($message);
  220. $mail->Send();
  221. }
  222. }
Add Comment
Please, Sign In to add comment