2016-12-28 23:49:51 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Module dependencies
|
|
|
|
*/
|
|
|
|
import AuthSess from '../../../models/auth-session';
|
|
|
|
import serialize from '../../../serializers/auth-session';
|
|
|
|
|
2017-01-05 11:01:37 +01:00
|
|
|
/**
|
|
|
|
* @swagger
|
|
|
|
* /auth/session/show:
|
|
|
|
* post:
|
|
|
|
* summary: Show a session information
|
|
|
|
* parameters:
|
|
|
|
* -
|
|
|
|
* name: token
|
2017-01-06 07:13:46 +01:00
|
|
|
* description: Session Token
|
2017-01-05 11:01:37 +01:00
|
|
|
* in: formData
|
|
|
|
* required: true
|
|
|
|
* type: string
|
|
|
|
*
|
|
|
|
* responses:
|
|
|
|
* 200:
|
|
|
|
* description: OK
|
|
|
|
* schema:
|
|
|
|
* type: object
|
|
|
|
* properties:
|
|
|
|
* created_at:
|
|
|
|
* type: string
|
2017-01-06 08:19:41 +01:00
|
|
|
* format: date-time
|
2017-01-06 07:13:46 +01:00
|
|
|
* description: Date and time of the session creation
|
2017-01-05 11:01:37 +01:00
|
|
|
* app_id:
|
|
|
|
* type: string
|
|
|
|
* description: Application ID
|
|
|
|
* token:
|
|
|
|
* type: string
|
2017-01-05 15:42:27 +01:00
|
|
|
* description: Session Token
|
2017-01-05 11:01:37 +01:00
|
|
|
* user_id:
|
|
|
|
* type: string
|
2017-01-06 07:13:46 +01:00
|
|
|
* description: ID of user who create the session
|
2017-01-05 11:01:37 +01:00
|
|
|
* app:
|
|
|
|
* $ref: "#/definitions/Application"
|
2017-01-05 16:39:56 +01:00
|
|
|
* default:
|
2017-01-05 11:01:37 +01:00
|
|
|
* description: Failed
|
|
|
|
* schema:
|
|
|
|
* $ref: "#/definitions/Error"
|
|
|
|
*/
|
|
|
|
|
2016-12-28 23:49:51 +01:00
|
|
|
/**
|
|
|
|
* Show a session
|
|
|
|
*
|
|
|
|
* @param {Object} params
|
|
|
|
* @param {Object} user
|
|
|
|
* @return {Promise<object>}
|
|
|
|
*/
|
|
|
|
module.exports = (params, user) =>
|
|
|
|
new Promise(async (res, rej) =>
|
|
|
|
{
|
|
|
|
// Get 'token' parameter
|
|
|
|
const token = params.token;
|
|
|
|
if (token == null) {
|
|
|
|
return rej('token is required');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Lookup session
|
|
|
|
const session = await AuthSess.findOne({
|
|
|
|
token: token
|
|
|
|
});
|
|
|
|
|
|
|
|
if (session == null) {
|
|
|
|
return rej('session not found');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Response
|
|
|
|
res(await serialize(session, user));
|
|
|
|
});
|