diff --git a/src/controllers/LoginController.ts b/src/controllers/LoginController.ts index c20d688c..fb0cf45f 100644 --- a/src/controllers/LoginController.ts +++ b/src/controllers/LoginController.ts @@ -51,4 +51,44 @@ export class LoginController extends Controller { return new HttpSuccess(_data); } } + + /** + * API login checkin + * + * @summary - login checkin + * + */ + @Post("checkin") + async loginCheckin( + @Body() + body: { + username: string; + password: string; + }, + ) { + const data = { + client_id: "gettoken-checkin", + client_secret: process.env.KC_CHECKIN_SECRET, + grant_type: "password", + requested_token_type: "urn:ietf:params:oauth:token-type:refresh_token", + username: body.username, + password: body.password, + }; + let _data: any = null; + await Promise.all([ + await new CallAPI() + .PostDataKeycloak(`/realms/${process.env.KC_REALMS}/protocol/openid-connect/token`, data) + .then(async (x) => { + _data = x; + }) + .catch(async (x) => { + throw new HttpError(HttpStatus.UNAUTHORIZED, "ชื่อผู้ใช้งานหรือรหัสผ่านไม่ถูกต้อง"); + }), + ]); + if (_data == null) { + return new HttpError(HttpStatus.UNAUTHORIZED, "ชื่อผู้ใช้งานหรือรหัสผ่านไม่ถูกต้อง"); + } else { + return new HttpSuccess(_data); + } + } }