This commit is contained in:
+12
-10
@@ -1,12 +1,12 @@
|
||||
<?php
|
||||
|
||||
if (isset($_POST['form_id'])) {
|
||||
require_once '../vendor/autoload.php';
|
||||
include_once '../vendor/autoload.php';
|
||||
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/../');
|
||||
$dotenv->safeLoad();
|
||||
|
||||
require_once 'base.php';
|
||||
require_once 'db.php';
|
||||
include_once 'base.php';
|
||||
include_once 'db.php';
|
||||
|
||||
switch ($_POST['form_id']) {
|
||||
case 'create-account':
|
||||
@@ -15,6 +15,9 @@ if (isset($_POST['form_id'])) {
|
||||
echo json_encode($result);
|
||||
}
|
||||
break;
|
||||
case 'login':
|
||||
if (isset($_POST['username']) && isset($_POST['password']))
|
||||
echo json_encode(login($_POST['username'], $_POST['password']));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,29 +33,28 @@ function username_exists($username)
|
||||
|
||||
function login($username, $password)
|
||||
{
|
||||
$user = exec_stmt('SELECT id FROM user WHERE username = ? AND password = ?', 'ss', $username, $password)->fetch_assoc();
|
||||
$user = exec_stmt('SELECT id, password FROM user WHERE username = ?', 's', $username)->fetch_assoc();
|
||||
|
||||
if (!isset($user['id']))
|
||||
return false;
|
||||
|
||||
if (!password_verify($password, $user['password'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$_SESSION['id'] = $user['id'];
|
||||
return true;
|
||||
}
|
||||
|
||||
function signup($username, $password, $verify_password)
|
||||
{
|
||||
echo 'test';
|
||||
if (username_exists($username))
|
||||
return false;
|
||||
|
||||
echo 'username=' . $username;
|
||||
|
||||
if ($password != $verify_password)
|
||||
return false;
|
||||
|
||||
$user_id = exec_stmt('INSERT INTO user (username, password) VALUES (?, ?)', 'ss', $username, $password);
|
||||
|
||||
echo 'user_id=' . $user_id;
|
||||
$user_id = exec_stmt('INSERT INTO user (username, password) VALUES (?, ?)', 'ss', $username, password_hash($password, PASSWORD_DEFAULT));
|
||||
|
||||
if (!isset($user_id))
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user