This repository has been archived by the owner on Feb 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsignup.php
148 lines (143 loc) · 6.14 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
144
145
146
147
148
<?php
if (!isset($_SESSION)) session_start();
include_once '_class/StudentManager.class.php';
include_once '_class/LecturerManager.class.php';
include_once '_class/AuthenticationManager.class.php';
include '_pages/header.php';
//if there is a running session go to home page
if(isset($_SESSION['repsyst_session_username'])){
header("Location: index.php");
exit();
}
if(isset($_POST['submit_signup'])){
$database = new PDO('mysql:host=localhost;dbname=srproj', 'root', '');
$database->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$std_manager = new StudentManager($database);
//creating student object and formatting attributes
$t_array = array(
'firstname' => ucfirst(strtolower($_POST['firstname'])),
'middlename'=> ucfirst(strtolower($_POST['middlename'])),
'lastname' => ucfirst(strtolower($_POST['lastname'])),
'email' => strtolower($_POST['email']),
'schoolid' => strtoupper($_POST['schoolid']));
$temp_student = new Student($t_array);
//setting username
$t_username = explode('@', $t_array['email']);
if($t_username[1] == 'ueab.ac.ke') $temp_student->setUsername($t_username[0]);
else header("Location: signup.php?signup=wrongemail");
//setting major
switch ($_POST['major']){
case 'SWEN':
$temp_student->setMajor(Major::SWEN);
break;
case 'NETW':
$temp_student->setMajor(Major::NETW);
break;
case 'BBIT':
$temp_student->setMajor(Major::BBIT);
break;
}
//setting gender
switch ($_POST['gender']){
case 'Male':
$temp_student->setGender(Gender::MALE);
break;
case 'Female':
$temp_student->setGender(Gender::FEMALE);
break;
}
//adding credentials to database
if(isset($_POST['firstpasswd']) && isset($_POST['reenterpasswd'])){
if($_POST['firstpasswd'] == $_POST['reenterpasswd']){
global $database, $temp_student, $std_manager;
$temp_Credentials = new Authentication($temp_student->username(), md5($_POST['firstpasswd']));
$temp_CredManager = new AuthenticationManager($database);
$uid = uniqid();
$std_manager->temp_add($temp_student, $uid);
$temp_CredManager->temp_add($temp_Credentials, $uid);
$message = "Go to the following link to activate your account. http://localhost/sr-proj/validateaccount.php?usr=".$temp_student->username()."&uniqueid=".$uid;
if(mail($temp_student->email(), 'Account Validation', $message)) header("Location: signup.php?signup=success");
else header("Location: signup.php?signup=failed");
}
else header("Location: signup.php?signup=nomatch");
}
else header("Location: signup.php?signup=empty");
}
else{
//handling signup messages
if(isset($_GET['signup'])){
$signup = $_GET['signup'];
switch($signup){
case 'success':
echo '<label class="success_message">Account waiting for validation.<br/>
Check your email to validate your account!</label><br/>';
break;
case 'failed':
echo '<label class="error_message">Creating new user failed.<br/></label>';
break;
case 'empty':
echo '<label class="error_message">Fill both passwords.</label><br/>';
break;
case 'invalidated':
echo '<label class="error_message">Could not find account to validate.</label><br/>';
break;
case 'nomatch':
echo '<label class="error_message">Passwords do not match.</label><br/>';
break;
case 'wrongemail':
echo '<label class="error_message">Use a UEA Baraton e-mail address (<i>[email protected]</i>).</label><br/>';
break;
}
}
unset($_GET['signup']);
//checking type of user
if(isset($_POST['type'])){ ?>
<head>
<meta charset="utf-8" />
<!-- <link rel="stylesheet" href="style.css" /> -->
<title>Sign Up!</title>
</head>
<body>
<section class="main-container">
<div class="main-wrapper">
<h1>Signup</h1>
<form class="signup-form" method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
<input type="text" name="firstname" required placeholder="First Name" value="<?php if(isset($_POST['firstname'])) $_POST['firstname'];?>" /><br/>
<input type="text" name="middlename" placeholder= "Middle Name" value="<?php if(isset($_POST['middlename'])) $_POST['middlename'];?>" /><br/>
<input type="text" name="lastname" required placeholder="Last Name" value="<?php if(isset($_POST['lastname'])) $_POST['lastname'];?>" /><br/>
<div class="select-style">
<select name="gender" required placeholder="Last Name">
<option value="Select" disabled selected hidden>Gender</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</div>
<?php if($_POST['type'] == 'Student'){ ?>
<div class="select-style">
<select name="major" required>
<option value="Select" disabled selected hidden>Major</option>
<option value="SWEN">Software Engineering</option>
<option value="NETW">Networking</option>
<option value="BBIT">Business Information Technology</option>
</select>
</div>
<input type="text" name="schoolid" required placeholder="School ID" value="<?php if(isset($_POST['schoolid'])) $_POST['schoolid'];?>" />
<?php } ?>
<input type="Email" name="email" required placeholder="[email protected]" value="<?php if(isset($_POST['email'])) $_POST['email'];?>"/>
<input type="Password" required placeholder="Password" name="firstpasswd" id="firstpasswd"/>
<input type="Password" required placeholder="Re-enter Password" name="reenterpasswd" id="reenterpasswd"/>
<button type="submit" name="submit_signup" id="submit_signup">Sign Up</button>
</form>
</div>
</section>
<script src="../_js/signup.js"></script>
</body><?php
}
else echo '<form class="signup-option" method="post" action="'.$_SERVER["PHP_SELF"].'">
<label><b>User type:</b></label></br>
<input type="radio" name="type" value="Student"> Student<br>
<input type="radio" name="type" value="Lecturer"> Lecturer<br>
<button type="submit" name="submit">Sign Up!</button>
</form>';
}
?>