-
Notifications
You must be signed in to change notification settings - Fork 2
/
profile.php
164 lines (120 loc) · 4.87 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
require_once("includes/header.php");
require_once("includes/paypalConfig.php");
require_once("includes/classes/Account.php");
require_once("includes/classes/FormSanitizer.php");
require_once("includes/classes/Constants.php");
require_once("includes/classes/BillingDetails.php");
$user = new User($con, $userLoggedIn);
$detailsMessage = "";
$passwordMessage = "";
$subscriptionMessage = "";
if(isset($_POST["saveDetailsButton"])) {
$account = new Account($con);
$firstName = FormSanitizer::sanitizeFormString($_POST["firstName"]);
$lastName = FormSanitizer::sanitizeFormString($_POST["lastName"]);
$email = FormSanitizer::sanitizeFormEmail($_POST["email"]);
if($account->updateDetails($firstName, $lastName, $email, $userLoggedIn)) {
$detailsMessage = "<div class='alertSuccess'>
Details updated successfully!
</div>";
}
else {
$errorMessage = $account->getFirstError();
$detailsMessage = "<div class='alertError'>
$errorMessage
</div>";
}
}
if(isset($_POST["savePasswordButton"])) {
$account = new Account($con);
$oldPassword = FormSanitizer::sanitizeFormPassword($_POST["oldPassword"]);
$newPassword = FormSanitizer::sanitizeFormPassword($_POST["newPassword"]);
$newPassword2 = FormSanitizer::sanitizeFormPassword($_POST["newPassword2"]);
if($account->updatePassword($oldPassword, $newPassword, $newPassword2, $userLoggedIn)) {
$passwordMessage = "<div class='alertSuccess'>
Password updated successfully!
</div>";
}
else {
$errorMessage = $account->getFirstError();
$passwordMessage = "<div class='alertError'>
$errorMessage
</div>";
}
}
if (isset($_GET['success']) && $_GET['success'] == 'true') {
$token = $_GET['token'];
$agreement = new \PayPal\Api\Agreement();
$subscriptionMessage = "<div class='alertError'>
Something went wrong!
</div>";
try {
// Execute agreement
$agreement->execute($token, $apiContext);
$result = BillingDetails::insertDetails($con, $agreement, $token, $userLoggedIn);
$result = $result && $user->setIsSubscribed(1);
if($result) {
$subscriptionMessage = "<div class='alertSuccess'>
You're all signed up!
</div>";
}
} catch (PayPal\Exception\PayPalConnectionException $ex) {
echo $ex->getCode();
echo $ex->getData();
die($ex);
} catch (Exception $ex) {
die($ex);
}
}
else if (isset($_GET['success']) && $_GET['success'] == 'false') {
$subscriptionMessage = "<div class='alertError'>
User cancelled or something went wrong!
</div>";
}
?>
<div class="settingsContainer column">
<div class="formSection">
<form method="POST">
<h2>User details</h2>
<?php
$firstName = isset($_POST["firstName"]) ? $_POST["firstName"] : $user->getFirstName();
$lastName = isset($_POST["lastName"]) ? $_POST["lastName"] : $user->getLastName();
$email = isset($_POST["email"]) ? $_POST["email"] : $user->getEmail();
?>
<input type="text" name="firstName" placeholder="First name" value="<?php echo $firstName; ?>">
<input type="text" name="lastName" placeholder="Last name" value="<?php echo $lastName; ?>">
<input type="email" name="email" placeholder="Email" value="<?php echo $email; ?>">
<div class="message">
<?php echo $detailsMessage; ?>
</div>
<input type="submit" name="saveDetailsButton" value="Save">
</form>
</div>
<div class="formSection">
<form method="POST">
<h2>Update password</h2>
<input type="password" name="oldPassword" placeholder="Old password">
<input type="password" name="newPassword" placeholder="New password">
<input type="password" name="newPassword2" placeholder="Confirm new password">
<div class="message">
<?php echo $passwordMessage; ?>
</div>
<input type="submit" name="savePasswordButton" value="Save">
</form>
</div>
<div class="formSection">
<h2>Subscription</h2>
<div class="message">
<?php echo $subscriptionMessage; ?>
</div>
<?php
if($user->getIsSubscribed()) {
echo "<h3>You are subscribed! Go to PayPal to cancel.</h3>";
}
else {
echo "<a href='billing.php'>Subscribe to InfiMaze</a>";
}
?>
</div>
</div>