Refactor login components and adjust login API routes (#1678)

* Refactor login components and adjust API routes

Signed-off-by: Erik Michelson <github@erik.michelson.eu>

* Adjust API /me response and redux state

Signed-off-by: Erik Michelson <github@erik.michelson.eu>

* Fix moved function

Signed-off-by: Erik Michelson <github@erik.michelson.eu>

* Update cypress tests

Signed-off-by: Erik Michelson <github@erik.michelson.eu>

* Adjust mock response

Signed-off-by: Erik Michelson <github@erik.michelson.eu>

* Integrate new common fields and hook into profile page

Signed-off-by: Erik Michelson <github@erik.michelson.eu>

* Remove openid

Signed-off-by: Erik Michelson <github@erik.michelson.eu>

* Fix config mock

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>

Co-authored-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Erik Michelson 2021-12-11 01:32:38 +01:00 committed by GitHub
parent fe640268c5
commit eab189c3c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
44 changed files with 911 additions and 507 deletions

View file

@ -3,62 +3,31 @@
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { RegisterError } from '../../components/register-page/register-page'
import { defaultFetchConfig, expectResponseCode, getApiUrl } from '../utils'
export const INTERACTIVE_LOGIN_METHODS = ['internal', 'ldap', 'openid']
export const INTERACTIVE_LOGIN_METHODS = ['local', 'ldap']
export const doInternalLogin = async (username: string, password: string): Promise<void> => {
const response = await fetch(getApiUrl() + 'auth/internal', {
export enum AuthError {
INVALID_CREDENTIALS = 'invalidCredentials',
LOGIN_DISABLED = 'loginDisabled',
OPENID_ERROR = 'openIdError',
OTHER = 'other'
}
export enum RegisterError {
USERNAME_EXISTING = 'usernameExisting',
REGISTRATION_DISABLED = 'registrationDisabled',
OTHER = 'other'
}
/**
* Requests to logout the current user.
* @throws Error if logout is not possible.
*/
export const doLogout = async (): Promise<void> => {
const response = await fetch(getApiUrl() + 'auth/logout', {
...defaultFetchConfig,
method: 'POST',
body: JSON.stringify({
username: username,
password: password
})
})
expectResponseCode(response)
}
export const doInternalRegister = async (username: string, password: string): Promise<void> => {
const response = await fetch(getApiUrl() + 'auth/register', {
...defaultFetchConfig,
method: 'POST',
body: JSON.stringify({
username: username,
password: password
})
})
if (response.status === 409) {
throw new Error(RegisterError.USERNAME_EXISTING)
}
expectResponseCode(response)
}
export const doLdapLogin = async (username: string, password: string): Promise<void> => {
const response = await fetch(getApiUrl() + 'auth/ldap', {
...defaultFetchConfig,
method: 'POST',
body: JSON.stringify({
username: username,
password: password
})
})
expectResponseCode(response)
}
export const doOpenIdLogin = async (openId: string): Promise<void> => {
const response = await fetch(getApiUrl() + 'auth/openid', {
...defaultFetchConfig,
method: 'POST',
body: JSON.stringify({
openId: openId
})
method: 'DELETE'
})
expectResponseCode(response)