2024-12-30 23:50:15 +01:00
|
|
|
import React, {createContext, useEffect, useState} from 'react'
|
|
|
|
|
import {Button, Card} from 'antd'
|
2024-07-28 15:36:22 +02:00
|
|
|
import {t} from 'ttag'
|
2024-12-30 23:50:15 +01:00
|
|
|
import TextPage from './TextPage'
|
|
|
|
|
import {LoginForm} from '../components/LoginForm'
|
2024-12-31 13:55:42 +01:00
|
|
|
import type { InstanceConfig} from '../utils/api'
|
|
|
|
|
import {getConfiguration} from '../utils/api'
|
2024-12-30 23:50:15 +01:00
|
|
|
import {RegisterForm} from '../components/RegisterForm'
|
2024-07-26 18:31:47 +02:00
|
|
|
|
2024-12-30 23:50:15 +01:00
|
|
|
export const AuthenticatedContext = createContext<
|
|
|
|
|
{
|
|
|
|
|
authenticated: (authenticated: boolean) => void
|
|
|
|
|
setIsAuthenticated: React.Dispatch<React.SetStateAction<boolean>>
|
|
|
|
|
}
|
|
|
|
|
>({
|
|
|
|
|
authenticated: () => {
|
|
|
|
|
},
|
|
|
|
|
setIsAuthenticated: () => {
|
|
|
|
|
}
|
|
|
|
|
})
|
2024-07-23 18:37:59 +02:00
|
|
|
|
2024-08-02 16:17:55 +02:00
|
|
|
export default function LoginPage() {
|
2024-08-05 03:11:03 +02:00
|
|
|
const [wantRegister, setWantRegister] = useState<boolean>(false)
|
2024-08-04 15:49:38 +02:00
|
|
|
const [configuration, setConfiguration] = useState<InstanceConfig>()
|
2024-07-26 18:31:47 +02:00
|
|
|
|
2024-08-05 03:11:03 +02:00
|
|
|
const toggleWantRegister = () => {
|
|
|
|
|
setWantRegister(!wantRegister)
|
2024-07-26 18:31:47 +02:00
|
|
|
}
|
|
|
|
|
|
2024-08-02 16:17:55 +02:00
|
|
|
useEffect(() => {
|
2024-08-04 15:49:38 +02:00
|
|
|
getConfiguration().then(setConfiguration)
|
2024-08-02 16:17:55 +02:00
|
|
|
}, [])
|
|
|
|
|
|
2024-12-30 23:50:15 +01:00
|
|
|
return (
|
|
|
|
|
<Card title={wantRegister ? t`Register` : t`Log in`} style={{width: '100%'}}>
|
|
|
|
|
<Card.Grid style={{width: '50%', textAlign: 'center'}} hoverable={false}>
|
|
|
|
|
{wantRegister ? <RegisterForm/> : <LoginForm ssoLogin={configuration?.ssoLogin}/>}
|
|
|
|
|
{
|
|
|
|
|
configuration?.registerEnabled &&
|
|
|
|
|
<Button
|
|
|
|
|
type='link'
|
2024-08-05 03:11:03 +02:00
|
|
|
block
|
|
|
|
|
style={{marginTop: '1em'}}
|
2024-12-30 23:50:15 +01:00
|
|
|
onClick={toggleWantRegister}
|
|
|
|
|
>{wantRegister ? t`Log in` : t`Create an account`}
|
|
|
|
|
</Button>
|
|
|
|
|
}
|
|
|
|
|
</Card.Grid>
|
|
|
|
|
<Card.Grid style={{width: '50%'}} hoverable={false}>
|
|
|
|
|
<TextPage resource='ads.md'/>
|
|
|
|
|
</Card.Grid>
|
|
|
|
|
</Card>
|
|
|
|
|
)
|
|
|
|
|
}
|