forked from alexlittle/mQuiz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile.php
127 lines (107 loc) · 3.89 KB
/
profile.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
<?php
include_once("config.php");
$PAGE = "profile";
$username = optional_param("username",$USER->username,PARAM_TEXT);
$password = optional_param("password","",PARAM_TEXT);
$repeatpassword = optional_param("repeatpassword","",PARAM_TEXT);
$firstname = optional_param("firstname",$USER->firstname,PARAM_TEXT);
$surname = optional_param("surname",$USER->lastname,PARAM_TEXT);
$email = optional_param("email",$USER->email,PARAM_TEXT);
$submit = optional_param("submit","",PARAM_TEXT);
$ref = optional_param("ref",$CONFIG->homeAddress."index.php",PARAM_TEXT);
if ($submit != ""){
if ($username == ""){
array_push($MSG,"Enter a username");
}
if ($email == ""){
array_push($MSG,"Enter your email");
} else if(!preg_match("/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/i", $email) ) {
array_push($MSG,"Invalid email address format");
}
// check all fields completed
if ($firstname == ""){
array_push($MSG,"Enter your firstname");
}
if ($surname == ""){
array_push($MSG,"Enter your surname");
}
// check email/username not in use by anyone else
if($API->checkUserNameInUse($username)){
array_push($MSG,"Username already in use, please select another");
}
if($API->checkEmailInUse($email)){
array_push($MSG,"Email already in use, please select another");
}
// update user details
if(count($MSG) == 0){
if ($API->updateUser($username,$email, $firstname, $surname)){
array_push($MSG,"You details have been updated" );
// reload user
$USER->username = $username;
$USER->load();
} else {
array_push($MSG,"An error occured whilst updating your details" );
}
}
// check password long enough
if (strlen($password) > 0){
if (strlen($password) < 6){
array_push($MSG,"Your password must be 6 characters or more");
}
// check passwords match
if ($password != $repeatpassword){
array_push($MSG,"Your passwords don't match");
}
if (strlen($password) >= 6 && $password == $repeatpassword){
if($API->updateUserPassword($password)){
array_push($MSG,"Your password has been updated");
}
}
}
}
include_once("./includes/header.php");
echo "<h1>".getstring("profile.title")."</h1>";
if(!empty($MSG)){
echo "<ul>";
foreach ($MSG as $err){
echo "<li>".$err."</li>";
}
echo "</ul>";
}
?>
<form method="post" action="">
<div class="formblock">
<div class="formlabel"><?php echo getstring('register.username'); ?></div>
<div class="formfield"><input type="text" name="username" value="<?php echo $username; ?>"></input></div>
</div>
<div class="formblock">
<div class="formlabel"><?php echo getstring('register.email'); ?></div>
<div class="formfield"><input type="text" name="email" value="<?php echo $email; ?>"></input></div>
</div>
<div class="formblock">
<div class="formlabel"><?php echo getstring("register.firstname"); ?></div>
<div class="formfield"><input type="text" name="firstname" value="<?php echo $firstname; ?>"></input></div>
</div>
<div class="formblock">
<div class="formlabel"><?php echo getstring("register.surname"); ?></div>
<div class="formfield"><input type="text" name="surname" value="<?php echo $surname; ?>"></input></div>
</div>
<div class="formblock">
<div class="formfield"><?php echo getstring("profile.password.info"); ?></div>
</div>
<div class="formblock">
<div class="formlabel"><?php echo getstring("profile.newpassword"); ?></div>
<div class="formfield"><input type="password" name="password" value=""></input></div>
</div>
<div class="formblock">
<div class="formlabel"><?php echo getstring("profile.repeatnewpassword"); ?></div>
<div class="formfield"><input type="password" name="repeatpassword" value=""></input></div>
</div>
<div class="formblock">
<div class="formlabel"> </div>
<div class="formfield"><input type="submit" name="submit" value="<?php echo getstring("profile.submit.button"); ?>"></input></div>
</div>
</form>
<?php
include_once("./includes/footer.php");
?>