Initial project structure with sails.js
This commit is contained in:
37
api/responses/expired.js
Normal file
37
api/responses/expired.js
Normal file
@ -0,0 +1,37 @@
|
||||
/**
|
||||
* expired.js
|
||||
*
|
||||
* A custom response that content-negotiates the current request to either:
|
||||
* • serve an HTML error page about the specified token being invalid or expired
|
||||
* • or send back 498 (Token Expired/Invalid) with no response body.
|
||||
*
|
||||
* Example usage:
|
||||
* ```
|
||||
* return res.expired();
|
||||
* ```
|
||||
*
|
||||
* Or with actions2:
|
||||
* ```
|
||||
* exits: {
|
||||
* badToken: {
|
||||
* description: 'Provided token was expired, invalid, or already used up.',
|
||||
* responseType: 'expired'
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
module.exports = function expired() {
|
||||
|
||||
var req = this.req;
|
||||
var res = this.res;
|
||||
|
||||
sails.log.verbose('Ran custom response: res.expired()');
|
||||
|
||||
if (req.wantsJSON) {
|
||||
return res.status(498).send('Token Expired/Invalid');
|
||||
}
|
||||
else {
|
||||
return res.status(498).view('498');
|
||||
}
|
||||
|
||||
};
|
43
api/responses/unauthorized.js
Normal file
43
api/responses/unauthorized.js
Normal file
@ -0,0 +1,43 @@
|
||||
/**
|
||||
* unauthorized.js
|
||||
*
|
||||
* A custom response that content-negotiates the current request to either:
|
||||
* • log out the current user and redirect them to the login page
|
||||
* • or send back 401 (Unauthorized) with no response body.
|
||||
*
|
||||
* Example usage:
|
||||
* ```
|
||||
* return res.unauthorized();
|
||||
* ```
|
||||
*
|
||||
* Or with actions2:
|
||||
* ```
|
||||
* exits: {
|
||||
* badCombo: {
|
||||
* description: 'That email address and password combination is not recognized.',
|
||||
* responseType: 'unauthorized'
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
module.exports = function unauthorized() {
|
||||
|
||||
var req = this.req;
|
||||
var res = this.res;
|
||||
|
||||
sails.log.verbose('Ran custom response: res.unauthorized()');
|
||||
|
||||
if (req.wantsJSON) {
|
||||
return res.sendStatus(401);
|
||||
}
|
||||
// Or log them out (if necessary) and then redirect to the login page.
|
||||
else {
|
||||
|
||||
if (req.session.userId) {
|
||||
delete req.session.userId;
|
||||
}
|
||||
|
||||
return res.redirect('/login');
|
||||
}
|
||||
|
||||
};
|
Reference in New Issue
Block a user