-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.php
102 lines (88 loc) · 4 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
require_once 'include/header.php';
require_once 'include/classes/Account.php';
require_once 'include/classes/FormValidation.php';
require_once 'include/classes/Constants.php';
require_once 'include/classes/SettingsFormProvider.php';
if (!User::isLoggedIn()){
header("location: signIn.php");
}
$detailsMessage = "";
$passwordMessage = "";
$settingsFormProvider = new SettingsFormProvider();
if (isset($_POST['saveDetailsButton'])){
$account = new Account($conn);
$firstName = FormValidation::sanitizeFormString($_POST['fname']);
$lastName = FormValidation::sanitizeFormString($_POST['lname']);
$email = FormValidation::sanitizeFormEmail($_POST['email']);
if($account->updateDetails($firstName, $lastName,$email,$userLoggedInObj->getUserName())){
//success
$detailsMessage = "<div class='alert alert-success alert-dismissible fade show' role='alert'>
<strong>SUCCESS!</strong> Details updated successfully!
<button type='button' class='close' data-dismiss='alert' aria-label='Close'>
<span aria-hidden='true'>×</span>
</button>
</div>";
}else{
//update failed
$errorMessage = $account->getFirstError();
if(empty($errorMessage)) $errorMessage = "Something Went Wrong";
$detailsMessage = "<div class='alert alert-danger alert-dismissible fade show' role='alert'>
<strong>ERROR!</strong> $errorMessage
<button type='button' class='close' data-dismiss='alert' aria-label='Close'>
<span aria-hidden='true'>×</span>
</button>
</div>";
}
}
if (isset($_POST['savePasswordButton'])){
$account = new Account($conn);
$oldPassword = FormValidation::sanitizeFormPassword($_POST['oldPass']);
$newPassword = FormValidation::sanitizeFormPassword($_POST['newPass']);
$confirmNewPassword = FormValidation::sanitizeFormPassword($_POST['confirmNewPass']);
if($account->updatePassword($oldPassword,$newPassword,$confirmNewPassword,$userLoggedInObj->getUserName())){
//success
$passwordMessage = "<div class='alert alert-success alert-dismissible fade show' role='alert'>
<strong>SUCCESS!</strong> Password updated successfully!
<button type='button' class='close' data-dismiss='alert' aria-label='Close'>
<span aria-hidden='true'>×</span>
</button>
</div>";
}else{
//update failed
$errorMessage = $account->getFirstError();
if(empty($errorMessage)) $errorMessage = "Something Went Wrong";
$passwordMessage = "<div class='alert alert-danger alert-dismissible fade show' role='alert'>
<strong>ERROR!</strong> $errorMessage
<button type='button' class='close' data-dismiss='alert' aria-label='Close'>
<span aria-hidden='true'>×</span>
</button>
</div>";
}
}
?>
<div class="settingsContainer column">
<div class="formSection">
<div class="message">
<?php
echo $detailsMessage;
?>
</div>
<?php
echo $settingsFormProvider->createUserDetailsForm(
$_POST['fname'] ?? $userLoggedInObj->getFirstName(),
$_POST['lname'] ?? $userLoggedInObj->getLastName(),
$_POST['email'] ?? $userLoggedInObj->getEmail()
);
?>
</div>
<div class="formSection">
<div class="message">
<?php
echo $passwordMessage;
?>
</div>
<?php echo $settingsFormProvider->createPasswordForm(); ?>
</div>
</div>
<?php require_once 'include/footer.php'; ?>