Skip to content

Commit 6f13974

Browse files
committed
old: Add photo profile support
Initial photo profile support. The backend has already provided the API. Implement the feature on the frontend as well. Signed-off-by: Ammar Faizi <[email protected]>
1 parent c6d2396 commit 6f13974

File tree

3 files changed

+67
-6
lines changed

3 files changed

+67
-6
lines changed

old/assets/default_profile.png

17.6 KB
Loading

old/assets/js/api.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,12 @@ function gwm_fn_change_password(cb, cur_pass, new_pass, retype_new_pass)
146146

147147
function gwm_fn_set_user_info(cb, data)
148148
{
149-
gwm_api_set_user_info(cb, data);
149+
let callback = function (j) {
150+
alert(j.res);
151+
if (cb)
152+
cb(j);
153+
};
154+
gwm_api_set_user_info(callback, data);
150155
}
151156

152157
function gwm_fn_logout()
@@ -214,3 +219,21 @@ function gwm_auth_redirect_if_not_authorized()
214219
gwm_auth_renew_session();
215220
return false;
216221
}
222+
223+
function gwm_api_delete_user_photo(cb)
224+
{
225+
gwm_exec_api({
226+
method: "GET",
227+
url: GWM_API_URL + "delete_user_photo",
228+
token: LS.getItem("gwm_token"),
229+
callback: cb
230+
});
231+
}
232+
233+
function gwm_fn_delete_user_photo(cb)
234+
{
235+
if (!confirm("Are you sure you want to delete your photo?"))
236+
return;
237+
238+
gwm_api_delete_user_photo(cb);
239+
}

old/profile.html

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717
<tbody>
1818
<tr>
1919
<td align="center" colspan="3">
20-
<div id="photo_box"></div>
20+
<div id="del_photo" style="margin-bottom: 20px;"><a href="javascript:void();">Delete Photo</a></div>
21+
<div id="photo_box">
22+
<img src="assets/default_profile.png" id="photo_obj">
23+
</div>
2124
</td>
2225
</tr>
2326
<tr>
24-
<td>Upload Photo</td>
27+
<td>Upload New Photo</td>
2528
<td>:</td>
2629
<td><input type="file" name="photo" id="uform_photo"/></td>
2730
</tr>
@@ -95,6 +98,13 @@
9598
width: 200px;
9699
height: 200px;
97100
border: 1px solid #000;
101+
border-radius: 100%;
102+
margin-bottom: 50px;
103+
}
104+
#photo_obj {
105+
width: 100%;
106+
height: 100%;
107+
border-radius: 100%;
98108
}
99109
#frcg {
100110
margin: 0 auto;
@@ -114,6 +124,20 @@
114124
}
115125
</style>
116126
<script>
127+
function delete_photo_click_callback()
128+
{
129+
gwm_fn_delete_user_photo(function (j) {
130+
gwm_auth_renew_session(function () {
131+
form_uinfo_set_inputs(gwm_auth_get_user());
132+
});
133+
134+
if (j.code === 200) {
135+
gid("photo_obj").src = "assets/default_profile.png";
136+
dp.style.display = "none";
137+
}
138+
});
139+
}
140+
117141
function form_uinfo_set_inputs(u)
118142
{
119143
gid("uform_full_name").value = u.full_name;
@@ -124,6 +148,19 @@
124148
gid("uform_telegram_username").value = u.socials.telegram_username;
125149
gid("uform_twitter_username").value = u.socials.twitter_username;
126150
gid("uform_discord_username").value = u.socials.discord_username;
151+
152+
if (u.photo)
153+
gid("photo_obj").src = u.photo;
154+
155+
let dp = gid("del_photo");
156+
if (u.photo) {
157+
dp.style.display = "block";
158+
dp.onclick = function() {
159+
delete_photo_click_callback();
160+
};
161+
} else {
162+
dp.style.display = "none";
163+
}
127164
}
128165

129166
function main()
@@ -144,11 +181,12 @@
144181
e.preventDefault();
145182
let fd = new FormData(uform);
146183
gwm_fn_set_user_info(function (j) {
184+
toggle_disable_inputs(uform, false);
147185
gwm_auth_renew_session(function () {
148-
toggle_disable_inputs(uform, false);
149-
let u = gwm_auth_get_user();
150-
form_uinfo_set_inputs(u);
186+
form_uinfo_set_inputs(gwm_auth_get_user());
151187
});
188+
if (j.code === 200)
189+
photo.value = "";
152190
}, fd);
153191
toggle_disable_inputs(uform, true);
154192
});

0 commit comments

Comments
 (0)