Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once 'dbconfig.php';
- const PATH_PHOTOS = '/var/www/html/sbdev2/php/site3/upload/';
- global $_FILES;
- class USER
- {
- private $conn;
- public function __construct()
- {
- $database = new Database();
- $db = $database->dbConnection();
- $this->conn = $db;
- }
- public function runQuery($sql)
- {
- $stmt = $this->conn->prepare($sql);
- return $stmt;
- }
- public function lasdID()
- {
- $stmt = $this->conn->lastInsertId();
- return $stmt;
- }
- public function register($uname, $email, $upass, $code, $phone, $street_address, $street_address_2, $city, $state, $zip_code, $country , $portfolio)
- {
- try {
- // $password = md5($upass);
- $password = $_POST["upass"];
- // $hash = password_hash($upass, PASSWORD_DEFAULT);
- $password = password_hash('upass', PASSWORD_DEFAULT);
- $stmt = $this->conn->prepare("INSERT INTO tbl_users(userName,userEmail,userPass, tokenCode, phone, street_address, street_address_2 , city , state , zip_code , country , portfolio)
- VALUES(:user_name, :user_mail, :user_pass, :active_code, :phone , :street_address, :street_address_2 , :city , :state , :zip_code , :country, :portfolio) ;");
- $stmt->execute(array(
- ":user_name" => $uname,
- ":user_mail" => $email,
- ":user_pass" => $password,
- ":active_code" => $code,
- ":phone" => $phone,
- ":street_address" => $street_address,
- ":street_address_2" => $street_address_2,
- ":city" => $city,
- ":state" => $state,
- ":zip_code" => $zip_code,
- ":country" => $country,
- ":portfolio" => $portfolio
- ));
- return $stmt;
- } catch (PDOException $ex) {
- echo $ex->getMessage();
- }
- }
- /* php */
- public function update($uname, $email, $phone, $street_address, $street_address_2, $city, $state, $zip_code, $country, $sold_by,
- $portfolio, $paypal_email_id, $account_holder_name, $account_number, $branch_name, $bank_name, $ifsc_code)
- {
- try {
- $stmt = $this->conn->prepare('UPDATE tbl_users SET userName = ?, userEmail = ?, phone = ?, street_address = ? , street_address_2 = ?
- , city = ? , state = ? , zip_code = ? , country = ? , sold_by = ? , portfolio = ? , paypal_email_id = ? , account_holder_name = ? ,
- account_number = ?, branch_name = ? , bank_name =? , ifsc_code =? WHERE userID = ? ');
- return $stmt->execute(array($uname, $email, $phone, $street_address, $street_address_2, $city, $state, $zip_code, $country, $sold_by,
- $portfolio, $paypal_email_id, $account_holder_name, $account_number, $branch_name, $bank_name, $ifsc_code, $_SESSION['userSession']));
- } catch (PDOException $e) {
- echo '<p class="bg-danger">' . $e->getMessage() . '</p>';
- }
- }
- /*php end */
- const PATH_PHOTOS = '/var/www/html/sbdev2/php/site3/upload/';
- const BASE_URL = 'http://sbdev2.kidsdial.com:81/php/site3/';
- public function add_photo($file)
- {
- $ext = pathinfo($file['name'], PATHINFO_EXTENSION);
- $file['new_name'] = uniqid(rand(), true) . ".$ext";
- if (!$this->_upload_file($file))
- return false;
- return $this->_remove_previous_photo()->_add_file_to_db(self::PATH_PHOTOS . basename($file['new_name']));
- }
- protected function _remove_previous_photo()
- {
- $photo = $this->get_photo();
- if ($photo)
- unlink($photo);
- return $this;
- }
- public function get_photo()
- {
- global $_SESSION;
- $stmt = $this->conn->prepare('SELECT photo FROM tbl_users WHERE userID = ? ');
- $stmt->execute(array($_SESSION['userSession']));
- $result = $stmt->fetch();
- return reset($result);
- }
- public function get_photo_url()
- {
- $pathInfo = pathinfo($this->get_photo());
- $last_dir = end(explode(DIRECTORY_SEPARATOR, $pathInfo['dirname']));
- return self::BASE_URL . "$last_dir/" . basename($this->get_photo());
- }
- protected function _upload_file($file)
- {
- $uploadfile = self::PATH_PHOTOS . $file['new_name'];
- return move_uploaded_file($file['tmp_name'], $uploadfile);
- }
- protected function _add_file_to_db($file_path)
- {
- try {
- $stmt = $this->conn->prepare('UPDATE tbl_users SET photo = ? WHERE userID = ? ');
- return $stmt->execute(array($file_path, $_SESSION['userSession']));
- } catch (PDOException $e) {
- echo '<p class="bg-danger">' . $e->getMessage() . '</p>';
- }
- }
- public function login($email, $upass)
- {
- try {
- $stmt = $this->conn->prepare("SELECT * FROM tbl_users WHERE userEmail=:email_id");
- $stmt->execute(array(":email_id" => $email));
- $userRow = $stmt->fetch(PDO::FETCH_ASSOC);
- $password = password_hash('upass', PASSWORD_DEFAULT);
- if ($stmt->rowCount() == 1) {
- if ($userRow['userStatus'] == "Y") {
- // if ($userRow['userPass'] == md5($upass)) {
- if ($userRow['userPass'] == $_POST["upass"])
- {
- $_SESSION['userSession'] = $userRow['userID'];
- return true;
- } else {
- header("Location: index.php?error");
- exit;
- }
- } else {
- header("Location: index.php?inactive");
- exit;
- }
- } else {
- header("Location: index.php?error");
- exit;
- }
- } catch (PDOException $ex) {
- echo $ex->getMessage();
- }
- }
- public function checkCredentials($email, $upass)
- {
- $user = $this->getUserByUsername($email);
- if (!$email) {
- // No user found with provided username
- return false;
- }
- if (!password_verify($password, $email['password'])) {
- // Password does not match
- return false;
- }
- if (password_needs_rehash($email['password'], PASSWORD_DEFAULT)) {
- // This password was hashed using an older algorithm, update with new hash.
- $this->updatePassword($email['id'], $password);
- }
- // The password is no longer needed from the user data
- unset($email['password']);
- return $email;
- }
- public function is_logged_in()
- {
- if (isset($_SESSION['userSession'])) {
- return true;
- }
- }
- public function redirect($url)
- {
- header("Location: $url");
- }
- public function logout()
- {
- session_destroy();
- $_SESSION['userSession'] = false;
- }
- function send_mail($email, $message, $subject)
- {
- require_once('mailer/class.phpmailer.php');
- $mail = new PHPMailer();
- $mail->IsSMTP();
- $mail->SMTPDebug = 0;
- $mail->SMTPAuth = true;
- $mail->SMTPSecure = "ssl";
- $mail->Host = "smtp.gmail.com";
- $mail->Port = 465;
- $mail->AddAddress($email);
- $mail->Username = "kidsdial5@gmail.com";
- $mail->Password = "5dialkids";
- $mail->SetFrom('kidsdial5@gmail.com', 'stylebaby1');
- $mail->AddReplyTo("kidsdial5@gmail.com", "stylebaby2");
- $mail->Subject = $subject;
- $mail->MsgHTML($message);
- $mail->Send();
- }
- }
Add Comment
Please, Sign In to add comment