@@ -300,7 +300,8 @@ api.join = function(req, res, next) {
|
||||
group = res.locals.group;
|
||||
|
||||
if (group.type == 'party' && group._id == (user.invitations && user.invitations.party && user.invitations.party.id)) {
|
||||
user.invitations.party = undefined;
|
||||
User.update({_id:user.invitations.party.inviter}, {$inc:{'items.quests.basilist':1}}).exec(); // Reward inviter
|
||||
user.invitations.party = undefined; // Clear invite
|
||||
user.save();
|
||||
// invite new user to pending quest
|
||||
if (group.quest.key && !group.quest.active) {
|
||||
@@ -439,10 +440,10 @@ api.invite = function(req, res, next) {
|
||||
|
||||
function sendInvite (){
|
||||
if(group.type === 'guild'){
|
||||
invite.invitations.guilds.push({id: group._id, name: group.name});
|
||||
invite.invitations.guilds.push({id: group._id, name: group.name, inviter:res.locals.user._id});
|
||||
}else{
|
||||
//req.body.type in 'guild', 'party'
|
||||
invite.invitations.party = {id: group._id, name: group.name}
|
||||
invite.invitations.party = {id: group._id, name: group.name, inviter:res.locals.user._id};
|
||||
}
|
||||
|
||||
group.invites.push(invite._id);
|
||||
|
||||
+37
-1
@@ -7,13 +7,15 @@ var nconf = require('nconf');
|
||||
var async = require('async');
|
||||
var shared = require('habitrpg-shared');
|
||||
var User = require('./../models/user').model;
|
||||
var ga = require('./../utils').ga;
|
||||
var utils = require('./../utils');
|
||||
var ga = utils.ga;
|
||||
var Group = require('./../models/group').model;
|
||||
var Challenge = require('./../models/challenge').model;
|
||||
var moment = require('moment');
|
||||
var logging = require('./../logging');
|
||||
var acceptablePUTPaths;
|
||||
var api = module.exports;
|
||||
var qs = require('qs');
|
||||
|
||||
// api.purchase // Shared.ops
|
||||
|
||||
@@ -393,6 +395,40 @@ api.cast = function(req, res, next) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /user/invite-friends
|
||||
*/
|
||||
api.inviteFriends = function(req, res, next) {
|
||||
Group.findOne({type:'party', members:{'$in': [res.locals.user._id]}}).select('_id name').exec(function(err,party){
|
||||
if (err) return next(err);
|
||||
var link = nconf.get('BASE_URL') + '?' + qs.stringify({partyInvite:{id:party._id, inviter:res.locals.user._id, name:party.name}});
|
||||
_.each(req.body, function(invite){
|
||||
if (invite.email) {
|
||||
var variables = [
|
||||
{name: 'LINK', content: link},
|
||||
{name: 'INVITER', content: res.locals.user.profile.name},
|
||||
{name: 'INVITEE', content: invite.name}
|
||||
];
|
||||
// TODO implement "users can only be invited once"
|
||||
utils.txnEmail(invite, 'invite-friend', variables);
|
||||
}
|
||||
});
|
||||
res.send(200);
|
||||
})
|
||||
}
|
||||
api.sessionPartyInvite = function(req,res,next){
|
||||
if (req.session.partyInvite) {
|
||||
var inv = res.locals.user.invitations;
|
||||
if (!(inv.party && inv.party.id)) {
|
||||
inv.party = req.session.partyInvite;
|
||||
Group.update({_id:req.session.partyInvite.id},{$addToSet:{invites:res.locals.user._id}});
|
||||
delete req.session.partyInvite;
|
||||
return res.locals.user.save(next);
|
||||
}
|
||||
}
|
||||
next();
|
||||
}
|
||||
|
||||
/**
|
||||
* All other user.ops which can easily be mapped to habitrpg-shared/index.coffee, not requiring custom API-wrapping
|
||||
*/
|
||||
|
||||
+7
-1
@@ -12,6 +12,7 @@ var shared = require('habitrpg-shared');
|
||||
var request = require('request');
|
||||
var os = require('os');
|
||||
var moment = require('moment');
|
||||
var qs = require('qs');
|
||||
|
||||
module.exports.apiThrottle = function(app) {
|
||||
if (nconf.get('NODE_ENV') !== 'production') return;
|
||||
@@ -196,7 +197,12 @@ module.exports.locals = function(req, res, next) {
|
||||
|
||||
tavern: tavern, // for world boss
|
||||
worldDmg: (tavern && tavern.quest && tavern.quest.extra && tavern.quest.extra.worldDmg) || {}
|
||||
}
|
||||
};
|
||||
|
||||
// Put query-string party invitations into session to be handled later
|
||||
var partyInvite = qs.parse(req.query.partyInvite);
|
||||
if (partyInvite && partyInvite.id)
|
||||
req.session.partyInvite = partyInvite;
|
||||
|
||||
next();
|
||||
}
|
||||
|
||||
+10
-1
@@ -320,7 +320,7 @@ module.exports = (swagger, v2) ->
|
||||
parameters:[
|
||||
body '','The array of batch-operations to perform','object'
|
||||
]
|
||||
middleware: [middleware.forceRefresh, auth.auth, i18n.getUserLanguage, cron]
|
||||
middleware: [middleware.forceRefresh, auth.auth, i18n.getUserLanguage, cron, user.sessionPartyInvite]
|
||||
action: user.batchUpdate
|
||||
|
||||
# Tags
|
||||
@@ -364,6 +364,15 @@ module.exports = (swagger, v2) ->
|
||||
]
|
||||
action: user.deleteTag
|
||||
|
||||
"/user/social/invite-friends":
|
||||
spec:
|
||||
method: 'POST'
|
||||
description: 'Invite friends via email'
|
||||
parameters: [
|
||||
body 'invites','Array of [{name:"Friend\'s Name", email:"friends@email.com"}] to invite to play in your party','object'
|
||||
]
|
||||
action: user.inviteFriends
|
||||
|
||||
# ---------------------------------
|
||||
# Groups
|
||||
# ---------------------------------
|
||||
|
||||
Reference in New Issue
Block a user