forked from ellite/Wallos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregistration.php
186 lines (173 loc) · 7.73 KB
/
registration.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php
require_once 'includes/connect.php';
require_once 'includes/checkuser.php';
require_once 'includes/i18n/languages.php';
require_once 'includes/i18n/getlang.php';
require_once 'includes/i18n/' . $lang . '.php';
require_once 'includes/version.php';
function validate($value) {
$value = trim($value);
$value = stripslashes($value);
$value = htmlspecialchars($value);
$value = htmlentities($value);
return $value;
}
if ($userCount > 0) {
header("Location: login.php");
exit();
}
$theme = "light";
if (isset($_COOKIE['theme'])) {
$theme = $_COOKIE['theme'];
}
$currencies = array();
$query = "SELECT * FROM currencies";
$result = $db->query($query);
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
$currencyId = $row['id'];
$currencies[$currencyId] = $row;
}
$passwordMismatch = false;
$registrationFailed = false;
if (isset($_POST['username'])) {
$username = validate($_POST['username']);
$email = validate($_POST['email']);
$password = $_POST['password'];
$confirm_password = $_POST['confirm_password'];
$main_currency = $_POST['main_currency'];
$language = $_POST['language'];
$avatar = "0";
if ($password != $confirm_password) {
$passwordMismatch = true;
} else {
$query = "INSERT INTO user (username, email, password, main_currency, avatar, language) VALUES (:username, :email, :password, :main_currency, :avatar, :language)";
$stmt = $db->prepare($query);
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
$stmt->bindValue(':username', $username, SQLITE3_TEXT);
$stmt->bindValue(':email', $email, SQLITE3_TEXT);
$stmt->bindValue(':password', $hashedPassword, SQLITE3_TEXT);
$stmt->bindValue(':main_currency', $main_currency, SQLITE3_TEXT);
$stmt->bindValue(':avatar', $avatar, SQLITE3_TEXT);
$stmt->bindValue(':language', $language, SQLITE3_TEXT);
$result = $stmt->execute();
if ($result) {
$deleteQuery = "DELETE FROM household";
$stmtDelete = $db->prepare($deleteQuery);
$stmtDelete->execute();
$deleteQuery = "DELETE FROM subscriptions";
$stmtDelete = $db->prepare($deleteQuery);
$stmtDelete->execute();
$deleteQuery = "DELETE FROM fixer";
$stmtDelete = $db->prepare($deleteQuery);
$stmtDelete->execute();
$query = "INSERT INTO household (name) VALUES (:name)";
$stmt = $db->prepare($query);
$stmt->bindValue(':name', $username, SQLITE3_TEXT);
$stmt->execute();
$db->close();
header("Location: login.php");
exit();
} else {
$registrationFailed = true;
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="theme-color" content="<?= $theme == "light" ? "#FFFFFF" : "#222222" ?>"/>
<title>Wallos - Subscription Tracker</title>
<link rel="icon" type="image/png" href="images/icon/favicon.ico" sizes="16x16">
<link rel="apple-touch-icon" sizes="180x180" href="images/icon/apple-touch-icon.png">
<link rel="manifest" href="manifes.json">
<link rel="stylesheet" href="styles/login.css?<?= $version ?>">
<link rel="stylesheet" href="styles/login-dark-theme.css?<?= $version ?>" id="dark-theme" <?= $theme == "light" ? "disabled" : "" ?>>
<link rel="stylesheet" href="styles/barlow.css">
<script type="text/javascript" src="scripts/registration.js?<?= $version ?>"></script>
</head>
<body>
<div class="content">
<section class="container">
<header>
<?php
if ($theme == "light") {
?> <img src="images/wallossolid.png" alt="Wallos Logo" title="Wallos - Subscription Tracker" /> <?php
} else {
?> <img src="images/wallossolidwhite.png" alt="Wallos Logo" title="Wallos - Subscription Tracker" /> <?php
}
?>
<p>
<?= translate('create_account', $i18n) ?>
</p>
</header>
<form action="registration.php" method="post">
<div class="form-group">
<label for="username"><?= translate('username', $i18n) ?>:</label>
<input type="text" id="username" name="username" required>
</div>
<div class="form-group">
<label for="email"><?= translate('email', $i18n) ?>:</label>
<input type="email" id="email" name="email" required>
</div>
<div class="form-group">
<label for="password"><?= translate('password', $i18n) ?>:</label>
<input type="password" id="password" name="password" required>
</div>
<div class="form-group">
<label for="confirm_password"><?= translate('confirm_password', $i18n) ?>:</label>
<input type="password" id="confirm_password" name="confirm_password" required>
</div>
<div class="form-group">
<label for="currency"><?= translate('main_currency', $i18n) ?>:</label>
<select id="currency" name="main_currency" placeholder="Currency">
<?php
foreach ($currencies as $currency) {
?>
<option value="<?= $currency['id'] ?>"><?= $currency['name'] ?></option>
<?php
}
?>
</select>
</div>
<div class="form-group">
<label for="language"><?= translate('language', $i18n) ?>:</label>
<select id="language" name="language" placeholder="Language" onchange="changeLanguage(this.value)">
<?php
foreach ($languages as $code => $name) {
$selected = ($code === $lang) ? 'selected' : '';
?>
<option value="<?= $code ?>" <?= $selected ?>><?= $name ?></option>
<?php
}
?>
</select>
</div>
<?php
if ($passwordMismatch) {
?>
<sup class="error">
<?= translate('passwords_dont_match', $i18n) ?>
</sup>
<?php
}
?>
<?php
if ($registrationFailed) {
?>
<sup class="error">
<?= translate('registration_failed', $i18n) ?>
</sup>
<?php
}
?>
<div class="form-group">
<input type="submit" value="<?= translate('register', $i18n) ?>">
</div>
</form>
</section>
</div>
</body>
</html>