Merge branch 'development' of goeranh/fitness-api into master
This commit is contained in:
commit
b6b791d53a
25
html/api/login.php
Normal file
25
html/api/login.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
include "../../config.php";
|
||||||
|
|
||||||
|
if (isset($_POST['username']) and isset($_POST['password'])){
|
||||||
|
$sql = "SELECT * FROM users WHERE username=?";
|
||||||
|
$stmt = $pdo->prepare($sql);
|
||||||
|
$stmt->bindParam(1, $_POST['username']);
|
||||||
|
if ($stmt->execute()){
|
||||||
|
if ($stmt->rowCount()==1){
|
||||||
|
$user = $stmt->fetchAll(PDO::FETCH_ASSOC)[0];
|
||||||
|
if (password_verify($_POST['password'], $user['password'])){
|
||||||
|
$sql = "SELECT token FROM tokens WHERE user=?";
|
||||||
|
$stmt = $pdo->prepare($sql);
|
||||||
|
$stmt->bindParam(1, $user['id']);
|
||||||
|
if ($stmt->execute()){
|
||||||
|
if ($stmt->rowCount()>0){
|
||||||
|
echo $stmt->fetchAll(PDO::FETCH_ASSOC)[0]['token'];
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
var_dump($stmt->errorInfo());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user