Compare commits

..

66 Commits

Author SHA1 Message Date
vchikalkin
b8841e52b7 api: add /check-auth method for account mode 2024-07-14 16:23:37 +03:00
vchikalkin
8d2d3a12a9 Login: dynamic import Form components 2024-07-14 16:10:00 +03:00
vchikalkin
e5b34e13d6 ldap-tfa: export * from pages/ldap 2024-07-14 16:04:22 +03:00
vchikalkin
60519a171a web: split components into hooks & files 2024-07-14 15:26:32 +03:00
vchikalkin
099fe2646e ButtonLoading: change text 2024-07-14 14:23:57 +03:00
vchikalkin
5048d7e8d7 web: fix ButtonTelegram content layout 2024-07-13 23:52:33 +03:00
vchikalkin
0ffaaf877f fix build [3] 2024-07-13 23:15:00 +03:00
vchikalkin
fb4d5a779f fix build [2] 2024-07-13 23:07:12 +03:00
vchikalkin
a7c4510abb fix build 2024-07-13 22:58:37 +03:00
vchikalkin
fac77fec50 fix build: specify turbo version 2024-07-13 22:13:19 +03:00
vchikalkin
20c0391e81 web: auto refresh token
reuse buttons in default & telegram forms
2024-07-13 21:45:37 +03:00
vchikalkin
a6be242628 web: move utils/router -> components/Form/utils 2024-07-13 19:42:10 +03:00
vchikalkin
8ee2d97599 fix Form/types extension 2024-07-13 19:40:37 +03:00
vchikalkin
0f44c37673 web: move Login to /Login directory 2024-07-13 19:40:12 +03:00
vchikalkin
58fbfad17a web: split Form into files 2024-07-13 19:34:46 +03:00
vchikalkin
2719f4bb2d api: fix ldap check-auth (detect user and refresh token) 2024-07-13 18:54:31 +03:00
vchikalkin
8bc046369f [2] fix build 2024-06-07 12:56:09 +03:00
vchikalkin
8851f42ff4 fix build 2024-06-07 12:49:34 +03:00
vchikalkin
31b238b8d5 apps/web: pass env variables
remove .env file
2024-06-07 12:37:16 +03:00
vchikalkin
87edaa6025 gateway: fix redirect after /logout for account 2024-06-07 12:09:06 +03:00
vchikalkin
138b51d824 gateway: fix redirect after /logout 2024-06-07 11:45:10 +03:00
vchikalkin
745151df39 apps/web: export PageHead from pages/ldap 2024-06-06 22:18:53 +03:00
vchikalkin
5a7a412976 fix: rename apps/web pages 2024-06-06 22:17:38 +03:00
vchikalkin
5b04addf26 rename pages/telegram -> pages/ldap-tfa 2024-06-06 21:48:47 +03:00
vchikalkin
e51c59274c apps/web: use displayName or username 2024-06-06 21:46:04 +03:00
vchikalkin
dc9e0852ac feature: continue as @user 2024-06-06 21:15:56 +03:00
vchikalkin
eff2103c3e apps/api: add /refresh-token methods
remove refresh-token logic from app controller
2024-06-06 16:24:53 +03:00
vchikalkin
63b35af1d7 [2] apps/web: fix telegram icon margin 2024-06-06 12:56:42 +03:00
vchikalkin
708dbe42f8 apps/web: fix telegram icon margin 2024-06-06 12:45:31 +03:00
vchikalkin
dadb6f2040 apps/web: add error text overflow 2024-06-06 12:37:48 +03:00
vchikalkin
1ea939f41f pass error from telegram server to client 2024-06-06 12:36:07 +03:00
vchikalkin
6de1e1823f apps/api: pass creds for TELEGRAM_URL_SEND_AUTH_MESSAGE 2024-06-05 15:24:30 +03:00
vchikalkin
399179baa2 [1] apps/api: fix refresh token 2024-06-05 12:34:28 +03:00
vchikalkin
2e5f9fd001 complete 2024-06-04 18:45:22 +03:00
vchikalkin
d2c41fb983 apps/api: use global CacheModule 2024-06-04 14:33:04 +03:00
vchikalkin
14327d262e packages: add socket.io 2024-06-04 14:32:14 +03:00
vchikalkin
fc7950653d .env: add new variables 2024-05-31 14:43:18 +03:00
vchikalkin
23275a121c Revert "remove .env"
This reverts commit 5002faff08f5cdfb85b77296f94c51b33716e368.
2024-05-31 14:42:32 +03:00
vchikalkin
5002faff08 remove .env 2024-05-31 14:31:03 +03:00
vchikalkin
718ebf525d docker-compose.yml: add envTELEGRAM_URL_SEND_AUTH_MESSAGE 2024-05-31 14:22:02 +03:00
vchikalkin
ab1e8d44c9 ldap-tfa: add method /telegram-reject 2024-05-31 14:14:35 +03:00
vchikalkin
1a0cfec09f ldap-tfa: add method GET /telegram-confirm 2024-05-29 13:56:02 +03:00
vchikalkin
8cad617acb apps/web: fix disable inputs after login step 2024-05-28 16:03:19 +03:00
vchikalkin
6ab9d44430 ldap: add employeeID
apps/api: add /telegram-confirm method
apps/web: show bot link info
2024-05-28 15:55:37 +03:00
vchikalkin
7a913a23f0 apps/web: fix Form onSubmit 2024-05-28 12:09:38 +03:00
vchikalkin
001c83e902 apps/web: refactor Form component 2024-05-28 11:39:46 +03:00
vchikalkin
e4357070af apps/web: add FormStateContext
apps/api: add methods ldap-tfa/login-telegram
2024-05-27 12:02:05 +03:00
vchikalkin
237aeb970f fix pass user to submit button 2024-05-14 16:16:34 +03:00
vchikalkin
becce3218d apps/api: move jwt types to src/types 2024-05-14 16:12:22 +03:00
vchikalkin
20b1aeda5c apps/api: fix verify token 2024-05-14 15:54:23 +03:00
vchikalkin
83975b0520 apps/api: add create token with audience in ldap-tfa controller
support token with audience in app controller
2024-05-14 15:38:32 +03:00
vchikalkin
092d2c98a1 apps/api: add AuthParams decorator & isTokenExpired function 2024-05-14 14:01:59 +03:00
vchikalkin
cc9ab04112 apps/api: create AuthToken decorator 2024-05-14 12:49:19 +03:00
vchikalkin
43e65ddbbe apps/api: remove token methods from ldap controller 2024-05-14 12:40:02 +03:00
vchikalkin
410a35d451 apps/web: fix submit button color animation 2024-05-07 14:19:15 +03:00
vchikalkin
51eb5ad130 apps/web: fix authContext is undefined 2024-05-07 14:17:55 +03:00
vchikalkin
4fc8d9485e apps/web: beautify telegram submit button 2024-05-07 13:42:55 +03:00
vchikalkin
1690794631 apps/api: add controller ldap-tfa 2024-05-07 12:53:55 +03:00
vchikalkin
69665a4831 apps/api: add type BaseAuthController 2024-05-07 11:53:56 +03:00
vchikalkin
4971605821 pages/telegram: wrap context value into useMemo 2024-05-07 11:21:28 +03:00
vchikalkin
df463924fe add 2fa initial features 2024-05-03 18:08:46 +03:00
vchikalkin
6f8d20e327 apps/web: replace global button style with .button-submit 2024-05-03 16:06:31 +03:00
vchikalkin
a6e52c0e87 apps/web: prepare for telegram login form 2024-05-03 16:02:21 +03:00
vchikalkin
dc9c8660ba apps/web: use react-hook-form 2024-05-03 14:00:05 +03:00
vchikalkin
8a1f6997ea apps/web: remove elements components
define global elements css
2024-05-03 13:38:17 +03:00
vchikalkin
8d42ab56c8 replace default exports with named 2024-05-02 21:02:03 +03:00
14 changed files with 43 additions and 53 deletions

View File

@ -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 });
}

View File

@ -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>

View File

@ -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>
);
}

View File

@ -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 () => {

View File

@ -23,6 +23,6 @@ export function useRefreshToken() {
}
useEffect(() => {
if (step === 'refresh-token') handleRefreshToken();
if (step === 'login' && user) handleRefreshToken();
}, []);
}

View File

@ -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;

View File

@ -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>
);
}

View File

@ -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>Войти как &nbsp;{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>
);
}

View File

@ -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;
}

View File

@ -1,3 +1,2 @@
export const ERROR_INVALID_CREDENTIALS = 'Неверный логин или пароль';
export const ERROR_SERVER = 'Не удалось войти. Повторите попытку позже';
export const ERROR_TELEGRAM_SEND_MESSAGE = 'Не удалось отправить сообщение в Telegram';

View File

@ -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,
});

View File

@ -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%;
}

View File

@ -5,6 +5,6 @@
text-transform: uppercase;
color: red;
overflow: hidden;
/* white-space: nowrap; */
white-space: nowrap;
text-overflow: ellipsis;
}

View File

@ -2,5 +2,4 @@
display: block;
margin-left: auto;
margin-right: auto;
margin-bottom: 5px;
}