v0.0.1 Added the first files and made a login system.
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
session_start();
|
||||
if (!isset($_SESSION['token'])) {
|
||||
header("location: ../Frontend/index.php?login=notloggedin");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
require_once "../../bootstrap.php";
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
session_start();
|
||||
if (isset($_POST['loginsubmit'])) {
|
||||
$username = $_POST["username"];
|
||||
$password = $_POST["password"];
|
||||
$user = User::query()->firstWhere('name', $username);
|
||||
if ($user) {
|
||||
$hashedPassword = $user->password;
|
||||
if (password_verify($password, $hashedPassword)) {
|
||||
$token = Str::random(100);
|
||||
$password = User::firstWhere('id', '=', $user->id);
|
||||
$password->remember_token = $token;
|
||||
if ($password->save()) {
|
||||
$_SESSION['token'] = $token;
|
||||
$_SESSION['name'] = $username;
|
||||
header('location: ../../Frontend/home.php?login=success');
|
||||
exit();
|
||||
http_response_code(200);
|
||||
} else {
|
||||
session_destroy();
|
||||
http_response_code(500);
|
||||
}
|
||||
|
||||
} else {
|
||||
session_destroy();
|
||||
http_response_code(401);
|
||||
echo json_encode(["message" => "Wrong password"]);
|
||||
}
|
||||
|
||||
} else {
|
||||
session_destroy();
|
||||
http_response_code(401);
|
||||
echo json_encode(["message" => "User was not found"]);
|
||||
}
|
||||
} else {
|
||||
http_response_code(400);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
session_start();
|
||||
session_unset();
|
||||
session_destroy();
|
||||
header("location: ../../Frontend/index.php");
|
||||
Reference in New Issue
Block a user