-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
128 lines (116 loc) · 5.01 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
session_start();
include "./library/autoload.php";
$login_error = "";
$signup_error = "";
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
if ($_POST["action"] == "signup")
{
$signup = new Signup();
$signup->set_name($_POST["name"]);
$signup->set_email($_POST["email"]);
$signup->set_password($_POST["password"]);
$signup->set_confirm_password($_POST["confirm_password"]);
if (!$signup->signup())
$signup_error = $signup->get_error();
else
login($signup->get_username(), $signup->get_name());
}
else if ($_POST["action"] == "login")
{
$login = new Login();
$login->set_email($_POST["email"]);
$login->set_password($_POST["password"]);
if (!$login->login())
$login_error = $login->get_error ();
else
login($login->get_username(), $login->get_name());
}
}
function login($username, $name)
{
$_SESSION["username"] = $username;
$_SESSION["name"] = $name;
session_write_close();
header("Location: ./dashboard.php");
exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Slate</title>
<link rel="stylesheet" href="./css/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="./css/stylesheet_1.css">
<script src="./js/jquery.js"></script>
<script src="./css/dist/js/bootstrap.min.js"></script>
</head>
<body>
<!--
Header containing site's name and
login block.
-->
<header class="container page-header">
<div class="pull-left">
<h1>Slate</h1>
</div>
<!-- Login form -->
<div class="pull-right col-sm-6">
<div class="form-group">
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>"
method="post" role="form" class="form-inline">
<span class="text-danger"><?php echo $login_error; ?></span>
<br />
<input type="email" name="email" required="required"
placeholder="Your email" class="form-control"/>
<input type="password" name="password" required="required"
placeholder="Your password" class="form-control" />
<input type="hidden" name="action" value="login" />
<button type="submit" class="btn btn-success">Login</button>
</form>
</div>
</div>
<div class="clearfix"></div>
</header>
<main class="container">
<div class="jumbotron custom-jumbotron">
<div class="pull-left col-sm-4">
<h2>Express yourself</h2>
<p>
Share your views by writing posts. Express
yourself through images. Discuss and clarify your doubts.
</p>
</div>
<!-- Signup form -->
<div class="pull-right col-sm-4">
<div class="form-group">
<h3>
<span class="text-center text-info">
Signup for Slate
</span>
</h3>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>"
method="post" role="form">
<span class="text-danger"><?php echo $signup_error?></span>
<input type="hidden" name="action" value="signup" />
<input type="text" name="name" required="required"
placeholder="Your full name" class="form-control"/><br />
<input type="email" name="email" required="required"
placeholder="Your email" class="form-control"/><br />
<input type="password" name="password" required="required"
placeholder="Password" class="form-control"/><br />
<input type="password" name="confirm_password" required="required"
placeholder="Confirm password" class="form-control"/><br />
<input type="submit" class="btn btn-success" value="Signup" />
</form>
</div>
</div>
<div class="clearfix"></div>
</div>
</main>
<?php include "footer.php"; ?>
</body>
</html>