2025-12-08 18:18:33 +01:00
|
|
|
import React, { useContext, useEffect, useState} from 'react'
|
2024-12-30 23:50:15 +01:00
|
|
|
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'
|
|
|
|
|
import {RegisterForm} from '../components/RegisterForm'
|
2025-10-31 23:13:45 +01:00
|
|
|
import useBreakpoint from "../hooks/useBreakpoint"
|
2025-12-08 18:18:33 +01:00
|
|
|
import {ConfigurationContext} from "../contexts"
|
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)
|
2025-12-08 18:18:33 +01:00
|
|
|
const { configuration } = useContext(ConfigurationContext)
|
|
|
|
|
|
2025-10-31 13:46:17 +01:00
|
|
|
const md = useBreakpoint('md')
|
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(() => {
|
2025-12-08 18:18:33 +01:00
|
|
|
if(!configuration?.registerEnabled && configuration?.ssoLogin && configuration?.ssoAutoRedirect) {
|
|
|
|
|
window.location.href = '/login/oauth'
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}, [configuration])
|
2024-08-02 16:17:55 +02:00
|
|
|
|
2025-10-31 13:46:17 +01:00
|
|
|
const grid = [
|
2025-10-31 22:52:45 +01:00
|
|
|
<Card.Grid key="form" style={{width: md ? '100%' : '50%', textAlign: 'center'}} hoverable={false}>
|
2025-10-31 13:46:17 +01:00
|
|
|
{wantRegister ? <RegisterForm/> : <LoginForm ssoLogin={configuration?.ssoLogin}/>}
|
|
|
|
|
{
|
|
|
|
|
configuration?.registerEnabled &&
|
|
|
|
|
<Button
|
|
|
|
|
type='link'
|
|
|
|
|
block
|
|
|
|
|
style={{marginTop: '1em'}}
|
|
|
|
|
onClick={toggleWantRegister}
|
|
|
|
|
>{wantRegister ? t`Log in` : t`Create an account`}
|
|
|
|
|
</Button>
|
|
|
|
|
}
|
|
|
|
|
</Card.Grid>,
|
2025-10-31 22:52:45 +01:00
|
|
|
<Card.Grid key="ads" style={{width: md ? '100%' : '50%'}} hoverable={false}>
|
2025-10-31 13:46:17 +01:00
|
|
|
<TextPage resource='ads.md'/>
|
|
|
|
|
</Card.Grid>
|
2025-10-31 22:52:45 +01:00
|
|
|
]
|
2025-10-31 13:46:17 +01:00
|
|
|
|
|
|
|
|
if (md) {
|
2025-10-31 22:52:45 +01:00
|
|
|
grid.reverse()
|
2025-10-31 13:46:17 +01:00
|
|
|
}
|
|
|
|
|
|
2024-12-30 23:50:15 +01:00
|
|
|
return (
|
|
|
|
|
<Card title={wantRegister ? t`Register` : t`Log in`} style={{width: '100%'}}>
|
2025-10-31 13:46:17 +01:00
|
|
|
{grid}
|
2024-12-30 23:50:15 +01:00
|
|
|
</Card>
|
|
|
|
|
)
|
|
|
|
|
}
|