add login checkin
This commit is contained in:
parent
13a7ccc997
commit
4fdbc122e4
1 changed files with 40 additions and 0 deletions
|
|
@ -51,4 +51,44 @@ export class LoginController extends Controller {
|
||||||
return new HttpSuccess(_data);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue