diff --git a/apps/api/package.json b/apps/api/package.json
index e4bd560..f5d85d3 100644
--- a/apps/api/package.json
+++ b/apps/api/package.json
@@ -35,6 +35,7 @@
"@nestjs/platform-express": "^10.2.7",
"@nestjs/platform-fastify": "^10.2.7",
"@nestjs/swagger": "^7.1.14",
+ "axios": "^1.5.1",
"bcrypt": "^5.1.1",
"cache-manager": "^5.2.4",
"cache-manager-ioredis": "^2.1.0",
diff --git a/apps/api/src/config/schema/env.ts b/apps/api/src/config/schema/env.ts
index 9ce3ca8..3571192 100644
--- a/apps/api/src/config/schema/env.ts
+++ b/apps/api/src/config/schema/env.ts
@@ -23,6 +23,7 @@ const envSchema = z.object({
.string()
.transform((val) => Number.parseInt(val, 10))
.default('6379'),
+ TELEGRAM_SERVICE_URL_SEND_MESSAGE: z.string(),
});
export default envSchema;
diff --git a/apps/api/src/ldap-tfa/ldap-tfa.controller.ts b/apps/api/src/ldap-tfa/ldap-tfa.controller.ts
index 8aa2f83..a8271f1 100644
--- a/apps/api/src/ldap-tfa/ldap-tfa.controller.ts
+++ b/apps/api/src/ldap-tfa/ldap-tfa.controller.ts
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/explicit-member-accessibility */
import { Body, Controller, HttpException, HttpStatus, Post, Req, Res } from '@nestjs/common';
import { ApiResponse, ApiTags } from '@nestjs/swagger';
+import axios from 'axios';
import { FastifyReply, FastifyRequest } from 'fastify';
import { cookieOptions } from 'src/config/cookie';
import { env } from 'src/config/env';
@@ -37,6 +38,19 @@ export class LdapTfaController extends LdapController {
async loginTelegram(@AuthToken() token: string, @Res() reply: FastifyReply) {
const user = await this.ldapService.getUser(token);
+ await axios.post(env.TELEGRAM_SERVICE_URL_SEND_MESSAGE, {
+ authId: crypto.randomUUID(),
+ user,
+ });
+
return reply.status(200).send(user);
}
+
+ @Post('/telegram-confirm')
+ @ApiResponse({
+ status: HttpStatus.OK,
+ })
+ async telegramConfirm(@Req() req: FastifyRequest, @Res() reply: FastifyReply) {
+ return reply.status(200).send('ok');
+ }
}
diff --git a/apps/api/src/utils/ldap.ts b/apps/api/src/utils/ldap.ts
index 8b070cf..726c1fd 100644
--- a/apps/api/src/utils/ldap.ts
+++ b/apps/api/src/utils/ldap.ts
@@ -18,6 +18,8 @@ export class User {
public position: string;
@ApiResponseProperty()
public username: string;
+ @ApiResponseProperty()
+ public employeeID: string;
}
export type LdapUser = {
@@ -108,6 +110,7 @@ export async function authenticate(login: string, password?: string) {
title,
mail,
sAMAccountName: username,
+ employeeID,
}: LdapUser = await ldap.authenticate(options);
const user: User = {
@@ -115,6 +118,7 @@ export async function authenticate(login: string, password?: string) {
displayName,
domain: env.LDAP_DOMAIN,
domainName: `${env.LDAP_DOMAIN}\\${username}`,
+ employeeID,
mail,
position: title,
username,
diff --git a/apps/web/components/Form.tsx b/apps/web/components/Form.tsx
index 3135b23..6e6f735 100644
--- a/apps/web/components/Form.tsx
+++ b/apps/web/components/Form.tsx
@@ -14,7 +14,7 @@ import { useForm } from 'react-hook-form';
const ERROR_INVALID_CREDENTIALS = 'Неверный логин или пароль';
const ERROR_SERVER = 'Не удалось войти. Повторите попытку позже';
-const { APP_BASE_PATH } = publicRuntimeConfig;
+const { APP_BASE_PATH, TELEGRAM_BOT_URL } = publicRuntimeConfig;
type FormData = {
readonly login: string;
@@ -49,6 +49,11 @@ function BaseForm({ children, onSubmit }: FormProps & PropsWithChildren) {
autoComplete="on"
{...register('password', { required: true })}
/>
+ {step === 'telegram-login' ? (
+
+ Открыть чат с ботом
+
+ ) : null}
{error ? {error} : null}
{children}
@@ -111,11 +116,16 @@ export const Form = {
}
function handleTelegramLogin() {
+ // window.open(TELEGRAM_BOT_URL);
axios
.post('/login-telegram')
- .then((res) => {
- // eslint-disable-next-line no-console
- console.log('🚀 ~ .then ~ res:', res);
+ .then(() => {
+ dispatch({
+ payload: {
+ step: 'telegram-login',
+ },
+ type: 'set-step',
+ });
})
.catch(() =>
dispatch({
@@ -142,6 +152,23 @@ export const Form = {
);
}
+ if (step === 'telegram-login') {
+ return (
+ {}}>
+
+
+ );
+ }
+
return (
handleLogin(data)}>