Compare commits
66 Commits
main
...
release/dy
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b8841e52b7 | ||
|
|
8d2d3a12a9 | ||
|
|
e5b34e13d6 | ||
|
|
60519a171a | ||
|
|
099fe2646e | ||
|
|
5048d7e8d7 | ||
|
|
0ffaaf877f | ||
|
|
fb4d5a779f | ||
|
|
a7c4510abb | ||
|
|
fac77fec50 | ||
|
|
20c0391e81 | ||
|
|
a6be242628 | ||
|
|
8ee2d97599 | ||
|
|
0f44c37673 | ||
|
|
58fbfad17a | ||
|
|
2719f4bb2d | ||
|
|
8bc046369f | ||
|
|
8851f42ff4 | ||
|
|
31b238b8d5 | ||
|
|
87edaa6025 | ||
|
|
138b51d824 | ||
|
|
745151df39 | ||
|
|
5a7a412976 | ||
|
|
5b04addf26 | ||
|
|
e51c59274c | ||
|
|
dc9e0852ac | ||
|
|
eff2103c3e | ||
|
|
63b35af1d7 | ||
|
|
708dbe42f8 | ||
|
|
dadb6f2040 | ||
|
|
1ea939f41f | ||
|
|
6de1e1823f | ||
|
|
399179baa2 | ||
|
|
2e5f9fd001 | ||
|
|
d2c41fb983 | ||
|
|
14327d262e | ||
|
|
fc7950653d | ||
|
|
23275a121c | ||
|
|
5002faff08 | ||
|
|
718ebf525d | ||
|
|
ab1e8d44c9 | ||
|
|
1a0cfec09f | ||
|
|
8cad617acb | ||
|
|
6ab9d44430 | ||
|
|
7a913a23f0 | ||
|
|
001c83e902 | ||
|
|
e4357070af | ||
|
|
237aeb970f | ||
|
|
becce3218d | ||
|
|
20b1aeda5c | ||
|
|
83975b0520 | ||
|
|
092d2c98a1 | ||
|
|
cc9ab04112 | ||
|
|
43e65ddbbe | ||
|
|
410a35d451 | ||
|
|
51eb5ad130 | ||
|
|
4fc8d9485e | ||
|
|
1690794631 | ||
|
|
69665a4831 | ||
|
|
4971605821 | ||
|
|
df463924fe | ||
|
|
6f8d20e327 | ||
|
|
a6e52c0e87 | ||
|
|
dc9c8660ba | ||
|
|
8a1f6997ea | ||
|
|
8d42ab56c8 |
@ -79,7 +79,7 @@ export class LdapTfaController extends LdapController {
|
||||
},
|
||||
})
|
||||
.then((res) => reply.status(200).send(res.data))
|
||||
.catch(() => reply.status(500).send());
|
||||
.catch((error) => reply.status(500).send(error.response.data));
|
||||
}
|
||||
|
||||
@Get('/telegram-confirm')
|
||||
@ -98,9 +98,7 @@ export class LdapTfaController extends LdapController {
|
||||
status: HttpStatus.OK,
|
||||
})
|
||||
@UsePipes(new ValidationPipe({ transform: true }))
|
||||
async telegramReject(@Query() query: TelegramDto, @Res() reply: FastifyReply) {
|
||||
this.ldapTfaGateway.notify('auth-deny', query);
|
||||
|
||||
async telegramReject(@Query() _query: TelegramDto, @Res() reply: FastifyReply) {
|
||||
return reply.status(200).send({ success: true });
|
||||
}
|
||||
|
||||
|
||||
@ -32,7 +32,7 @@ export function BaseForm({ children, onSubmit }: FormProps & PropsWithChildren)
|
||||
autoComplete="on"
|
||||
{...register('password', { required: true })}
|
||||
/>
|
||||
{step === 'login-success' || step === 'telegram-notification' ? (
|
||||
{step === 'telegram-login' ? (
|
||||
<a target="_blank" className="info" href={TELEGRAM_BOT_URL} rel="noreferrer">
|
||||
Открыть чат с ботом
|
||||
</a>
|
||||
|
||||
@ -10,16 +10,16 @@ export function DefaultForm() {
|
||||
const { handleLogin } = useLogin();
|
||||
|
||||
const {
|
||||
state: { step },
|
||||
state: { step, user },
|
||||
} = useContext(FormStateContext);
|
||||
|
||||
if (step === 'refresh-token') {
|
||||
return <ButtonLoading>Подождите...</ButtonLoading>;
|
||||
if (step === 'login' && user) {
|
||||
return <ButtonLoading />;
|
||||
}
|
||||
|
||||
return (
|
||||
<BaseForm onSubmit={(data) => handleLogin(data)}>
|
||||
<ButtonLogin>Войти</ButtonLogin>
|
||||
<ButtonLogin />
|
||||
</BaseForm>
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,14 +1,11 @@
|
||||
import type { FormData } from '../lib/types';
|
||||
import { useSocket } from './socket';
|
||||
import { redirect } from '@/components/Form/lib/utils';
|
||||
import {
|
||||
ERROR_INVALID_CREDENTIALS,
|
||||
ERROR_SERVER,
|
||||
ERROR_TELEGRAM_SEND_MESSAGE,
|
||||
} from '@/constants/errors';
|
||||
import { ERROR_INVALID_CREDENTIALS, ERROR_SERVER } from '@/constants/errors';
|
||||
import { FormStateContext } from '@/context/form-state';
|
||||
import type { TelegramUrlResponse } from '@/types/error';
|
||||
import type { LdapUser } from '@/types/user';
|
||||
import axios from 'axios';
|
||||
import axios, { isAxiosError } from 'axios';
|
||||
import { useContext, useEffect } from 'react';
|
||||
|
||||
export function useLogin() {
|
||||
@ -20,7 +17,7 @@ export function useLogin() {
|
||||
.then((res) => {
|
||||
dispatch({
|
||||
payload: {
|
||||
step: 'login-success',
|
||||
step: 'telegram',
|
||||
user: res.data,
|
||||
},
|
||||
type: 'set-step',
|
||||
@ -46,17 +43,23 @@ export function useTelegramLogin() {
|
||||
.then(() => {
|
||||
dispatch({
|
||||
payload: {
|
||||
step: 'telegram-notification',
|
||||
step: 'telegram-login',
|
||||
},
|
||||
type: 'set-step',
|
||||
});
|
||||
})
|
||||
.catch(() =>
|
||||
dispatch({
|
||||
payload: { error: ERROR_TELEGRAM_SEND_MESSAGE },
|
||||
.catch((error_) => {
|
||||
let error = ERROR_SERVER;
|
||||
|
||||
if (isAxiosError<TelegramUrlResponse>(error_) && error_.response?.data?.message) {
|
||||
error = error_.response?.data?.message;
|
||||
}
|
||||
|
||||
return dispatch({
|
||||
payload: { error },
|
||||
type: 'set-error',
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return { handleTelegramLogin };
|
||||
@ -71,7 +74,7 @@ export function useTelegramConfirm() {
|
||||
const { socket } = useSocket();
|
||||
|
||||
useEffect(() => {
|
||||
if (step === 'telegram-notification') {
|
||||
if (step === 'telegram-login') {
|
||||
socket.open();
|
||||
socket.on('connect', () => {});
|
||||
|
||||
@ -87,11 +90,6 @@ export function useTelegramConfirm() {
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
socket.on('auth-deny', () => {
|
||||
socket.off('connect');
|
||||
window.location.reload();
|
||||
});
|
||||
}
|
||||
|
||||
return () => {
|
||||
|
||||
@ -23,6 +23,6 @@ export function useRefreshToken() {
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (step === 'refresh-token') handleRefreshToken();
|
||||
if (step === 'login' && user) handleRefreshToken();
|
||||
}, []);
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
// text-transform: none;
|
||||
text-transform: none;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
|
||||
@ -9,7 +9,7 @@ type Props = ButtonHTMLAttributes<HTMLButtonElement>;
|
||||
export function ButtonLogin(props: Props) {
|
||||
return (
|
||||
<button className={styles['button-submit']} type="submit" {...props}>
|
||||
{props.children}
|
||||
Войти
|
||||
</button>
|
||||
);
|
||||
}
|
||||
@ -19,7 +19,7 @@ export function ButtonLoading(props: Props) {
|
||||
<button disabled type="button" className={styles['button-submit']} {...props}>
|
||||
<div className={styles['loading-wrapper']}>
|
||||
<Spinner alt="spinner" className={styles['spinner-icon']} />
|
||||
{props.children}
|
||||
Подождите...
|
||||
</div>
|
||||
</button>
|
||||
);
|
||||
@ -50,7 +50,7 @@ export function ButtonTelegramLogin(props: Props) {
|
||||
height={22}
|
||||
alt="Telegram icon"
|
||||
/>
|
||||
{props.children}
|
||||
Ожидаем подтверждения...
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
@ -12,32 +12,32 @@ export function TelegramForm() {
|
||||
useTelegramConfirm();
|
||||
|
||||
const {
|
||||
state: { step },
|
||||
state: { step, user },
|
||||
} = useContext(FormStateContext);
|
||||
|
||||
if (step === 'refresh-token') {
|
||||
return <ButtonLoading>Подождите...</ButtonLoading>;
|
||||
if (step === 'login' && user) {
|
||||
return <ButtonLoading />;
|
||||
}
|
||||
|
||||
if (step === 'login-success') {
|
||||
if (step === 'telegram') {
|
||||
return (
|
||||
<BaseForm onSubmit={() => handleTelegramLogin()}>
|
||||
<ButtonTelegram>Войти через Telegram</ButtonTelegram>
|
||||
<ButtonTelegram>Войти как {user?.displayName}</ButtonTelegram>
|
||||
</BaseForm>
|
||||
);
|
||||
}
|
||||
|
||||
if (step === 'telegram-notification') {
|
||||
if (step === 'telegram-login') {
|
||||
return (
|
||||
<BaseForm onSubmit={() => {}}>
|
||||
<ButtonTelegramLogin>Ожидаем подтверждения...</ButtonTelegramLogin>
|
||||
<ButtonTelegramLogin />
|
||||
</BaseForm>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<BaseForm onSubmit={(data) => handleLogin(data)}>
|
||||
<ButtonLogin>Далее</ButtonLogin>
|
||||
<ButtonLogin />
|
||||
</BaseForm>
|
||||
);
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ $layout-breakpoint-desktop: 1680px;
|
||||
background-color: white;
|
||||
margin: 0;
|
||||
height: 250px;
|
||||
width: 100vw;
|
||||
width: 100%;
|
||||
padding: 25px 10px;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
@ -1,3 +1,2 @@
|
||||
export const ERROR_INVALID_CREDENTIALS = 'Неверный логин или пароль';
|
||||
export const ERROR_SERVER = 'Не удалось войти. Повторите попытку позже';
|
||||
export const ERROR_TELEGRAM_SEND_MESSAGE = 'Не удалось отправить сообщение в Telegram';
|
||||
|
||||
@ -5,8 +5,7 @@ import { createContext, useMemo, useReducer } from 'react';
|
||||
|
||||
type State = {
|
||||
error: string | undefined;
|
||||
step: 'login' | 'login-success' | 'telegram-notification' | 'refresh-token';
|
||||
tfa: boolean;
|
||||
step: 'login' | 'telegram' | 'telegram-login';
|
||||
user: LdapUser | undefined;
|
||||
};
|
||||
|
||||
@ -21,7 +20,6 @@ const reducer = (state: State, action: Action): State => {
|
||||
if (action.payload.step)
|
||||
return {
|
||||
...state,
|
||||
error: undefined,
|
||||
step: action.payload.step,
|
||||
user: action.payload.user || state.user,
|
||||
};
|
||||
@ -60,15 +58,13 @@ type Context = {
|
||||
export const FormStateContext = createContext<Context>({} as Context);
|
||||
|
||||
type FormStateProviderProps = {
|
||||
readonly tfa: boolean;
|
||||
readonly user?: LdapUser;
|
||||
} & PropsWithChildren;
|
||||
|
||||
export function FormStateProvider({ children, tfa, user = undefined }: FormStateProviderProps) {
|
||||
export function FormStateProvider({ children, user = undefined }: FormStateProviderProps) {
|
||||
const [state, dispatch] = useReducer(reducer, {
|
||||
error: undefined,
|
||||
step: user ? 'refresh-token' : 'login',
|
||||
tfa,
|
||||
step: 'login',
|
||||
user,
|
||||
});
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@ button {
|
||||
outline: none;
|
||||
padding: 0.55rem 0.75rem;
|
||||
text-align: center;
|
||||
text-transform: none;
|
||||
text-transform: uppercase;
|
||||
vertical-align: middle;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@ -5,6 +5,6 @@
|
||||
text-transform: uppercase;
|
||||
color: red;
|
||||
overflow: hidden;
|
||||
/* white-space: nowrap; */
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
@ -2,5 +2,4 @@
|
||||
display: block;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user