51 lines
1.6 KiB
PHP
51 lines
1.6 KiB
PHP
<?php
|
|
include "connectionDB.php";
|
|
|
|
$message="";
|
|
if($_SERVER["REQUEST_METHOD"] === "POST") {
|
|
if(isset($_POST["username"]) && $_POST["password"]) {
|
|
try {
|
|
$get_user->execute(array($_POST["username"], $_POST["password"]));
|
|
$result = $get_user->fetch();
|
|
if($result) {
|
|
setcookie("user",crypt($_POST["password"],$_POST["username"]));
|
|
setcookie("userID",$result["id"]);
|
|
header("Location: /index.php");
|
|
}
|
|
else {
|
|
$add_user->execute(array($_POST["username"], $_POST["password"]));
|
|
}
|
|
} catch(Exception $e) {
|
|
|
|
if($e->getCode() == 23505) {
|
|
$message = "User alredy exists";
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
$message = "Something missing!";
|
|
}
|
|
}
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>TinyTalkHub</title>
|
|
<link rel="stylesheet" href="css/global.css">
|
|
<link rel="icon" type="image/x-icon" href="/favicon-32x32.png">
|
|
</head>
|
|
<body>
|
|
<form action="/auth.php" method="POST" class="form-auth-wrap">
|
|
<label>User login: </label>
|
|
<input name="username" placeholder="Type here..." /> <br/>
|
|
<label>User Password: </label>
|
|
<input name="password"placeholder="Type here..." /> </br>
|
|
<button>Submit</button>
|
|
|
|
<p> <?php echo $message; ?></p>
|
|
</form>
|
|
</body>
|
|
</html>
|