This repository has been archived by the owner on Jan 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignup.php
136 lines (131 loc) · 4.63 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
<?php
require_once "functions/db_connect.php";
include "functions/tools.php";
if(isset($_POST["signup"])){
session_start();
$db = PDOFactory::getConnection();
$token = generateReference(6);
$colorID = rand(1,20);
$color = $db->query("SELECT color_value FROM name_colors WHERE number = $colorID")->fetch(PDO::FETCH_ASSOC);
try{
$db->beginTransaction();
$newUser = $db->prepare("INSERT INTO user(user_token, user_pseudo, user_pwd) VALUES(:token, :pseudo, :pwd)");
$newUser->bindParam(':pseudo', $_POST["username"]);
$newUser->bindParam(':pwd', $_POST["password"]);
$newUser->bindParam(':token', $token);
$newUser->execute();
$newPref = $db->prepare("INSERT INTO user_preferences(user_token, up_color)
VALUES(:token, :color)");
$newPref->bindParam(':token', $token);
$newPref->bindParam(':color', $color["color_value"]);
$newPref->execute();
$newStats = $db->prepare("INSERT INTO user_stats(user_token) VALUES(:token)");
$newStats->bindParam(':token', $token);
$newStats->execute();
$db->commit();
$_SESSION["username"] = $_POST["username"];
$_SESSION["power"] = "0";
$_SESSION["token"] = $token;
$_SESSION["user_lang"] = "en";
if(isset($_POST["box-token-redirect"])){
header("Location: box/".$_POST["box-token-redirect"]);
} else {
header("Location: home");
}
} catch(PDOException $e){
$db->rollBack();
echo $e->getMessage();
}
}
?>
<html>
<head>
<meta charset="UTF-8">
<title>Sign up</title>
<?php include "styles.php";?>
<link rel="stylesheet" href="assets/css/light-theme.css">
</head>
<body>
<?php include "nav.php";?>
<div class="main layer portal-main">
<div class="col-lg-4 col-lg-offset-4 col-md-offset-3 col-md-6 login-space">
<legend><?php echo $lang["sign_up"];?></legend>
<form action="" method="post">
<div class="form-group form-group-lg has-feedback" id="username-form-group">
<input type="text" placeholder="<?php echo $lang["username"];?>" class="form-control form-control-portal" name="username">
</div>
<div class="form-group form-group-lg">
<input type="password" placeholder="<?php echo $lang["password"];?>" class="form-control form-control-portal" name="password">
</div>
<div class="form-group form-group-lg has-feedback" id="password-confirm-form-group">
<input type="password" placeholder="<?php echo $lang["pwd_confirm"];?>" class="form-control form-control-portal" name="password-confirm">
</div>
<?php if(isset($_POST["box-token"])){ ?>
<input type="hidden" name="box-token-redirect" value="<?php echo $_POST["box-token"];?>">
<?php } ?>
<input type="submit" class="btn btn-primary btn-block" name="signup" value="<?php echo $lang["sign_up"];?>">
</form>
<p style="text-align: center"><?php echo $lang["already_account"];?> <a href="portal"><?php echo $lang["log_in_here"];?></a></p>
</div>
</div>
<style>
.layer{
background-color: #cf9930;
height: 100%;
}
</style>
<?php include "scripts.php";?>
<script>
$(document).ready(function(){
var compare;
$(":regex(name,username)").on('keyup blur', function(){
var box = $(this);
var elementId = "#username-form-group";
removeFeedback(elementId);
//console.log("Letter typed");
if(compare){
clearTimeout(compare);
//console.log("There is a timeout. Clearing...");
}
compare = setTimeout(function(){
var string = box.val();
//console.log("timeout expired. Search with '"+string+"' query.");
$.post("functions/compare_user_string.php", {string : string}).done(function(data){
if(data == 1){
console.log("Success, you can use this username");
applySuccessFeedback(elementId);
$(":regex(name,signup)").removeClass("disabled");
$(":regex(name,signup)").removeAttr("disabled");
} else {
console.log("This username already exists");
applyErrorFeedback(elementId);
$(":regex(name,signup)").addClass("disabled");
$(":regex(name,signup)").attr("disabled", "disabled");
}
})
}, 1000);
}).on('keydown', function(e){
if(e.which === 32) return false;
})
$(":regex(name,password-confirm)").on('keyup blur', function(){
var box = $(this);
var elementId = "#password-confirm-form-group";
removeFeedback(elementId);
if(compare){
clearTimeout(compare);
}
compare = setTimeout(function(){
var string = box.val();
if(string != ""){
if(string == $(":regex(name,password)").val()){
applySuccessFeedback(elementId);
} else {
applyErrorFeedback(elementId);
}
}
}, 500);
})
})
</script>
</body>
</html>