iceshrimp-legacy/src/server/api/endpoints/auth/session/show.ts

65 lines
1.6 KiB
TypeScript
Raw Normal View History

2017-03-08 19:50:09 +01:00
import $ from 'cafy';
2018-03-29 13:32:18 +02:00
import AuthSess, { pack } from '../../../../../models/auth-session';
2018-06-18 02:54:53 +02:00
import { ILocalUser } from '../../../../../models/user';
2016-12-28 23:49:51 +01:00
2017-01-05 11:01:37 +01:00
/**
* @swagger
* /auth/session/show:
2018-04-07 19:30:37 +02:00
* note:
2017-01-05 11:01:37 +01:00
* 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
2017-03-01 09:37:01 +01:00
*
2017-01-05 11:01:37 +01:00
* responses:
* 200:
* description: OK
2017-03-01 09:37:01 +01:00
* schema:
2017-01-05 11:01:37 +01:00
* type: object
* properties:
2018-03-29 07:48:47 +02:00
* createdAt:
2017-01-05 11:01:37 +01:00
* 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
2018-03-29 07:48:47 +02:00
* appId:
2017-01-05 11:01:37 +01:00
* type: string
* description: Application ID
* token:
* type: string
2017-01-05 15:42:27 +01:00
* description: Session Token
2018-03-29 07:48:47 +02:00
* userId:
2017-01-05 11:01:37 +01:00
* 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
*/
2018-07-05 19:58:29 +02:00
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
2016-12-28 23:49:51 +01:00
// Get 'token' parameter
2018-05-02 11:06:16 +02:00
const [token, tokenErr] = $.str.get(params.token);
2017-03-03 11:39:41 +01:00
if (tokenErr) return rej('invalid token param');
2016-12-28 23:49:51 +01:00
// Lookup session
const session = await AuthSess.findOne({
token: token
});
if (session == null) {
return rej('session not found');
}
// Response
2018-02-02 00:21:30 +01:00
res(await pack(session, user));
2016-12-28 23:49:51 +01:00
});