Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class User{
- // $Conn is the database connection handler defined in db.include.php
- protected $Conn;
- // the constructor links $Conn inside the User class to the one outside of class defined in db.include.php
- public function __construct($Conn) {
- $this->Conn = $Conn;
- }
- public function createUser($user_data) {
- // take users set password and convert to hash value using password_hash method
- $sec_password = password_hash($user_data['password'], PASSWORD_DEFAULT);
- // INSERT values into database using :placeholders
- $query = "INSERT INTO users(user_email, user_pass, user_name) VALUES
- (:user_email, :user_pass, :user_name)";
- $stmt = $this->Conn->prepare($query);
- // execute the statement using an array to pass the values
- return $stmt->execute(array(
- 'user_email'=>$user_data['email'],
- 'user_pass'=>$sec_password,
- 'user_name'=>$user_data['fullName']
- // method complete, refer to join.php
- ));
- }
- public function loginUser($email,$password){
- // query database for users email address
- $query = "SELECT * FROM users WHERE user_email = :user_email";
- $stmt = $this->Conn->prepare($query);
- // execute query using user email
- $stmt->execute(array(':user_email'=>$email));
- // fetch the results of query
- $attempt = $stmt->fetch();
- if($attempt && password_verify($password,$attempt['user_pass'])) {
- return $attempt;
- }else{
- return false;
- }
- }
- public function getUser($user_id){
- // gets all user_id
- $query = "SELECT * FROM users WHERE user_id = :user_id";
- $stmt = $this->$Conn->prepare($query);
- $stmt->execute(array(':user_id' => $user_id));
- return $stmt->fetch();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement