Can authenticate using password
This commit is contained in:
@ -9,6 +9,13 @@ export enum CreateAccountResult {
|
||||
Error,
|
||||
}
|
||||
|
||||
export enum PasswordLoginResult {
|
||||
TooManyRequests,
|
||||
InvalidCredentials,
|
||||
Success,
|
||||
Error,
|
||||
}
|
||||
|
||||
export interface CheckResetTokenResponse {
|
||||
name: string;
|
||||
}
|
||||
@ -65,6 +72,40 @@ export class AuthApi {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Authenticate using an email and a password
|
||||
*
|
||||
* @param mail The email address to use
|
||||
* @param password The password to use
|
||||
*/
|
||||
static async LoginWithPassword(
|
||||
mail: string,
|
||||
password: string
|
||||
): Promise<PasswordLoginResult> {
|
||||
const res = await APIClient.exec({
|
||||
uri: "/auth/password_login",
|
||||
method: "POST",
|
||||
allowFail: true,
|
||||
jsonData: {
|
||||
mail: mail,
|
||||
password: password,
|
||||
},
|
||||
});
|
||||
|
||||
switch (res.status) {
|
||||
case 429:
|
||||
return PasswordLoginResult.TooManyRequests;
|
||||
case 401:
|
||||
return PasswordLoginResult.InvalidCredentials;
|
||||
case 200:
|
||||
case 201:
|
||||
sessionStorage.setItem(TokenStateKey, res.data.token);
|
||||
return PasswordLoginResult.Success;
|
||||
default:
|
||||
return PasswordLoginResult.Error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start OpenID login
|
||||
*
|
||||
|
Reference in New Issue
Block a user