tlmarker1968

Untitled

Feb 2nd, 2020
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.55 KB | None | 0 0
  1. <?php
  2.     /**
  3.      * Phoenix Hospitality Management System
  4.      * Phoenix REST API - API Security Repository file
  5.      * Written in PHP using the Slim microframework
  6.      *
  7.      * @author Troy L. Marker
  8.      * @version 0.5.0
  9.      * @since 0.5.0
  10.      * @copyright Copyright (c) 2020 By Troy Marker Enterprises
  11.      *
  12.      * Declare namespace and Import needed functions/classes
  13.      */
  14.     namespace App\Domain\Repository;
  15.  
  16.     use App\Domain\Data\User as DatabaseUser;
  17.     use App\Domain\Data\LoggingUser as LoggingUser;
  18.     use App\Domain\Service\Grade as ServiceGrades;
  19.     use App\Domain\Repository\Grade as RepositoryGrade;
  20.     use PDO;
  21.    
  22.     /**
  23.      * This class provides needed security functions to the system
  24.      */
  25.     class Security {
  26.      
  27.         private $connection;
  28.  
  29.         /**
  30.          * Class constructor
  31.          *
  32.          * @param PDO $connection - The database connection
  33.          */
  34.         public function __construct(PDO $connection) {
  35.             $this->connection = $connection;
  36.         }
  37.        
  38.         /**
  39.          * This method logs a user onto the system
  40.          *
  41.          * @param string $username - the user  who want to login
  42.          * @param string $password - the users password
  43.          *
  44.          * $return array - information about the user logging in
  45.          */
  46.         public function login(LoggingUser $loggingUser): array {
  47.  
  48.             $repoGrade = new RepositoryGrade($this->connection);
  49.             $row['username'] = $loggingUser->username;
  50.             $sql = "SELECT * FROM users WHERE username=:username";
  51.             $stmt = $this->connection->prepare($sql);
  52.             $stmt->execute($row);
  53.             $return = $stmt->fetchAll(PDO::FETCH_ASSOC);
  54.             if(password_verify($loggingUser->password, $return[0]['password'])) {
  55.                 $return_value['username'] = $return[0]['username'];
  56.                 $return_value['grade'] = $return[0]['grade'];
  57.                 $return_value['grade_text'] = $this->getGrade($return[0]['grade']);
  58.                 $return_value['department'] = $return[0]['department'];
  59.             } else {
  60.                 $return_value['message'] = 'User not authorized';
  61.             }
  62.             return $return_value;
  63.         }
  64.  
  65.         public function getGrade(int $id) {
  66.             $sql = "SELECT grade FROM grades WHERE id=:id";
  67.             $stmt = $this->connection->prepare($sql);
  68.             $stmt->execute(['id'=>$id]);
  69.             $grade = $stmt->fetch();
  70.             var_dump($grade);
  71.             return $grade;
  72.         }
  73.     }
Advertisement
Add Comment
Please, Sign In to add comment