-
Notifications
You must be signed in to change notification settings - Fork 1
/
edit-profile.php
174 lines (156 loc) · 7.2 KB
/
edit-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
165
166
167
168
169
170
171
172
173
174
<?php include('head.php');
/**
* editProfile Page - This page is for a user to change his password, change bio, information...redirect to userProfile.php
* Copyright (C) 2011-2012 Betaville
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
?>
<body>
<div class='master-container'>
<?php
//If user is not logged in Redirect....
if (!isset($_SESSION['logged']) && !$_SESSION['logged'] == true ) {
?>
<script type="text/javascript" >
window.location=<?php echo '"'.$WEB_URL.'"';?>;
</script>
<?php
}
//If Password entered was wrong, the Service request returns false!
if(isset($_GET['changedPass'])) {
echo '<strong>OldPassword you entered was incorrect!!!</strong>';
}
/* NOT SURE IF THIS IS NEEDED RIGHT NOW
if(isset($_POST['displayName'])){
echo "inside displayName";
$updateUser = SERVICE_URL.'?section=user&request=changedisplayName&token='.$_SESSION['token'].'&username='.$userName.'&displayName='.$_POST['displayName'];
$temp1 = file_get_contents($updateUser,0,null,null);
$dNameChanged = json_decode($temp1, true);
if ($dNameChanged['dNameChanged'])
echo "Web service call initiated for displayName <br />";
else
echo $dNameChanged['dNameChanged']; // make sure that the web service has the same name when u code it.
}
*/
//Check if either the bio or website were updated
if(isset($_POST['bio'])||isset($_POST['website'])) {
$userName = $_SESSION['username'];
//Service call to change bio for a user/ urlencode string before passing through service
if(isset($_POST['bio'])){
$bio_encoded = urlencode($_POST['bio']);
$updatebioRequest = SERVICE_URL.'?section=user&request=changebio&token='.$_SESSION['token'].'&username='.$userName.'&bio='.$bio_encoded;
$updatebioJSON = file_get_contents($updatebioRequest,0,null,null);
$bio_changed = json_decode($updatebioJSON, true);
}
//Service call to change website for a user/ urlencode string before passing through service
if(isset($_POST['website'])){
$website_encoded = urlencode($_POST['website']);
$updatewebsiteRequest = SERVICE_URL.'?section=user&request=changewebsite&token='.$_SESSION['token'].'&username='.$userName.'&website='.$website_encoded;
$updatewebsiteJSON = file_get_contents($updatewebsiteRequest,0,null,null);
$website_changed = json_decode($updatewebsiteJSON, true);
}
?>
<script type="text/javascript" >
window.location=<?php echo "\"".WEB_URL."/profile.php\""; ?>;
</script>
<?php
}
//Service call to Change password, merged into the same file......
if(isset($_POST['oldPass']) && isset($_POST['newPass'])){
$updatePass = SERVICE_URL.'?section=user&request=changepass&token='.$_SESSION['token'].'&oldPass='.$_POST['oldPass'].'&newPass='.$_POST['newPass'];
$updatePassJSON = file_get_contents($updatePass,0,null,null);
$passChanged = json_decode($updatePassJSON, true);
$changedPass = $passChanged['passChanged'];
if($changedPass===true) {
?>
<script type="text/javascript" >
window.location=<?php echo "\"".WEB_URL."/profile.php\""; ?>;
</script>
<?php
}
else {
header("Location: edit-profile.php?changedPass=".$changedPass);
}
}
$userName = $_SESSION['username'];
// get user information
$userRequest = SERVICE_URL.'?section=user&request=getpublicinfo&username='.$userName;
$userJSON = file_get_contents($userRequest,0,null,null);
$userOutput = json_decode($userJSON, true);
$user = $userOutput['userInfo'];
$gravatarImage= $user['avatar'];
?>
<!-- User Profile Update form-->
<div class='page-container'>
<div class='project-container'>
<h1> Hello <?php echo $userName; ?>! </h1>
<div class='projects'>
<div class='project-description'>
<form name='edit-profile' id='edit-profile' action='edit-profile.php' method='post' enctype="multipart/form-data">
<input type="hidden" name="username" value="<?php echo $userName ?>">
<table border="0">
<tr><td><img src=<?php echo $gravatarImage;?> height='100' width='100' style='background-color: #383838'></td>
<tr><td><label>Name: </label></td><td><label><?php echo $user['userName'];?></label></td></tr>
<tr><td><label>About me: </label></td><td><input type="text" name="bio" value="<?php echo $user['bio']; ?>" /></td></tr>
<tr><td><label>Website: </label></td><td><input type="text" name="website" value="<?php echo $user['website']; ?>" /></td></tr>
<tr><td><label>Profile: </label></td><td><label><?php echo $user['type'];?></label></td></tr>
<tr><td></td><td></td></tr>
<tr><td><input type="submit" name="submit" value="Update Profile" /></td></tr>
</table>
</form>
</div>
</div>
</div>
<!-- User Password Update form-->
<div class='activity-section'>
<form name='changePass' id='idChangePass' method='post' action='edit-profile.php'>
<input type="hidden" name="username" value="<?php echo $userName; ?>">
<table class="ChangePass-section" border="0" >
<tr><td><label>Old Password: </label></td><td><input type="password" name="oldPass" onkeypress="if (event.keyCode==13) document.getElementById('button').click()"/></td></tr>
<tr><td><label>New Password: </label></td><td><input type="password" name="newPass" onkeypress="if (event.keyCode==13) document.getElementById('button').click()"/></td></tr>
<tr><td><label>Confirm New Password: </label></td><td><input type="password" name="confirmPass" onkeypress="if (event.keyCode==13) document.getElementById('button').click()"/></td></tr>
<tr><td></td><td></td></tr>
<tr><td><input type="button" id="button" value="Change Password" onclick="verifyNewPass()"/></td></tr>
</table>
</form>
<div id="verifyMsg" style="display:none">
<p align="center" style="color:red">Please make sure that your Confirm Password matches your New Password</p>
</div>
<div id="passMsg" style="display:none">
<p align="center" style="color:red">None of the above fields can be left blank.</p>
</div>
<script type="text/javascript">
function verifyNewPass(){
document.getElementById('verifyMsg').style.display="none";
document.getElementById('passMsg').style.display="none";
var oldPass = document.forms['changePass']['oldPass'].value;
var newPass = document.forms['changePass']['newPass'].value;
var confirmPass = document.forms['changePass']['confirmPass'].value;
if(oldPass=='' || newPass=='' || confirmPass=='')
document.getElementById('passMsg').style.display="block";
else
if(newPass==confirmPass){
var formId = document.getElementById('idChangePass');
formId.submit();
}
else
document.getElementById('verifyMsg').style.display="block";
}
</script>
</div>
<?php include('footer.php'); ?>
</div>
</body>
</html>