Skip to content

Commit

Permalink
Controllers completed, I believe, and some testing on dev... still ha…
Browse files Browse the repository at this point in the history
…ve libs to do.

* Changed "WARNING" on login page to "CAUTION"... a little too assertive... some users may want their email addy in there.
* Notated some STYLEGUIDE conformance needs
* Notated very short function name(s)
* At least one undefined identifier
  • Loading branch information
Martii committed Jul 15, 2014
1 parent dd9a807 commit af46e15
Show file tree
Hide file tree
Showing 5 changed files with 742 additions and 741 deletions.
28 changes: 14 additions & 14 deletions controllers/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,36 @@ var User = require('../models/user').User;
var destroySessions = require('../libs/modifySessions').destroy;

// Simple controller to remove content and save it in the graveyard
exports.rm = function (req, res, next) {
var type = req.route.params[0];
var path = req.route.params[1];
var thisUser = req.session.user;
exports.rm = function (aReq, aRes, aNext) {
var type = aReq.route.params[0];
var path = aReq.route.params[1];
var thisUser = aReq.session.user;

switch (type) {
case 'scripts':
case 'libs':
path += type === 'libs' ? '.js' : '.user.js';
Script.findOne({ installName: path }, function (err, script) {
removeLib.remove(Script, script, thisUser, '', function (removed) {
if (!removed) { return next(); }
res.redirect('/');
Script.findOne({ installName: path }, function (aErr, aScript) {
removeLib.remove(Script, aScript, thisUser, '', function (aRemoved) {
if (!aRemoved) { return aNext(); }
aRes.redirect('/');
});
});
break;
case 'users':
User.findOne({ name: { $regex: new RegExp('^' + path + '$', "i") } },
function (err, user) {
removeLib.remove(User, user, thisUser, '', function (removed) {
if (!removed) { return next(); }
function (aErr, aUser) {
removeLib.remove(User, aUser, thisUser, '', function (aRemoved) {
if (!aRemoved) { return aNext(); }

// Destory all the sessions belonging to the removed user
destroySessions(req, user, function () {
res.redirect('/');
destroySessions(aReq, aUser, function () {
aRes.redirect('/');
});
});
});
break;
default:
next();
aNext();
}
};
Loading

1 comment on commit af46e15

@Martii
Copy link
Owner

@Martii Martii commented on af46e15 Jul 15, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applies to OpenUserJS#264

Please sign in to comment.