This repository has been archived by the owner on Jul 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
settings.php
86 lines (71 loc) · 2.95 KB
/
settings.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
<?php
require_once("includes/header.php");
require_once("includes/classes/Account.php");
require_once("includes/classes/FormSanitizer.php");
require_once("includes/classes/SettingsFormProvider.php");
require_once("includes/classes/Constants.php");
if(!User::isLoggedIn()) {
header("Location: signIn.php");
}
$detailsMessage = "";
$passwordMessage = "";
$formProvider = new SettingsFormProvider();
if(isset($_POST["saveDetailsButton"])) {
$account = new Account($conn);
$firstName = FormSanitizer::sanitizingFormString($_POST["firstName"]);
$lastName = FormSanitizer::sanitizingFormString($_POST["lastName"]);
$email = FormSanitizer::sanitizingFormString($_POST["email"]);
if($account->updateDetails($firstName, $lastName, $email, $userLoggedInObj->getusername())) {
$detailsMessage = "<div class='alert alert-success'>
<strong>SUCCESS!</strong> Details updated successfully!
</div>";
}
else {
$errorMessage = $account->getFirstError();
if($errorMessage == "") $errorMessage = "Something went wrong";
$detailsMessage = "<div class='alert alert-danger'>
<strong>ERROR!</strong> $errorMessage
</div>";
}
}
if(isset($_POST["savePasswordButton"])) {
$account = new Account($conn);
$oldPassword = FormSanitizer::sanitizingFormPassword($_POST["oldPassword"]);
$newPassword = FormSanitizer::sanitizingFormPassword($_POST["newPassword"]);
$newPassword2 = FormSanitizer::sanitizingFormPassword($_POST["newPassword2"]);
if($account->updatePassword($oldPassword, $newPassword, $newPassword2, $userLoggedInObj->getusername())) {
$passwordMessage = "<div class='alert alert-success'>
<strong>SUCCESS!</strong> Password updated successfully!
</div>";
}
else {
$errorMessage = $account->getFirstError();
if($errorMessage == "") $errorMessage = "Something went wrong";
$passwordMessage = "<div class='alert alert-danger'>
<strong>ERROR!</strong> $errorMessage
</div>";
}
}
?>
<div class="settingsContainer column">
<div class="formSection">
<div class="message">
<?php echo $detailsMessage; ?>
</div>
<?php
echo $formProvider->createUserDetailsForm(
isset($_POST["firstName"]) ? $_POST["firstName"] : $userLoggedInObj->getUserFirstName(),
isset($_POST["lastName"]) ? $_POST["lastName"] : $userLoggedInObj->getUserLastName(),
isset($_POST["email"]) ? $_POST["email"] : $userLoggedInObj->getUserEmail()
);
?>
</div>
<div class="formSection">
<div class="message">
<?php echo $passwordMessage; ?>
</div>
<?php
echo $formProvider->createPasswordForm();
?>
</div>
</div>