mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2025-06-20 08:35:17 +00:00
Sign in user
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import { RequestHandler } from "../entities/RequestHandler";
|
||||
import { AccountHelper } from "../helpers/AccountHelper";
|
||||
|
||||
/**
|
||||
* Account controller
|
||||
@ -13,9 +14,31 @@ export class AccountController {
|
||||
*
|
||||
* @param handler
|
||||
*/
|
||||
public static LoginUser(handler: RequestHandler) {
|
||||
public static async LoginUser(handler: RequestHandler) {
|
||||
|
||||
handler.success("Successful operation.");
|
||||
// Get post data
|
||||
const email = handler.postEmail("userMail");
|
||||
const password = handler.postString("userPassword");
|
||||
|
||||
// TODO : add limits
|
||||
|
||||
// Authenticate user
|
||||
const tokens = await AccountHelper.LoginUser(email, password, handler.getClientInfo());
|
||||
|
||||
if(tokens == null) {
|
||||
// TODO : add limits
|
||||
|
||||
handler.error(401, "Invalid e-mail address / password !");
|
||||
}
|
||||
|
||||
// Success
|
||||
handler.send({
|
||||
success: "User signed in!",
|
||||
tokens: {
|
||||
token1: tokens.token1,
|
||||
token2: tokens.token2
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user