23a0b799f78368c18b85d097ce4b98eede607d4b
1 const _
= require("underscore");
2 const UserModel
= require("../models/user");
6 getUser: function(req
, res
, callback
)
8 if (!res
.locals
.loggedIn
)
9 return callback({errmsg: "Not logged in!"}, undefined);
10 UserModel
.getBySessionToken(req
.cookies
.token
, function(err
, user
) {
12 return callback({errmsg: "Not logged in!"}, undefined);
13 return callback(null, user
);
17 // Before loading sensible content, check + save credentials
18 logged: function(req
, res
, next
)
20 Access
.getUser(req
, res
, (err
,user
) => {
28 // Prevent access to "anonymous pages"
29 unlogged: function(req
, res
, next
)
32 return res
.json({errmsg: "Already logged in!"});
36 // Prevent direct access to AJAX results
37 ajax: function(req
, res
, next
)
40 return res
.json({errmsg: "Unauthorized access"});
44 // Check for errors before callback (continue page loading). TODO: better name.
45 checkRequest: function(res
, err
, out
, msg
, cb
)
49 if (!out
|| _
.isEmpty(out
))
50 return res
.json({errmsg: msg
});
55 module
.exports
= Access
;