-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
72 lines (69 loc) · 2.64 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<!DOCTYPE html>
<?php
include('firebase.php');
include_once('includes.php');
$firebase = new \Firebase\FirebaseLib(DEFAULT_URL, DEFAULT_TOKEN);
session_start();
if(isset($_POST["logout"])){
$_SESSION["user"] = "invalid";
}
?>
<html>
<head>
<link href="general.css" rel="stylesheet">
</head>
<body>
<?php
include('navbar.php');
?>
<div class='content'>
<form action="index.php" method="post">
<h1 class="full-width">Register</h1>
Username: <input type="text" name="username" required/>
Display Name: <input type="text" name="displayName"/>
Password: <input type="password" name="password"/>
<input type="submit" name="submitReg"/>
</form>
<form action="index.php" method="post">
<h1 class="full-width">Login</h1>
Username: <input type="text" name="logusername"/>
Password: <input type="password" name="logpassword"/>
<input type="submit" name="submitLog"/>
</form>
<?php
function showAlert($content, $type = "info"){
echo "<h5 class=\"alert alert-$type alert-dismissible fade show\" role=\"alert\">$content<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button></h5>";
}
if(isset($_POST["submitReg"])) {
$username = stripper($_POST["username"]);
$displayName = stripper($_POST["displayName"]);
$password = stripper($_POST["password"]);
if(!userExist($firebase, $username)) {
$result = createAccount($username, $password, $displayName, $firebase);
if(!empty($result)){
echo showAlert("Account Creation Successsful", "sucess");
}else {
echo showAlert("Account Creation Failure", "danger");
}
}else {
echo showAlert("Username Already Taken", "danger");
}
}
if(isset($_POST["submitLog"])) {
$username = stripper($_POST["logusername"]);
$password = stripper($_POST["logpassword"]);
if(!userExist($firebase, $username)) {
echo showAlert("Login Failed: Username doesn't exist", "warning");
}else {
if(verifyPassword($firebase, $username, $password)) {
$_SESSION["user"] = $username;
header("Location: home.php");
}else {
echo showAlert("Login Failed: Incorrect Password", "warning");
}
}
}
?>
</div>
<body>
<html>