psychobunny 12 years ago
commit f608505cbb

@ -12,61 +12,74 @@
<span id="editLink" class="pull-right"><a href="/users/{username}/edit">edit</a></span>
</div>
<div class="account-picture-block">
<img src="{picture}" class="user-profile-picture"/>
</div>
<div class="row-fluid">
<div class="span3" style="text-align: center; margin-bottom:20px;">
<div class="account-picture-block">
<img src="{picture}" class="user-profile-picture"/>
</div>
</div>
<div class="account-bio-block">
<span class="account-bio-label">email</span>
<span>{email}</span>
<br/>
<span class="account-bio-label">full name</span>
<span>{fullname}</span>
<br/>
<span class="account-bio-label">website</span>
<span><a href="{website}">{website}</a></span>
<br/>
<span class="account-bio-label">location</span>
<span>{location}</span>
<br/>
<span class="account-bio-label">age</span>
<span>{age}</span>
<br/>
<span class="account-bio-label">member for</span>
<span>{joindate}</span>
<br/>
<div class="span9">
<div class="inline-block">
<div class="account-bio-block">
<span class="account-bio-label">email</span>
<span>{email}</span>
<br/>
<span class="account-bio-label">full name</span>
<span>{fullname}</span>
<br/>
<span class="account-bio-label">website</span>
<span><a href="{website}">{website}</a></span>
<br/>
<span class="account-bio-label">location</span>
<span>{location}</span>
<br/>
<span class="account-bio-label">age</span>
<span>{age}</span>
<br/>
<span class="account-bio-label">member for</span>
<span>{joindate}</span>
<br/>
<span class="account-bio-label">reputation</span>
<span id='reputation'>{reputation}</span>
<br/>
<span class="account-bio-label">posts</span>
<span id='postcount'>{postcount}</span>
<span class="account-bio-label">reputation</span>
<span id='reputation'>{reputation}</span>
<br/>
<span class="account-bio-label">posts</span>
<span id='postcount'>{postcount}</span>
</div>
</div>
</div>
</div>
<div id="user-actions" class="container">
<a id="add-friend-btn" href="#" class="btn">Add Friend</a>
<a id="send-message-btn" href="#" class="btn">Send Message</a>
</div>
<!-- END user -->
</div>
<script type="text/javascript">
var yourid = '{yourid}';
var theirid = '{theirid}';
(function() {
function addCommas(text) {
return text.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
}
$(document).ready(function() {
var rep = $('#reputation');
rep.html(addCommas(rep.html()));
@ -74,9 +87,32 @@ var theirid = '{theirid}';
postcount.html(addCommas(postcount.html()));
var editLink = $('#editLink');
if( yourid !== theirid)
editLink.addClass('hidden');
var addFriendBtn = $('#add-friend-btn');
var sendMessageBtn = $('#send-message-btn');
if( yourid !== theirid) {
editLink.hide();
addFriendBtn.show();
sendMessageBtn.show();
}
else {
addFriendBtn.hide();
sendMessageBtn.hide();
}
addFriendBtn.on('click', function() {
$.post('/users/addfriend', {uid: theirid},
function(data) {
}
);
return false;
});
sendMessageBtn.on('click', function() {
return false;
});
});

@ -80,7 +80,7 @@
<div class="span9">
<div class="inline-block">
<form class='form-horizontal'>
<div class="control-group">
<div class="control-group">
<label class="control-label" for="inputEmail">Email</label>
<div class="controls">
<input type="text" id="inputEmail" placeholder="Email" value="{email}">
@ -120,7 +120,7 @@
<div class="form-actions">
<a id="submitBtn" href="" class="btn btn-primary">Save changes</a>
<a href="/users/{username}" class="btn">Cancel</a>
</div>
</div>
</form>
</div>
@ -136,6 +136,8 @@ var uploadedPicture = '{uploadedpicture}';
$(document).ready(function() {
$('#uploadForm').submit(function() {
status('uploading the file ...');

@ -37,6 +37,9 @@
</li>
<li>
<a href="/active">Active</a>
</li>
<li>
<a href="/users">Users</a>
</li>
</ul>
<ul class="nav pull-right" id="right-menu">

@ -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) {

@ -102,8 +102,12 @@ var config = require('../config.js'),
RDB.keys('user:*', function(err, userkeys){
var anonUserIndex = userkeys.indexOf("user:0");
if(anonUserIndex !== -1) {
userkeys.splice(anonUserIndex, 1);
}
for(var i=0,ii=userkeys.length; i<ii; ++i) {
RDB.hgetall(userkeys[i], function(err, userdata) {
if(userdata && userdata.password)
@ -115,7 +119,6 @@ var config = require('../config.js'),
callback(data);
});
}
});
}
@ -351,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