mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-05 18:47:03 +02:00
all user account pages; all static pages; outgoing page
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
var topicsController = require('./topics'),
|
||||
categoriesController = require('./categories'),
|
||||
staticController = require('./static'),
|
||||
async = require('async'),
|
||||
nconf = require('nconf'),
|
||||
auth = require('./../routes/authentication'),
|
||||
@@ -12,13 +13,14 @@ var topicsController = require('./topics'),
|
||||
|
||||
Controllers = {
|
||||
topics: topicsController,
|
||||
categories: categoriesController
|
||||
categories: categoriesController,
|
||||
static: staticController
|
||||
};
|
||||
|
||||
|
||||
Controllers.home = function(req, res, next) {
|
||||
async.parallel({
|
||||
"header": function (next) {
|
||||
header: function (next) {
|
||||
/*app.build_header({
|
||||
req: req,
|
||||
res: res,
|
||||
@@ -39,7 +41,7 @@ Controllers.home = function(req, res, next) {
|
||||
|
||||
next(null);
|
||||
},
|
||||
"categories": function (next) {
|
||||
categories: function (next) {
|
||||
var uid = (req.user) ? req.user.uid : 0;
|
||||
categories.getAllCategories(uid, function (err, data) {
|
||||
data.categories = data.categories.filter(function (category) {
|
||||
@@ -186,4 +188,23 @@ Controllers.robots = function (req, res) {
|
||||
}
|
||||
};
|
||||
|
||||
Controllers.outgoing = function(req, res, next) {
|
||||
var url = req.query.url,
|
||||
data = {
|
||||
url: url,
|
||||
title: meta.config.title
|
||||
};
|
||||
|
||||
if (url) {
|
||||
if (res.locals.isAPI) {
|
||||
res.json(data);
|
||||
} else {
|
||||
res.render('outgoing', data);
|
||||
}
|
||||
} else {
|
||||
res.status(404);
|
||||
res.redirect(nconf.get('relative_path') + '/404');
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = Controllers;
|
||||
27
src/controllers/static.js
Normal file
27
src/controllers/static.js
Normal file
@@ -0,0 +1,27 @@
|
||||
var staticController = {};
|
||||
|
||||
staticController['404'] = function(req, res, next) {
|
||||
if (res.locals.isAPI) {
|
||||
res.json({});
|
||||
} else {
|
||||
res.render('404', {});
|
||||
}
|
||||
};
|
||||
|
||||
staticController['403'] = function(req, res, next) {
|
||||
if (res.locals.isAPI) {
|
||||
res.json({});
|
||||
} else {
|
||||
res.render('403', {});
|
||||
}
|
||||
};
|
||||
|
||||
staticController['500'] = function(req, res, next) {
|
||||
if (res.locals.isAPI) {
|
||||
res.json({});
|
||||
} else {
|
||||
res.render('500', {});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = staticController;
|
||||
277
src/controllers/users.js
Normal file
277
src/controllers/users.js
Normal file
@@ -0,0 +1,277 @@
|
||||
var usersController = {},
|
||||
user = require('./../user'),
|
||||
posts = require('./../posts');
|
||||
|
||||
|
||||
function userNotFound(res) {
|
||||
if (res.locals.isAPI) {
|
||||
return res.json(404, {
|
||||
error: 'User not found!'
|
||||
});
|
||||
} else {
|
||||
return res.render('404', {
|
||||
error: 'User not found!'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function userNotAllowed(res) {
|
||||
if (res.locals.isAPI) {
|
||||
return res.json(403, {
|
||||
error: 'Not allowed.'
|
||||
});
|
||||
} else {
|
||||
return res.render('403', {
|
||||
error: 'Not allowed.'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
usersController.getAccount = function(req, res, next) {
|
||||
var callerUID = req.user ? parseInt(req.user.uid, 10) : 0;
|
||||
|
||||
getUserDataByUserSlug(req.params.userslug, callerUID, function (err, userData) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if(!userData) {
|
||||
return res.json(404, {
|
||||
error: 'User not found!'
|
||||
});
|
||||
}
|
||||
|
||||
user.isFollowing(callerUID, userData.theirid, function (isFollowing) {
|
||||
posts.getPostsByUid(callerUID, userData.theirid, 0, 9, function (err, userPosts) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
userData.posts = userPosts.posts.filter(function (p) {
|
||||
return p && parseInt(p.deleted, 10) !== 1;
|
||||
});
|
||||
|
||||
userData.isFollowing = isFollowing;
|
||||
|
||||
if (!userData.profileviews) {
|
||||
userData.profileviews = 1;
|
||||
}
|
||||
|
||||
if (callerUID !== parseInt(userData.uid, 10) && callerUID) {
|
||||
user.incrementUserFieldBy(userData.uid, 'profileviews', 1);
|
||||
}
|
||||
|
||||
postTools.parse(userData.signature, function (err, signature) {
|
||||
userData.signature = signature;
|
||||
|
||||
if (res.locals.isAPI) {
|
||||
res.json({});
|
||||
} else {
|
||||
res.render('account', {});
|
||||
};
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
usersController.getFollowing = function(req, res, next) {
|
||||
var callerUID = req.user ? parseInt(req.user.uid, 10) : 0;
|
||||
|
||||
getUserDataByUserSlug(req.params.userslug, callerUID, function (err, userData) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if (userData) {
|
||||
user.getFollowing(userData.uid, function (err, followingData) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
userData.following = followingData;
|
||||
userData.followingCount = followingData.length;
|
||||
|
||||
if (res.locals.isAPI) {
|
||||
res.json(userData);
|
||||
} else {
|
||||
res.render('following', userData);
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
return userNotFound();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
usersController.getFollowers = function(req, res, next) {
|
||||
var callerUID = req.user ? parseInt(req.user.uid, 10) : 0;
|
||||
|
||||
getUserDataByUserSlug(req.params.userslug, callerUID, function (err, userData) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if (userData) {
|
||||
user.getFollowers(userData.uid, function (err, followersData) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
userData.followers = followersData;
|
||||
userData.followersCount = followersData.length;
|
||||
|
||||
if (res.locals.isAPI) {
|
||||
res.json(userData);
|
||||
} else {
|
||||
res.render('followers', userData);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return userNotFound();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
usersController.getFavourites = function(req, res, next) {
|
||||
var callerUID = req.user ? parseInt(req.user.uid, 10) : 0;
|
||||
|
||||
user.getUidByUserslug(req.params.userslug, function (err, uid) {
|
||||
if (!uid) {
|
||||
return userNotFound();
|
||||
}
|
||||
|
||||
if (parseInt(uid, 10) !== callerUID) {
|
||||
return userNotAllowed();
|
||||
}
|
||||
|
||||
user.getUserFields(uid, ['username', 'userslug'], function (err, userData) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if (!userData) {
|
||||
return userNotFound();
|
||||
}
|
||||
|
||||
posts.getFavourites(uid, 0, 9, function (err, favourites) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
userData.theirid = uid;
|
||||
userData.yourid = callerUID;
|
||||
userData.posts = favourites.posts;
|
||||
userData.nextStart = favourites.nextStart;
|
||||
|
||||
if (res.locals.isAPI) {
|
||||
res.json(userData);
|
||||
} else {
|
||||
res.render('favourites', userData);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
usersController.getPosts = function(req, res, next) {
|
||||
var callerUID = req.user ? parseInt(req.user.uid, 10) : 0;
|
||||
|
||||
user.getUidByUserslug(req.params.userslug, function (err, uid) {
|
||||
if (!uid) {
|
||||
return userNotFound();
|
||||
}
|
||||
|
||||
user.getUserFields(uid, ['username', 'userslug'], function (err, userData) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if (!userData) {
|
||||
return userNotFound();
|
||||
}
|
||||
|
||||
posts.getPostsByUid(callerUID, uid, 0, 19, function (err, userPosts) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
userData.uid = uid;
|
||||
userData.theirid = uid;
|
||||
userData.yourid = callerUID;
|
||||
userData.posts = userPosts.posts;
|
||||
userData.nextStart = userPosts.nextStart;
|
||||
|
||||
if (res.locals.isAPI) {
|
||||
res.json(userData);
|
||||
} else {
|
||||
res.render('accountposts', userData);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
usersController.accountEdit = function(req, res, next) {
|
||||
var callerUID = req.user ? parseInt(req.user.uid, 10) : 0;
|
||||
|
||||
getUserDataByUserSlug(req.params.userslug, callerUID, function (err, userData) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if (res.locals.isAPI) {
|
||||
res.json(userData);
|
||||
} else {
|
||||
res.render('accountedit', userData);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
usersController.accountSettings = function(req, res, next) {
|
||||
var callerUID = req.user ? parseInt(req.user.uid, 10) : 0;
|
||||
|
||||
user.getUidByUserslug(req.params.userslug, function(err, uid) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if (!uid) {
|
||||
return userNotFound();
|
||||
}
|
||||
|
||||
if (parseInt(uid, 10) !== callerUID) {
|
||||
return userNotAllowed();
|
||||
}
|
||||
|
||||
plugins.fireHook('filter:user.settings', [], function(err, settings) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
user.getUserFields(uid, ['username', 'userslug'], function(err, userData) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if(!userData) {
|
||||
return userNotFound();
|
||||
}
|
||||
userData.yourid = req.user.uid;
|
||||
userData.theirid = uid;
|
||||
userData.settings = settings;
|
||||
|
||||
if (res.locals.isAPI) {
|
||||
res.json(userData);
|
||||
} else {
|
||||
res.render('accountsettings', userData);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
module.exports = usersController;
|
||||
Reference in New Issue
Block a user