why does urls dont work when put into address bar

v1.18.x
Baris Usakli 12 years ago
parent 4f0901e164
commit 233752a9c7

@ -101,6 +101,11 @@ var theirid = '{theirid}';
}
addFriendBtn.on('click', function() {
$.post('/users/addfriend', {uid: theirid},
function(data) {
}
);
return false;
});

@ -183,9 +183,35 @@ var user = require('./../user.js'),
res.send({});
});
app.post('/users/addfriend', function(req, res){
if(!req.user)
return res.redirect('/403');
if(req.user.uid == req.body.uid)
return res.redirect('/');
function api_method(req, res) {
user.addFriend(req.user.uid, req.body.uid, function(err, data) {
if(err)
res.send({error:err});
else
res.send(data);
});
});
app.get('/users/:username/friends', function(req, res){
if(!req.user)
return res.redirect('/403');
user.get_uid_by_username(req.params.username, function(uid) {
user.getFriends(uid, function(data) {
res.send(JSON.stringify(data, null, 0));
});
});
});
function api_method(req, res) {
console.log("fail "+req.params.section);
var callerUID = req.user?req.user.uid : 0;
if (!req.params.section && !req.params.username) {
@ -195,6 +221,9 @@ var user = require('./../user.js'),
res.send(JSON.stringify({users:data}));
});
}
else if(String(req.params.section).toLowerCase() === 'friends') {
}
else if (String(req.params.section).toLowerCase() === 'edit') {
getUserDataByUserName(req.params.username, callerUID, function(userData) {
@ -210,6 +239,8 @@ var user = require('./../user.js'),
app.get('/api/users/:username?/:section?', api_method);
function getUserDataByUserName(username, callerUID, callback) {
user.get_uid_by_username(username, function(uid) {

@ -354,6 +354,23 @@ var config = require('../config.js'),
});
}
User.addFriend = function(uid, friendid, callback) {
RDB.sadd('user:'+uid+':friends', friendid, function(err, data){
if(err === null)
callback(data);
else
console.log(err);
})
}
User.getFriends = function(uid, callback) {
RDB.smembers('user:'+uid+':friends', function(err, data){
if(err === null)
callback(data);
else
console.log(err);
});
}
User.exists = function(username, callback) {
User.get_uid_by_username(username, function(exists) {

Loading…
Cancel
Save