-
Notifications
You must be signed in to change notification settings - Fork 0
/
student_process_signup.php
118 lines (95 loc) · 3.5 KB
/
student_process_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
<?php
require_once 'logger.php';
require_once("database.php");
session_start();
if (isset($_POST['signup'])) {
$_SESSION['form_data'] = [
'name' => $_POST['name'],
'email' => $_POST['email'],
'studie_retning' => $_POST['studie_retning'],
'studie_kull' => $_POST['studie_kull'],
'answer_1' => $_POST['answer_1'],
'answer_2' => $_POST['answer_2'],
];
$name = $_POST['name'];
$email = $_POST['email'];
$password = $_POST['password'];
$password_confirmation = $_POST['password_confirmation'];
$studie_retning = $_POST['studie_retning'];
$studie_kull = $_POST['studie_kull'];
$security_question_1 = $_POST['security_question_1'];
$security_question_2 = $_POST['security_question_2'];
$answer_1 = $_POST['answer_1'];
$answer_2 = $_POST['answer_2'];
$errors = [];
if (empty($name)) {
$errors['name_error'] = 'Navn må fylles ut';
}
if (strlen($name) < 3) {
$errors['name_error'] = 'Navn må være minst 3 bokstaver';
}
if (empty($email)) {
$errors['email_error'] = 'E-post må fylles ut';
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors['email_error'] = 'E-post må være en gyldig e-post';
}
if (strlen($password) < 8) {
$errors['password_error'] = 'Passord må inneholde minst 8 tegn';
}
if (!preg_match("/[a-zA-Z]/", $_POST['password'])) {
$errors['password_error'] = 'Passordet må inneholde minst 1 bokstav';
}
if (!preg_match("/[0-9]/", $_POST['password'])) {
$errors['password_error'] = 'Passordet må inneholde minst 1 tall';
}
if ($_POST['password'] !== $_POST['password_confirmation']) {
$errors['password_confirmation_error'] = 'Passordene må være like';
}
$password_hash = password_hash($password, PASSWORD_DEFAULT);
$mysqli = getConnection(0,0);
$emailCheckQuery = "Call DoesEmailExist(?)";
$emailstmt = mysqli_prepare($mysqli, $emailCheckQuery);
$emailstmt->bind_param("s", $email);
mysqli_stmt_execute($emailstmt);
mysqli_stmt_bind_result($emailstmt, $rowValue);
mysqli_stmt_fetch($emailstmt);
mysqli_stmt_close($emailstmt);
if($rowValue > 0) {
$errors['email_error'] = 'Eposten er allerede registrert.';
$errors['error'] = 'E-posten er allerede registrert. Vennligst prøv en annen e-post, eller <a href="login.php">logg inn</a>.';
}
if(!empty($errors)) {
$query = http_build_query($errors);
header("Location: student_signup.php?$query");
} else {
$sql = "CALL createStudent(?,?,?,?,?,?,?,?,?,?);";
$stmt = $mysqli->stmt_init();
if (!$stmt->prepare($sql)) {
die("SQL error: " . $mysqli->error);
}
$photo_path = "fetchFile.php?UUID=default";
$stmt->bind_param("ssssiiiiss",
$name,
$photo_path,
$password_hash,
$email,
$studie_retning,
$studie_kull,
$security_question_1,
$security_question_2,
$answer_1,
$answer_2);
$stmt_result = $stmt->execute();
if($stmt_result) {
$logger->info("STUDENT SIGNUP: Student successfully registered.");
header("Location: signup_success.php");
session_destroy();
} else {
header("Location: student_signup.php?error=Noe gikk galt. Vennligst prøv igjen.");
}
$stmt->close();
$mysqli->close();
exit();
}
}