forked from pinico42/revi.se
-
Notifications
You must be signed in to change notification settings - Fork 0
/
signup.php
143 lines (123 loc) · 3.33 KB
/
signup.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
// Copyright © 2014 Max Penrose
?>
<?php
include 'private/pwds.php';
function startsWith($haystack, $needle)
{
return $needle === "" || strpos($haystack, $needle) === 0;
}
function writeJson($json, $file){
$data = json_encode($json, true);
$f = fopen($file, "w");
fwrite($f, $data);
fclose($f);
}
function readJson($file){
$f = fopen($file, "r");
$data = fread($f, filesize($file));
fclose($f);
$json = json_decode($data, true);
return $json;
}
function writeSubjects($subs, $email){
$json = readJson('private/subjects.json');
$subsJson = array();
foreach($subs as $k => $v){
$subsJson = array_merge($subsJson,array(["Name"=>$k, "Board"=>$v]));
}
$json[$email] = $subsJson;
writeJson($json, 'private/subjects.json');
}
function writeAbilities($email){
$json = readJson('private/abilities.json');
$json[$email] = [];
writeJson($json, 'private/abilities.json');
}
function writeTopics($email, $subs){
$json = readJson('private/topics.json');
$json[$email] = [];
foreach($subs as $k => $v){
$json[$email][$k] = [];
}
writeJson($json, 'private/topics.json');
}
if(isset($_POST['pwd'])){
$success = true;
$subs = array();
foreach($_POST as $postK => $postV){
if($postK == 'email'){
$email = $postV;
} else
if($postK == 'fname'){
$fname = $postV;
} else
if($postK == 'sname'){
$sname = $postV;
} else
if($postK == 'pwd'){
if($_POST['cfpwd'] == $postV){
$pwd = sha1($postV);
} else {
$success = false;
}
}else
if(startsWith($postK,'s')){
$num = substr($postK, 1);
$subs[$postV] = $_POST["b".$num];
}
}
if($success){
writeAbilities($email);
writeTopics($email, $subs);
writeSubjects($subs, $email);
$conn = mysqli_connect('localhost',$mysqlUsername,$mysqlPassword,'revise');
$q = 'INSERT INTO accounts (`fname`, `sname`, `email`, `pwd`) VALUES ("'.$fname.'","'.$sname.'","'.$email.'","'.$pwd.'");';
$query = mysqli_query($conn,$q);
echo $email;
setcookie("email", $email, time()+259200);
setcookie("pwd", $pwd, time()+259200);
var_dump($_COOKIE);
header('Location: index.php');
}
} else if(isset($_POST['email'])) {
$email = $_POST['email'];
$fname = $_POST['fname'];
$sname = $_POST['sname'];
} else {
$email = '';
$fname = '';
$sname = '';
}
?>
<?php
include "layouts.php";
$l = getLayout("basic.layout");
$l->writeHeader();
?>
<h1 class='title'>Sign Up</h1>
<form name='signup' method='post'>
<input type='text' name='fname' placeholder='First Name' value='<?php echo $fname;?>'><br/>
<input type='text' name='sname' placeholder='Surname' value='<?php echo $sname;?>'><br/>
<input type='text' name='email' placeholder='E-mail' value='<?php echo $email;?>'><br/>
<input type='password' name='pwd' placeholder='Password'><br/>
<input type='password' name='cfpwd' placeholder='Retype Password'><br/>
<div id='subjectPicker'>
<h3>Your Subjects:</h3>
<script src='subjectpicker.js' type='text/javascript'></script>
<div id='subPickarea'>
<div class='subjectPickerSubject'>
<input class='subjectPick' placeholder='Subject' name='s1' type='text'>
<select name="b1">
<option value='aqa'>AQA</option>
<option value='other'>Other</option>
</select>
</div>
</div>
<img src='images/plus.png' alt='+' onclick='newSubject()' height='30px' width='30px'/>
</div>
<input type='submit' value='Sign Up'>
</form>
<?php
$l->writeFooter();
?>