-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignup.php
126 lines (120 loc) · 6.82 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
<html>
<head>
<meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1.0"/>
<link href="css/signup.css" rel="stylesheet">
<script src="jquery-3.4.1.js" type="text/javascript"></script>
<title> Sign up </title>
</head>
<body>
<?php
// define variables and set to empty values
$nameErr = $emailErr = $surnameErr = $passwordErr = $passwordRepeatErr = "";
$name = $email = $surname = $password = $passwordRepeat = "";
if(isset($_POST["signup"])) {
require("db/users.php");
$objUser = new users;
//validate the input
//validate the email
$email = test_input($_POST["email"]);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
}
else {
$objUser->setEmail($_POST['email']);
$name = test_input($_POST["name"]);
//validate the name
if(preg_match("/^[\p{Cyrillic}]+$/u", $name)) {
$objUser->setName($_POST['name']);
$surname = test_input($_POST["surname"]);
//validate the surname
if(preg_match("/^[\p{Cyrillic}]+$/u", $surname)) {
$objUser->setSurname($_POST['surname']);
$objUser->setUsername($_POST['username']);
//validate the password
$password = test_input($_POST["password"]);
if(strlen($password) < 10) {
$passwordErr = "The password must be at least 10 characters long";
} else {
//hash the password
$hash = password_hash($password, PASSWORD_DEFAULT);
$objUser->setPassword($hash);
//validate the confirm password field
$passwordRepeat = test_input($_POST["passwordRepeat"]);
if($password == $passwordRepeat) {
$value = $_POST['type'];
if($value == 'student') {
$objUser->setType(0);
}
else {
$objUser->setType(1);
}
$objUser->setLastLogin(date('Y-m-d h:i:s'));
$userData = $objUser->getUserByEmail();
if(is_array($userData) && count($userData)>0) {
echo "User already registered in the system";
} else {
if($objUser->save()) {
echo "User Registred..";
header("location: welcome.html");
} else {
echo "Failed..";
}
}
} else {
$passwordRepeatErr = "The two passwords are not the same";
}
}
} else {
$surnameErr = "The surname field must contain only cyrilic letters";
}
} else {
$nameErr = "The name filed must contain only cyrilic letters";
}
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<form id="signupForm" action="" method="post" role="form">
<div class="container">
<h1>Регистрация</h1>
<p>Моля попълнете тази форма, за да създадете акаунт.</p>
<hr>
<label ><b>Email*</b></label>
<div class="error"> <?php echo $emailErr;?></div>
<input type="text" placeholder="Въведете email" name="email" required>
<label ><b>Име*</b></label>
<div class="error"> <?php echo $nameErr;?></div>
<input type="text" placeholder="Въведете име" name="name" required>
<label><b>Фамилия*</b></label>
<div class="error"> <?php echo $surnameErr;?></div>
<input type="text" placeholder="Въведете фамилия" name="surname" required>
<label ><b>Потребителско име*</b></label>
<input type="text" placeholder="Въведете потребителско име" name="username" required>
<label ><b>Парола*</b></label>
<div class="error"> <?php echo $passwordErr;?></div>
<input type="password" placeholder="Въведете парола" name="password" required>
<label ><b>Повторете паролата*</b></label>
<div class="error"> <?php echo $passwordRepeatErr;?></div>
<input type="password" placeholder="Повтори парола" name="passwordRepeat" required>
<p>Моля изберете тип участие в системата</p>
<input type="radio" name="type" value="student"> Студент
<input type="radio" name="type" value="lector"> Преподавател
<p>Със създаването на акаунт се съгласявате с нашите <a href="#">Terms & Privacy</a>.</p>
<div class="clearfix">
<button type="submit" class="signupBtn" name="signup">Регистрация</button>
<button type="button" class="cancelBtn" onclick="resetForm()">Отмяна</button>
</div>
</div>
</form>
<script>
function resetForm() {
document.getElementById("signupForm").reset();
}
</script>
</body>
</html>