Merge branch 'develop' of https://github.com/HabitRPG/habitrpg into develop
This commit is contained in:
@@ -88,6 +88,8 @@ api.registerUser = function(req, res, next) {
|
||||
timestamps: {created: +new Date(), loggedIn: +new Date()}
|
||||
}
|
||||
};
|
||||
newUser.preferences = newUser.preferences || {};
|
||||
newUser.preferences.language = req.language; // User language detected from browser, not saved
|
||||
user = new User(newUser);
|
||||
|
||||
// temporary for conventions
|
||||
@@ -255,7 +257,11 @@ api.setupPassport = function(router) {
|
||||
},
|
||||
function(user, cb){
|
||||
if (user) return cb(null, user);
|
||||
|
||||
user = new User({
|
||||
preferences: {
|
||||
language: req.language // User language detected from browser, not saved
|
||||
},
|
||||
auth: {
|
||||
facebook: req.user,
|
||||
timestamps: {created: +new Date(), loggedIn: +new Date()}
|
||||
|
||||
@@ -76,7 +76,7 @@ api.score = function(req, res, next) {
|
||||
if (task.type === 'daily' || task.type === 'todo')
|
||||
task.completed = direction === 'up';
|
||||
}
|
||||
var delta = user.ops.score({params:{id:task.id, direction:direction}});
|
||||
var delta = user.ops.score({params:{id:task.id, direction:direction}, language: req.language});
|
||||
|
||||
user.save(function(err,saved){
|
||||
if (err) return next(err);
|
||||
@@ -336,7 +336,7 @@ api.cast = function(req, res, next) {
|
||||
|
||||
if (group) {
|
||||
series.push(function(cb2){
|
||||
var message = '`'+user.profile.name+' casts '+spell.text + (targetType=='user' ? ' on '+found.profile.name : ' for the party')+'.`';
|
||||
var message = '`'+user.profile.name+' casts '+spell.text() + (targetType=='user' ? ' on '+found.profile.name : ' for the party')+'.`';
|
||||
group.sendChat(message);
|
||||
group.save(cb2);
|
||||
})
|
||||
@@ -397,6 +397,8 @@ api.batchUpdate = function(req, res, next) {
|
||||
res.locals.ops = [];
|
||||
var ops = _.transform(req.body, function(m,_req){
|
||||
if (_.isEmpty(_req)) return;
|
||||
_req.language = req.language;
|
||||
|
||||
m.push(function() {
|
||||
var cb = arguments[arguments.length-1];
|
||||
res.locals.ops.push(_req);
|
||||
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
var fs = require('fs'),
|
||||
path = require('path'),
|
||||
_ = require('lodash'),
|
||||
User = require('./models/user').model,
|
||||
shared = require('habitrpg-shared'),
|
||||
translations = {};
|
||||
|
||||
var loadTranslations = function(locale){
|
||||
var files = fs.readdirSync(path.join(__dirname, "/../node_modules/habitrpg-shared/locales/", locale));
|
||||
translations[locale] = {};
|
||||
_.each(files, function(file){
|
||||
_.merge(translations[locale], require(path.join(__dirname, "/../node_modules/habitrpg-shared/locales/", locale, file)));
|
||||
});
|
||||
};
|
||||
|
||||
// First fetch english so we can merge with missing strings in other languages
|
||||
loadTranslations('en');
|
||||
|
||||
fs.readdirSync(path.join(__dirname, "/../node_modules/habitrpg-shared/locales/")).forEach(function(file) {
|
||||
if(file === 'en' || file === 'README.md') return;
|
||||
loadTranslations(file);
|
||||
// Merge missing strings from english
|
||||
_.defaults(translations[file], translations.en);
|
||||
});
|
||||
|
||||
var langCodes = Object.keys(translations);
|
||||
|
||||
var avalaibleLanguages = _.map(langCodes, function(langCode){
|
||||
return {
|
||||
code: langCode,
|
||||
name: translations[langCode].languageName
|
||||
}
|
||||
});
|
||||
|
||||
// Load MomentJS localization files
|
||||
var momentLangs = {};
|
||||
|
||||
// Handle different language codes from MomentJS and /locales
|
||||
var momentLangsMapping = {
|
||||
'en': 'en-gb',
|
||||
'no': 'nn'
|
||||
};
|
||||
|
||||
var momentLangs = {};
|
||||
|
||||
_.each(langCodes, function(code){
|
||||
var lang = _.find(avalaibleLanguages, {code: code});
|
||||
lang.momentLangCode = (momentLangsMapping[code] || code);
|
||||
try{
|
||||
// MomentJS lang files are JS files that has to be executed in the browser so we load them as plain text files
|
||||
var f = fs.readFileSync(path.join(__dirname, '/../node_modules/moment/lang/' + lang.momentLangCode + '.js'), 'utf8');
|
||||
momentLangs[code] = f;
|
||||
}catch (e){}
|
||||
});
|
||||
|
||||
var getUserLanguage = function(req, res, next){
|
||||
var getFromBrowser = function(){
|
||||
var acceptable = _(req.acceptedLanguages).map(function(lang){
|
||||
return lang.slice(0, 2);
|
||||
}).uniq().value();
|
||||
var matches = _.intersection(acceptable, langCodes);
|
||||
return matches.length > 0 ? matches[0] : 'en';
|
||||
};
|
||||
|
||||
var getFromUser = function(user){
|
||||
var lang;
|
||||
if(user && user.preferences.language && translations[user.preferences.language]){
|
||||
lang = user.preferences.language;
|
||||
}else{
|
||||
var preferred = getFromBrowser();
|
||||
lang = translations[preferred] ? preferred : 'en';
|
||||
}
|
||||
req.language = lang;
|
||||
next();
|
||||
};
|
||||
|
||||
if(req.locals && req.locals.user){
|
||||
getFromUser(req.locals.user);
|
||||
}else if(req.session && req.session.userId){
|
||||
User.findOne({_id: req.session.userId}, function(err, user){
|
||||
if(err) return callback(err);
|
||||
getFromUser(user);
|
||||
});
|
||||
}else{
|
||||
getFromUser(null);
|
||||
}
|
||||
};
|
||||
|
||||
shared.i18n.translations = translations;
|
||||
|
||||
module.exports = {
|
||||
translations: translations,
|
||||
avalaibleLanguages: avalaibleLanguages,
|
||||
langCodes: langCodes,
|
||||
getUserLanguage: getUserLanguage,
|
||||
momentLangs: momentLangs
|
||||
};
|
||||
+26
-111
@@ -7,6 +7,8 @@ var limiter = require('connect-ratelimit');
|
||||
var logging = require('./logging');
|
||||
var domainMiddleware = require('domain-middleware');
|
||||
var cluster = require('cluster');
|
||||
var i18n = require('./i18n.js');
|
||||
var shared = require('habitrpg-shared');
|
||||
|
||||
module.exports.apiThrottle = function(app) {
|
||||
if (nconf.get('NODE_ENV') !== 'production') return;
|
||||
@@ -139,121 +141,34 @@ var getManifestFiles = function(page){
|
||||
return code;
|
||||
}
|
||||
|
||||
// Translations
|
||||
|
||||
var translations = {};
|
||||
|
||||
var loadTranslations = function(locale){
|
||||
var files = fs.readdirSync(path.join(__dirname, "/../node_modules/habitrpg-shared/locales/", locale));
|
||||
translations[locale] = {};
|
||||
_.each(files, function(file){
|
||||
_.merge(translations[locale], require(path.join(__dirname, "/../node_modules/habitrpg-shared/locales/", locale, file)));
|
||||
});
|
||||
};
|
||||
|
||||
// First fetch english so we can merge with missing strings in other languages
|
||||
loadTranslations('en');
|
||||
|
||||
fs.readdirSync(path.join(__dirname, "/../node_modules/habitrpg-shared/locales/")).forEach(function(file) {
|
||||
if(file === 'en') return;
|
||||
loadTranslations(file);
|
||||
// Merge missing strings from english
|
||||
_.defaults(translations[file], translations.en);
|
||||
});
|
||||
|
||||
var langCodes = Object.keys(translations);
|
||||
|
||||
var avalaibleLanguages = _.map(langCodes, function(langCode){
|
||||
return {
|
||||
code: langCode,
|
||||
name: translations[langCode].languageName
|
||||
}
|
||||
});
|
||||
|
||||
// Load MomentJS localization files
|
||||
var momentLangs = {};
|
||||
|
||||
// Handle different language codes from MomentJS and /locales
|
||||
var momentLangsMapping = {
|
||||
'en': 'en-gb',
|
||||
'no': 'nn'
|
||||
};
|
||||
|
||||
var momentLangs = {};
|
||||
|
||||
_.each(langCodes, function(code){
|
||||
var lang = _.find(avalaibleLanguages, {code: code});
|
||||
lang.momentLangCode = (momentLangsMapping[code] || code);
|
||||
try{
|
||||
// MomentJS lang files are JS files that has to be executed in the browser so we load them as plain text files
|
||||
var f = fs.readFileSync(path.join(__dirname, '/../node_modules/moment/lang/' + lang.momentLangCode + '.js'), 'utf8');
|
||||
momentLangs[code] = f;
|
||||
}catch (e){}
|
||||
});
|
||||
|
||||
var getUserLanguage = function(req, callback){
|
||||
var getFromBrowser = function(){
|
||||
var acceptable = _(req.acceptedLanguages).map(function(lang){
|
||||
return lang.slice(0, 2);
|
||||
}).uniq().value();
|
||||
var matches = _.intersection(acceptable, langCodes);
|
||||
return matches.length > 0 ? matches[0] : 'en';
|
||||
};
|
||||
|
||||
if(req.session && req.session.userId){
|
||||
User.findOne({_id: req.session.userId}, function(err, user){
|
||||
if(err) return callback(err);
|
||||
if(user && user.preferences.language && translations[user.preferences.language]){
|
||||
return callback(null, _.find(avalaibleLanguages, {code: user.preferences.language}));
|
||||
}else{
|
||||
var langCode = getFromBrowser();
|
||||
// Because english is usually always avalaible as an acceptable language for the browser,
|
||||
// if the user visit the page when his own language is not avalaible yet
|
||||
// he'll have english set in his preferences, which is not good.
|
||||
//if(user && translations[langCode]){
|
||||
//user.preferences.language = langCode;
|
||||
//user.save(); //callback?
|
||||
//}
|
||||
return callback(null, _.find(avalaibleLanguages, {code: langCode}))
|
||||
}
|
||||
});
|
||||
}else{
|
||||
return callback(null, _.find(avalaibleLanguages, {code: getFromBrowser()}));
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.locals = function(req, res, next) {
|
||||
getUserLanguage(req, function(err, language){
|
||||
if(err) return res.json(500, {err: err});
|
||||
var language = _.find(i18n.avalaibleLanguages, {code: req.language});
|
||||
var isStaticPage = req.url.split('/')[1] === 'static'; // If url contains '/static/'
|
||||
|
||||
var isStaticPage = req.url.split('/')[1] === 'static'; // If url contains '/static/'
|
||||
// Load moment.js language file only when not on static pages
|
||||
language.momentLang = ((!isStaticPage && i18n.momentLangs[language.code]) || undefined);
|
||||
|
||||
// Load moment.js language file only when not on static pages
|
||||
language.momentLang = ((!isStaticPage && momentLangs[language.code])|| undefined);
|
||||
res.locals.habitrpg = {
|
||||
NODE_ENV: nconf.get('NODE_ENV'),
|
||||
BASE_URL: nconf.get('BASE_URL'),
|
||||
GA_ID: nconf.get("GA_ID"),
|
||||
IS_MOBILE: /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(req.header('User-Agent')),
|
||||
STRIPE_PUB_KEY: nconf.get('STRIPE_PUB_KEY'),
|
||||
getManifestFiles: getManifestFiles,
|
||||
getBuildUrl: getBuildUrl,
|
||||
avalaibleLanguages: i18n.avalaibleLanguages,
|
||||
language: language,
|
||||
isStaticPage: isStaticPage,
|
||||
translations: i18n.translations[language.code],
|
||||
t: function(){ // stringName and vars are the allowed parameters
|
||||
var args = Array.prototype.slice.call(arguments, 0);
|
||||
args.push(language.code);
|
||||
return shared.i18n.t.apply(null, args);
|
||||
},
|
||||
siteVersion: siteVersion
|
||||
}
|
||||
|
||||
res.locals.habitrpg = {
|
||||
NODE_ENV: nconf.get('NODE_ENV'),
|
||||
BASE_URL: nconf.get('BASE_URL'),
|
||||
GA_ID: nconf.get("GA_ID"),
|
||||
IS_MOBILE: /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(req.header('User-Agent')),
|
||||
STRIPE_PUB_KEY: nconf.get('STRIPE_PUB_KEY'),
|
||||
getManifestFiles: getManifestFiles,
|
||||
getBuildUrl: getBuildUrl,
|
||||
avalaibleLanguages: avalaibleLanguages,
|
||||
language: language,
|
||||
isStaticPage: isStaticPage,
|
||||
translations: translations[language.code],
|
||||
t: function(stringName, vars){
|
||||
var string = translations[language.code][stringName];
|
||||
if(!string) return _.template(translations[language.code].stringNotFound, {string: stringName});
|
||||
|
||||
return vars === undefined ? string : _.template(string, vars);
|
||||
},
|
||||
siteVersion: siteVersion
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
next();
|
||||
}
|
||||
|
||||
module.exports.enTranslations = function(stringName, vars){
|
||||
|
||||
+30
-5
@@ -305,14 +305,14 @@ var UserSchema = new Schema({
|
||||
id: { type: String, 'default': shared.uuid },
|
||||
name: String,
|
||||
challenge: String
|
||||
}], 'default': shared.content.userDefaults.tags},
|
||||
}]},
|
||||
|
||||
challenges: [{type: 'String', ref:'Challenge'}],
|
||||
|
||||
habits: {type:[TaskSchemas.HabitSchema], 'default': shared.content.userDefaults.habits},
|
||||
dailys: {type:[TaskSchemas.DailySchema], 'default': shared.content.userDefaults.dailys},
|
||||
todos: {type:[TaskSchemas.TodoSchema], 'default': shared.content.userDefaults.todos},
|
||||
rewards: {type:[TaskSchemas.RewardSchema], 'default': shared.content.userDefaults.rewards},
|
||||
habits: {type:[TaskSchemas.HabitSchema]},
|
||||
dailys: {type:[TaskSchemas.DailySchema]},
|
||||
todos: {type:[TaskSchemas.TodoSchema]},
|
||||
rewards: {type:[TaskSchemas.RewardSchema]},
|
||||
|
||||
extra: Schema.Types.Mixed
|
||||
|
||||
@@ -348,6 +348,31 @@ UserSchema.post('init', function(doc){
|
||||
|
||||
UserSchema.pre('save', function(next) {
|
||||
|
||||
// Populate new users with default content
|
||||
if (this.isNew){
|
||||
//TODO for some reason this doesn't work here: `_.merge(this, shared.content.userDefaults);`
|
||||
var self = this;
|
||||
_.each(['habits', 'dailys', 'todos', 'rewards', 'tags'], function(taskType){
|
||||
self[taskType] = _.map(shared.content.userDefaults[taskType], function(task){
|
||||
var newTask = task;
|
||||
|
||||
// Render task's text and notes in user's language
|
||||
if(taskType === 'tags'){
|
||||
// tasks automatically get id=helpers.uuid() from TaskSchema id.default, but tags are Schema.Types.Mixed - so we need to manually invoke here
|
||||
newTask.id = shared.uuid();
|
||||
newTask.name = task.name(self.preferences.language);
|
||||
}else{
|
||||
newTask.text = task.text(self.preferences.language);
|
||||
newTask.notes = task.notes(self.preferences.language);
|
||||
}
|
||||
|
||||
return newTask;
|
||||
});
|
||||
});
|
||||
|
||||
this.preferences.language = undefined;
|
||||
}
|
||||
|
||||
//this.markModified('tasks');
|
||||
if (_.isNaN(this.preferences.dayStart) || this.preferences.dayStart < 0 || this.preferences.dayStart > 23) {
|
||||
this.preferences.dayStart = 0;
|
||||
|
||||
+34
-33
@@ -19,6 +19,7 @@ middleware = require("../middleware")
|
||||
cron = user.cron
|
||||
_ = require('lodash')
|
||||
content = require('habitrpg-shared').content
|
||||
i18n = require('../i18n')
|
||||
|
||||
|
||||
module.exports = (swagger, v2) ->
|
||||
@@ -47,7 +48,7 @@ module.exports = (swagger, v2) ->
|
||||
spec:
|
||||
description: "Export user history"
|
||||
method: 'GET'
|
||||
middleware: auth.auth
|
||||
middleware: [auth.auth, i18n.getUserLanguage]
|
||||
action: dataexport.history #[todo] encode data output options in the data controller and use these to build routes
|
||||
|
||||
# ---------------------------------
|
||||
@@ -138,7 +139,7 @@ module.exports = (swagger, v2) ->
|
||||
path("id", "Task ID", "string")
|
||||
query 'keep',"When unlinking a challenge task, how to handle the orphans?",'string',['keep','keep-all','remove','remove-all']
|
||||
]
|
||||
middleware: auth.auth ## removing cron since they may want to remove task first
|
||||
middleware: [auth.auth, i18n.getUserLanguage] ## removing cron since they may want to remove task first
|
||||
action: challenges.unlink
|
||||
|
||||
|
||||
@@ -227,7 +228,7 @@ module.exports = (swagger, v2) ->
|
||||
path: '/user'
|
||||
method: 'DELETE'
|
||||
description: "Delete a user object entirely, USE WITH CAUTION!"
|
||||
middleware: auth.auth
|
||||
middleware: [auth.auth, i18n.getUserLanguage]
|
||||
action: user["delete"]
|
||||
|
||||
"/user/revive":
|
||||
@@ -306,7 +307,7 @@ module.exports = (swagger, v2) ->
|
||||
parameters:[
|
||||
body '','The array of batch-operations to perform','object'
|
||||
]
|
||||
middleware: [middleware.forceRefresh, auth.auth, cron]
|
||||
middleware: [middleware.forceRefresh, auth.auth, i18n.getUserLanguage, cron]
|
||||
action: user.batchUpdate
|
||||
|
||||
# Tags
|
||||
@@ -350,7 +351,7 @@ module.exports = (swagger, v2) ->
|
||||
parameters: [
|
||||
query 'type',"Comma-separated types of groups to return, eg 'party,guilds,public,tavern'",'string'
|
||||
]
|
||||
middleware: auth.auth
|
||||
middleware: [auth.auth, i18n.getUserLanguage]
|
||||
action: groups.list
|
||||
|
||||
|
||||
@@ -362,7 +363,7 @@ module.exports = (swagger, v2) ->
|
||||
parameters: [
|
||||
body '','Group object (see GroupSchema)','object'
|
||||
]
|
||||
middleware: auth.auth
|
||||
middleware: [auth.auth, i18n.getUserLanguage]
|
||||
action: groups.create
|
||||
|
||||
"/groups/{gid}:GET":
|
||||
@@ -370,7 +371,7 @@ module.exports = (swagger, v2) ->
|
||||
path: '/groups/{gid}'
|
||||
description: "Get a group"
|
||||
parameters: [path('gid','Group ID','string')]
|
||||
middleware: auth.auth
|
||||
middleware: [auth.auth, i18n.getUserLanguage]
|
||||
action: groups.get
|
||||
|
||||
"/groups/{gid}:POST":
|
||||
@@ -379,7 +380,7 @@ module.exports = (swagger, v2) ->
|
||||
method: 'POST'
|
||||
description: "Edit a group"
|
||||
parameters: [body('','Group object (see GroupSchema)','object')]
|
||||
middleware: [auth.auth, groups.attachGroup]
|
||||
middleware: [auth.auth, i18n.getUserLanguage, groups.attachGroup]
|
||||
action: groups.update
|
||||
|
||||
"/groups/{gid}/join":
|
||||
@@ -387,7 +388,7 @@ module.exports = (swagger, v2) ->
|
||||
method: 'POST'
|
||||
description: 'Join a group'
|
||||
parameters: [path('gid','Id of the group to join','string')]
|
||||
middleware: [auth.auth, groups.attachGroup]
|
||||
middleware: [auth.auth, i18n.getUserLanguage, groups.attachGroup]
|
||||
action: groups.join
|
||||
|
||||
"/groups/{gid}/leave":
|
||||
@@ -395,7 +396,7 @@ module.exports = (swagger, v2) ->
|
||||
method: 'POST'
|
||||
description: 'Leave a group'
|
||||
parameters: [path('gid','ID of the group to leave','string')]
|
||||
middleware: [auth.auth, groups.attachGroup]
|
||||
middleware: [auth.auth, i18n.getUserLanguage, groups.attachGroup]
|
||||
action: groups.leave
|
||||
|
||||
"/groups/{gid}/invite":
|
||||
@@ -406,7 +407,7 @@ module.exports = (swagger, v2) ->
|
||||
path 'gid','Group id','string'
|
||||
query 'uuid','User id to invite','string'
|
||||
]
|
||||
middleware: [auth.auth, groups.attachGroup]
|
||||
middleware: [auth.auth, i18n.getUserLanguage, groups.attachGroup]
|
||||
action:groups.invite
|
||||
|
||||
"/groups/{gid}/removeMember":
|
||||
@@ -417,7 +418,7 @@ module.exports = (swagger, v2) ->
|
||||
path 'gid','Group id','string'
|
||||
query 'uuid','User id to boot','string'
|
||||
]
|
||||
middleware: [auth.auth, groups.attachGroup]
|
||||
middleware: [auth.auth, i18n.getUserLanguage, groups.attachGroup]
|
||||
action:groups.removeMember
|
||||
|
||||
"/groups/{gid}/questAccept":
|
||||
@@ -428,7 +429,7 @@ module.exports = (swagger, v2) ->
|
||||
path 'gid',"Group id",'string'
|
||||
query 'key',"optional. if provided, trigger new invite, if not, accept existing invite",'string'
|
||||
]
|
||||
middleware: [auth.auth, groups.attachGroup]
|
||||
middleware: [auth.auth, i18n.getUserLanguage, groups.attachGroup]
|
||||
action:groups.questAccept
|
||||
|
||||
"/groups/{gid}/questReject":
|
||||
@@ -438,7 +439,7 @@ module.exports = (swagger, v2) ->
|
||||
parameters: [
|
||||
path 'gid','Group id','string'
|
||||
]
|
||||
middleware: [auth.auth, groups.attachGroup]
|
||||
middleware: [auth.auth, i18n.getUserLanguage, groups.attachGroup]
|
||||
action: groups.questReject
|
||||
|
||||
"/groups/{gid}/questAbort":
|
||||
@@ -446,7 +447,7 @@ module.exports = (swagger, v2) ->
|
||||
method: 'POST'
|
||||
description: 'Abort quest'
|
||||
parameters: [path('gid','Group to abort quest in','string')]
|
||||
middleware: [auth.auth, groups.attachGroup]
|
||||
middleware: [auth.auth, i18n.getUserLanguage, groups.attachGroup]
|
||||
action: groups.questAbort
|
||||
|
||||
#TODO PUT /groups/:gid/chat/:messageId
|
||||
@@ -456,7 +457,7 @@ module.exports = (swagger, v2) ->
|
||||
path: "/groups/{gid}/chat"
|
||||
description: "Get all chat messages"
|
||||
parameters: [path('gid','Group to return the chat from ','string')]
|
||||
middleware: [auth.auth, groups.attachGroup]
|
||||
middleware: [auth.auth, i18n.getUserLanguage, groups.attachGroup]
|
||||
action: groups.getChat
|
||||
|
||||
|
||||
@@ -469,7 +470,7 @@ module.exports = (swagger, v2) ->
|
||||
query 'message', 'Chat message','string'
|
||||
path 'gid','Group id','string'
|
||||
]
|
||||
middleware: [auth.auth, groups.attachGroup]
|
||||
middleware: [auth.auth, i18n.getUserLanguage, groups.attachGroup]
|
||||
action: groups.postChat
|
||||
|
||||
# placing before route below, so that if !=='seen' it goes to next()
|
||||
@@ -480,7 +481,7 @@ module.exports = (swagger, v2) ->
|
||||
parameters: [
|
||||
path 'gid','Group id','string'
|
||||
]
|
||||
middleware: []
|
||||
middleware: [i18n.getUserLanguage]
|
||||
action: groups.seenMessage
|
||||
|
||||
"/groups/{gid}/chat/{messageId}":
|
||||
@@ -488,7 +489,7 @@ module.exports = (swagger, v2) ->
|
||||
method: 'DELETE'
|
||||
description: 'Delete a group'
|
||||
parameters: [path('gid','ID of group to delete','string')]
|
||||
middleware: [auth.auth, groups.attachGroup]
|
||||
middleware: [auth.auth, i18n.getUserLanguage, groups.attachGroup]
|
||||
action: groups.deleteChatMessage
|
||||
|
||||
"/groups/{gid}/chat/{mid}/like":
|
||||
@@ -499,7 +500,7 @@ module.exports = (swagger, v2) ->
|
||||
path 'gid','Group id','string'
|
||||
path 'mid','Message id','string'
|
||||
]
|
||||
middleware: [auth.auth, groups.attachGroup]
|
||||
middleware: [auth.auth, i18n.getUserLanguage, groups.attachGroup]
|
||||
action: groups.likeChatMessage
|
||||
|
||||
# ---------------------------------
|
||||
@@ -514,19 +515,19 @@ module.exports = (swagger, v2) ->
|
||||
# ---------------------------------
|
||||
"/hall/heroes":
|
||||
spec: {}
|
||||
middleware:[auth.auth]
|
||||
middleware:[auth.auth, i18n.getUserLanguage]
|
||||
action: hall.getHeroes
|
||||
|
||||
"/hall/heroes/{uid}:GET":
|
||||
spec: path: "/hall/heroes/{uid}"
|
||||
middleware:[auth.auth, hall.ensureAdmin]
|
||||
middleware:[auth.auth, i18n.getUserLanguage, hall.ensureAdmin]
|
||||
action: hall.getHero
|
||||
|
||||
"/hall/heroes/{uid}:POST":
|
||||
spec:
|
||||
method: 'POST'
|
||||
path: "/hall/heroes/{uid}"
|
||||
middleware: [auth.auth, hall.ensureAdmin]
|
||||
middleware: [auth.auth, i18n.getUserLanguage, hall.ensureAdmin]
|
||||
action: hall.updateHero
|
||||
|
||||
"/hall/patrons":
|
||||
@@ -534,7 +535,7 @@ module.exports = (swagger, v2) ->
|
||||
parameters: [
|
||||
query 'page','Page number to fetch (this list is long)','string'
|
||||
]
|
||||
middleware:[auth.auth]
|
||||
middleware:[auth.auth, i18n.getUserLanguage]
|
||||
action: hall.getPatrons
|
||||
|
||||
|
||||
@@ -549,7 +550,7 @@ module.exports = (swagger, v2) ->
|
||||
spec:
|
||||
path: '/challenges'
|
||||
description: "Get a list of challenges"
|
||||
middleware: [auth.auth]
|
||||
middleware: [auth.auth, i18n.getUserLanguage]
|
||||
action: challenges.list
|
||||
|
||||
|
||||
@@ -559,7 +560,7 @@ module.exports = (swagger, v2) ->
|
||||
method: 'POST'
|
||||
description: "Create a challenge"
|
||||
parameters: [body('','Challenge object (see ChallengeSchema)','object')]
|
||||
middleware: [auth.auth]
|
||||
middleware: [auth.auth, i18n.getUserLanguage]
|
||||
action: challenges.create
|
||||
|
||||
"/challenges/{cid}:GET":
|
||||
@@ -584,7 +585,7 @@ module.exports = (swagger, v2) ->
|
||||
path 'cid','Challenge id','string'
|
||||
body('','Challenge object (see ChallengeSchema)','object')
|
||||
]
|
||||
middleware: [auth.auth]
|
||||
middleware: [auth.auth, i18n.getUserLanguage]
|
||||
action: challenges.update
|
||||
|
||||
"/challenges/{cid}:DELETE":
|
||||
@@ -593,7 +594,7 @@ module.exports = (swagger, v2) ->
|
||||
method: 'DELETE'
|
||||
description: "Delete a challenge"
|
||||
parameters: [path('cid','Challenge id','string')]
|
||||
middleware: [auth.auth]
|
||||
middleware: [auth.auth, i18n.getUserLanguage]
|
||||
action: challenges["delete"]
|
||||
|
||||
"/challenges/{cid}/close":
|
||||
@@ -604,7 +605,7 @@ module.exports = (swagger, v2) ->
|
||||
path 'cid','Challenge id','string'
|
||||
query 'uid','User ID of the winner','string',true
|
||||
]
|
||||
middleware: [auth.auth]
|
||||
middleware: [auth.auth, i18n.getUserLanguage]
|
||||
action: challenges.selectWinner
|
||||
|
||||
"/challenges/{cid}/join":
|
||||
@@ -612,7 +613,7 @@ module.exports = (swagger, v2) ->
|
||||
method: 'POST'
|
||||
description: "Join a challenge"
|
||||
parameters: [path('cid','Challenge id','string')]
|
||||
middleware: [auth.auth]
|
||||
middleware: [auth.auth, i18n.getUserLanguage]
|
||||
action: challenges.join
|
||||
|
||||
"/challenges/{cid}/leave":
|
||||
@@ -620,7 +621,7 @@ module.exports = (swagger, v2) ->
|
||||
method: 'POST'
|
||||
description: 'Leave a challenge'
|
||||
parameters: [path('cid','Challenge id','string')]
|
||||
middleware: [auth.auth]
|
||||
middleware: [auth.auth, i18n.getUserLanguage]
|
||||
action: challenges.leave
|
||||
|
||||
"/challenges/{cid}/member/{uid}":
|
||||
@@ -630,7 +631,7 @@ module.exports = (swagger, v2) ->
|
||||
path 'cid','Challenge id','string'
|
||||
path 'uid','User id','string'
|
||||
]
|
||||
middleware: [auth.auth]
|
||||
middleware: [auth.auth, i18n.getUserLanguage]
|
||||
action: challenges.getMember
|
||||
|
||||
|
||||
@@ -662,7 +663,7 @@ module.exports = (swagger, v2) ->
|
||||
#type: 'Pet'
|
||||
errorResponses: []
|
||||
method: 'GET'
|
||||
route.middleware ?= if path.indexOf('/user') is 0 then [auth.auth, cron] else []
|
||||
route.middleware ?= if path.indexOf('/user') is 0 then [auth.auth, i18n.getUserLanguage, cron] else []
|
||||
swagger["add#{route.spec.method}"](route);true
|
||||
|
||||
|
||||
|
||||
+9
-8
@@ -1,17 +1,18 @@
|
||||
var auth = require('../controllers/auth');
|
||||
var express = require('express');
|
||||
var i18n = require('../i18n');
|
||||
var router = new express.Router();
|
||||
|
||||
/* auth.auth*/
|
||||
auth.setupPassport(router); //FIXME make this consistent with the others
|
||||
router.post('/api/v2/register', auth.registerUser);
|
||||
router.post('/api/v2/user/auth/local', auth.loginLocal);
|
||||
router.post('/api/v2/user/auth/facebook', auth.loginFacebook);
|
||||
router.post('/api/v2/user/reset-password', auth.resetPassword);
|
||||
router.post('/api/v2/user/change-password', auth.auth, auth.changePassword);
|
||||
router.post('/api/v2/register', i18n.getUserLanguage, auth.registerUser);
|
||||
router.post('/api/v2/user/auth/local', i18n.getUserLanguage, auth.loginLocal);
|
||||
router.post('/api/v2/user/auth/facebook', i18n.getUserLanguage, auth.loginFacebook);
|
||||
router.post('/api/v2/user/reset-password', i18n.getUserLanguage, auth.resetPassword);
|
||||
router.post('/api/v2/user/change-password', i18n.getUserLanguage, auth.auth, auth.changePassword);
|
||||
|
||||
router.post('/api/v1/register', auth.registerUser);
|
||||
router.post('/api/v1/user/auth/local', auth.loginLocal);
|
||||
router.post('/api/v1/user/auth/facebook', auth.loginFacebook);
|
||||
router.post('/api/v1/register', i18n.getUserLanguage, auth.registerUser);
|
||||
router.post('/api/v1/user/auth/local', i18n.getUserLanguage, auth.loginLocal);
|
||||
router.post('/api/v1/user/auth/facebook', i18n.getUserLanguage, auth.loginFacebook);
|
||||
|
||||
module.exports = router;
|
||||
@@ -3,10 +3,11 @@ var router = new express.Router();
|
||||
var dataexport = require('../controllers/dataexport');
|
||||
var auth = require('../controllers/auth');
|
||||
var nconf = require('nconf');
|
||||
var i18n = require('../i18n')
|
||||
|
||||
/* Data export */
|
||||
router.get('/history.csv',auth.authWithSession,dataexport.history); //[todo] encode data output options in the data controller and use these to build routes
|
||||
router.get('/userdata.xml',auth.authWithSession,dataexport.leanuser,dataexport.userdata.xml);
|
||||
router.get('/userdata.json',auth.authWithSession,dataexport.leanuser,dataexport.userdata.json);
|
||||
router.get('/history.csv',auth.authWithSession,i18n.getUserLanguage,dataexport.history); //[todo] encode data output options in the data controller and use these to build routes
|
||||
router.get('/userdata.xml',auth.authWithSession,i18n.getUserLanguage,dataexport.leanuser,dataexport.userdata.xml);
|
||||
router.get('/userdata.json',auth.authWithSession,i18n.getUserLanguage,dataexport.leanuser,dataexport.userdata.json);
|
||||
|
||||
module.exports = router;
|
||||
|
||||
+10
-9
@@ -5,9 +5,10 @@ var _ = require('lodash');
|
||||
var middleware = require('../middleware');
|
||||
var user = require('../controllers/user');
|
||||
var auth = require('../controllers/auth');
|
||||
var i18n = require('../i18n');
|
||||
|
||||
// -------- App --------
|
||||
router.get('/', middleware.locals, function(req, res) {
|
||||
router.get('/', i18n.getUserLanguage, middleware.locals, function(req, res) {
|
||||
if (!req.headers['x-api-user'] && !req.headers['x-api-key'] && !(req.session && req.session.userId))
|
||||
return res.redirect('/static/front')
|
||||
|
||||
@@ -19,35 +20,35 @@ router.get('/', middleware.locals, function(req, res) {
|
||||
|
||||
// -------- Marketing --------
|
||||
|
||||
router.get('/static/front', middleware.locals, function(req, res) {
|
||||
router.get('/static/front', i18n.getUserLanguage, middleware.locals, function(req, res) {
|
||||
res.render('static/front', {env: res.locals.habitrpg});
|
||||
});
|
||||
|
||||
router.get('/static/privacy', middleware.locals, function(req, res) {
|
||||
router.get('/static/privacy', i18n.getUserLanguage, middleware.locals, function(req, res) {
|
||||
res.render('static/privacy', {env: res.locals.habitrpg});
|
||||
});
|
||||
|
||||
router.get('/static/terms', middleware.locals, function(req, res) {
|
||||
router.get('/static/terms', i18n.getUserLanguage, middleware.locals, function(req, res) {
|
||||
res.render('static/terms', {env: res.locals.habitrpg});
|
||||
});
|
||||
|
||||
router.get('/static/api', middleware.locals, function(req, res) {
|
||||
router.get('/static/api', i18n.getUserLanguage, middleware.locals, function(req, res) {
|
||||
res.render('static/api', {env: res.locals.habitrpg});
|
||||
});
|
||||
|
||||
router.get('/static/features', middleware.locals, function(req, res) {
|
||||
router.get('/static/features', i18n.getUserLanguage, middleware.locals, function(req, res) {
|
||||
res.render('static/features', {env: res.locals.habitrpg});
|
||||
});
|
||||
|
||||
router.get('/static/videos', middleware.locals, function(req, res) {
|
||||
router.get('/static/videos', i18n.getUserLanguage, middleware.locals, function(req, res) {
|
||||
res.render('static/videos', {env: res.locals.habitrpg});
|
||||
});
|
||||
|
||||
router.get('/static/contact', middleware.locals, function(req, res) {
|
||||
router.get('/static/contact', i18n.getUserLanguage, middleware.locals, function(req, res) {
|
||||
res.render('static/contact', {env: res.locals.habitrpg});
|
||||
});
|
||||
|
||||
router.get('/static/plans', middleware.locals, function(req, res) {
|
||||
router.get('/static/plans', i18n.getUserLanguage, middleware.locals, function(req, res) {
|
||||
res.render('static/plans', {env: res.locals.habitrpg});
|
||||
});
|
||||
|
||||
|
||||
@@ -27,6 +27,9 @@ if (cluster.isMaster && (isDev || isProd)) {
|
||||
var swagger = require("swagger-node-express");
|
||||
var autoinc = require('mongoose-id-autoinc');
|
||||
|
||||
// Setup translations
|
||||
var i18n = require('./i18n');
|
||||
|
||||
var middleware = require('./middleware');
|
||||
|
||||
var TWO_WEEKS = 1000 * 60 * 60 * 24 * 14;
|
||||
|
||||
Reference in New Issue
Block a user