changed profile page to /users/username

v1.18.x
Baris Usakli 12 years ago
parent 0eacec8166
commit cef1ba4c08

@ -59,7 +59,7 @@
gravatar.src = data['picture']+"?s=24"; gravatar.src = data['picture']+"?s=24";
$('#user_label').attr('href','/users/'+data.uid+'/'+data['username']); $('#user_label').attr('href','/users/'+data['username']);
user_label.innerHTML = ''; user_label.innerHTML = '';
user_label.appendChild(gravatar); user_label.appendChild(gravatar);

@ -340,8 +340,12 @@ passport.deserializeUser(function(uid, done) {
var requestedUserId = req.user.uid; var requestedUserId = req.user.uid;
if(req.params.id != req.user.uid) var username = req.params.id;
requestedUserId = req.params.id;
user.get_uid_by_username(username, function(uid) {
if(uid != req.user.uid)
requestedUserId = uid;
user.getUserData(requestedUserId, function(data) { user.getUserData(requestedUserId, function(data) {
if(data) if(data)
@ -353,6 +357,11 @@ passport.deserializeUser(function(uid, done) {
else else
callback({user:{}}); callback({user:{}});
}); });
});
} }
@ -387,28 +396,28 @@ passport.deserializeUser(function(uid, done) {
return res.redirect('/403'); return res.redirect('/403');
}); });
app.get('/users/:uid', handleUserProfile);
app.get('/users/:uid/:username*', handleUserProfile); app.get('/users/:username*', handleUserProfile);
function handleUserProfile(req, res) { function handleUserProfile(req, res) {
console.log("OPPA 1");
if(req.params.uid == 0) { if(!req.params.username) {
res.send("User doesn't exist!"); res.send("User doesn't exist!");
return; return;
} }
user.getUserData(req.params.uid, function(data) { user.get_uid_by_username(req.params.username, function(uid) {
user.getUserData(uid, function(data) {
if(data) { if(data) {
if(req.url.indexOf(data.username) == -1) res.send(templates['header'] + '<script>templates.ready(function(){ajaxify.go("users/'+data.username + '");});</script>' + templates['footer']);
res.redirect(301, '/users/'+req.params.uid+'/'+data.username);
else
res.send(templates['header'] + '<script>templates.ready(function(){ajaxify.go("users/' + req.params.uid +'/'+data.username + '");});</script>' + templates['footer']);
} }
else { else {
res.send("User doesn't exist! /users/"+req.params.uid); res.send("User doesn't exist! /users/"+req.params.username);
} }
}); });
});
} }

Loading…
Cancel
Save