Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Phoenix Hospitality Management System
- * Phoenix REST API - API Security Repository file
- * Written in PHP using the Slim microframework
- *
- * @author Troy L. Marker
- * @version 0.5.0
- * @since 0.5.0
- * @copyright Copyright (c) 2020 By Troy Marker Enterprises
- *
- * Declare namespace and Import needed functions/classes
- */
- namespace App\Domain\Repository;
- use App\Domain\Data\User as DatabaseUser;
- use App\Domain\Data\LoggingUser as LoggingUser;
- use App\Domain\Service\Grade as ServiceGrades;
- use App\Domain\Repository\Grade as RepositoryGrade;
- use PDO;
- /**
- * This class provides needed security functions to the system
- */
- class Security {
- private $connection;
- /**
- * Class constructor
- *
- * @param PDO $connection - The database connection
- */
- public function __construct(PDO $connection) {
- $this->connection = $connection;
- }
- /**
- * This method logs a user onto the system
- *
- * @param string $username - the user who want to login
- * @param string $password - the users password
- *
- * $return array - information about the user logging in
- */
- public function login(LoggingUser $loggingUser): array {
- $repoGrade = new RepositoryGrade($this->connection);
- $row['username'] = $loggingUser->username;
- $sql = "SELECT * FROM users WHERE username=:username";
- $stmt = $this->connection->prepare($sql);
- $stmt->execute($row);
- $return = $stmt->fetchAll(PDO::FETCH_ASSOC);
- if(password_verify($loggingUser->password, $return[0]['password'])) {
- $return_value['username'] = $return[0]['username'];
- $return_value['grade'] = $return[0]['grade'];
- $return_value['grade_text'] = $this->getGrade($return[0]['grade']);
- $return_value['department'] = $return[0]['department'];
- } else {
- $return_value['message'] = 'User not authorized';
- }
- return $return_value;
- }
- public function getGrade(int $id) {
- $sql = "SELECT grade FROM grades WHERE id=:id";
- $stmt = $this->connection->prepare($sql);
- $stmt->execute(['id'=>$id]);
- $grade = $stmt->fetch();
- var_dump($grade);
- return $grade;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment