Initial commit
This commit is contained in:
47
app/Models/Auth.php
Normal file
47
app/Models/Auth.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
class Auth {
|
||||
|
||||
private $connection;
|
||||
// private $bearer_token;
|
||||
|
||||
public function __construct($db) {
|
||||
$this->connection = $db;
|
||||
}
|
||||
|
||||
|
||||
public function read_api_auth(){
|
||||
// $bearer = $this->bearer_token;
|
||||
|
||||
if(!function_exists('getallheaders')){
|
||||
return false;
|
||||
}
|
||||
$headers = [];
|
||||
foreach (getallheaders() as $name => $value) {
|
||||
// echo "$name: $value <br>" . PHP_EOL;
|
||||
$headers[$name] = $value;
|
||||
}
|
||||
$check = array_key_exists('Authorization', $headers);
|
||||
if ($check == false) {
|
||||
return false;
|
||||
}
|
||||
list($type, $bearer_token) = explode(" ", $headers['Authorization'], 2);
|
||||
|
||||
$query = 'SELECT id, name FROM auth_users WHERE bearer_token = ? LIMIT 0,1';
|
||||
$statement = $this->connection->prepare($query);
|
||||
|
||||
$statement->bindParam(1, $bearer_token);
|
||||
$statement->execute();
|
||||
|
||||
$row = $statement->fetch(PDO::FETCH_ASSOC);
|
||||
if ($row == false) {
|
||||
return false;
|
||||
}
|
||||
else{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user