diff --git a/apps/api/src/app.controller.spec.ts b/apps/api/src/app.controller.spec.ts index a76112e..e3e4f2d 100644 --- a/apps/api/src/app.controller.spec.ts +++ b/apps/api/src/app.controller.spec.ts @@ -1,7 +1,7 @@ -import type { TestingModule } from '@nestjs/testing'; -import { Test } from '@nestjs/testing'; import { AppController } from './app.controller'; import { AppService } from './app.service'; +import type { TestingModule } from '@nestjs/testing'; +import { Test } from '@nestjs/testing'; describe('AppController', () => { let appController: AppController; diff --git a/apps/api/src/app.controller.ts b/apps/api/src/app.controller.ts index cce879e..fcfae70 100644 --- a/apps/api/src/app.controller.ts +++ b/apps/api/src/app.controller.ts @@ -1,5 +1,5 @@ -import { Controller, Get } from '@nestjs/common'; import { AppService } from './app.service'; +import { Controller, Get } from '@nestjs/common'; @Controller() export class AppController { diff --git a/apps/api/src/app.module.ts b/apps/api/src/app.module.ts index 1bf0d9b..266af32 100644 --- a/apps/api/src/app.module.ts +++ b/apps/api/src/app.module.ts @@ -1,14 +1,16 @@ -import { Global, Module } from '@nestjs/common'; -import { ConfigModule } from '@nestjs/config'; -import { JwtModule } from '@nestjs/jwt'; import { AppController } from './app.controller'; import { AppService } from './app.service'; import { AuthModule } from './auth/auth.module'; -import { UsersModule } from './users/users.module'; import { LdapModule } from './ldap/ldap.module'; +import { UsersModule } from './users/users.module'; +import { Global, Module } from '@nestjs/common'; +import { ConfigModule } from '@nestjs/config'; +import { JwtModule } from '@nestjs/jwt'; @Global() @Module({ + controllers: [AppController], + exports: [JwtModule], imports: [ ConfigModule.forRoot({ isGlobal: true, @@ -23,8 +25,7 @@ import { LdapModule } from './ldap/ldap.module'; UsersModule, LdapModule, ], - controllers: [AppController], providers: [AppService], - exports: [JwtModule], }) +// eslint-disable-next-line @typescript-eslint/no-extraneous-class export class AppModule {} diff --git a/apps/api/src/auth/auth.controller.spec.ts b/apps/api/src/auth/auth.controller.spec.ts index e3e4fda..2aa6ec7 100644 --- a/apps/api/src/auth/auth.controller.spec.ts +++ b/apps/api/src/auth/auth.controller.spec.ts @@ -1,7 +1,7 @@ -import type { TestingModule } from '@nestjs/testing'; -import { Test } from '@nestjs/testing'; import { AuthController } from './auth.controller'; import { AuthService } from './auth.service'; +import type { TestingModule } from '@nestjs/testing'; +import { Test } from '@nestjs/testing'; describe('AuthController', () => { let controller: AuthController; diff --git a/apps/api/src/auth/auth.controller.ts b/apps/api/src/auth/auth.controller.ts index f19e22d..2b550ce 100644 --- a/apps/api/src/auth/auth.controller.ts +++ b/apps/api/src/auth/auth.controller.ts @@ -1,10 +1,10 @@ /* eslint-disable class-methods-use-this */ /* eslint-disable import/no-extraneous-dependencies */ -import { Body, Controller, Get, HttpException, HttpStatus, Post, Req, Res } from '@nestjs/common'; -import { FastifyReply, FastifyRequest } from 'fastify'; import { AuthService } from './auth.service'; import { COOKIE_TOKEN_NAME } from './lib/constants'; import { Credentials } from './types/request'; +import { Body, Controller, Get, HttpException, HttpStatus, Post, Req, Res } from '@nestjs/common'; +import { FastifyReply, FastifyRequest } from 'fastify'; @Controller() export class AuthController { diff --git a/apps/api/src/auth/auth.module.ts b/apps/api/src/auth/auth.module.ts index 0ba5ea5..410c056 100644 --- a/apps/api/src/auth/auth.module.ts +++ b/apps/api/src/auth/auth.module.ts @@ -1,12 +1,13 @@ -import { Module } from '@nestjs/common'; import { LdapModule } from '../ldap/ldap.module'; import { UsersModule } from '../users/users.module'; import { AuthController } from './auth.controller'; import { AuthService } from './auth.service'; +import { Module } from '@nestjs/common'; @Module({ - imports: [UsersModule, LdapModule], controllers: [AuthController], + imports: [UsersModule, LdapModule], providers: [AuthService], }) +// eslint-disable-next-line @typescript-eslint/no-extraneous-class export class AuthModule {} diff --git a/apps/api/src/auth/auth.service.spec.ts b/apps/api/src/auth/auth.service.spec.ts index 4c67f38..207bb16 100644 --- a/apps/api/src/auth/auth.service.spec.ts +++ b/apps/api/src/auth/auth.service.spec.ts @@ -1,6 +1,6 @@ +import { AuthService } from './auth.service'; import type { TestingModule } from '@nestjs/testing'; import { Test } from '@nestjs/testing'; -import { AuthService } from './auth.service'; describe('AuthService', () => { let service: AuthService; diff --git a/apps/api/src/auth/auth.service.ts b/apps/api/src/auth/auth.service.ts index 738f6ba..d981ac8 100644 --- a/apps/api/src/auth/auth.service.ts +++ b/apps/api/src/auth/auth.service.ts @@ -1,8 +1,8 @@ -import { Injectable } from '@nestjs/common'; -import { JwtService } from '@nestjs/jwt'; import { LdapService } from '../ldap/ldap.service'; import { UsersCache } from '../users/users.cache'; import type { DecodedToken, TokenPayload } from './types/jwt'; +import { Injectable } from '@nestjs/common'; +import { JwtService } from '@nestjs/jwt'; @Injectable() export class AuthService { @@ -19,8 +19,8 @@ export class AuthService { await this.usersCache.addUser(username, user); const payload: TokenPayload = { - username, domain: process.env.LDAP_DOMAIN, + username, }; return this.jwtService.sign(payload); diff --git a/apps/api/src/ldap/ldap.module.ts b/apps/api/src/ldap/ldap.module.ts index 25fe500..2fae433 100644 --- a/apps/api/src/ldap/ldap.module.ts +++ b/apps/api/src/ldap/ldap.module.ts @@ -1,8 +1,9 @@ -import { Module } from '@nestjs/common'; import { LdapService } from './ldap.service'; +import { Module } from '@nestjs/common'; @Module({ - providers: [LdapService], exports: [LdapService], + providers: [LdapService], }) +// eslint-disable-next-line @typescript-eslint/no-extraneous-class export class LdapModule {} diff --git a/apps/api/src/ldap/ldap.service.spec.ts b/apps/api/src/ldap/ldap.service.spec.ts index 6711f8c..d5ed721 100644 --- a/apps/api/src/ldap/ldap.service.spec.ts +++ b/apps/api/src/ldap/ldap.service.spec.ts @@ -1,6 +1,6 @@ +import { LdapService } from './ldap.service'; import type { TestingModule } from '@nestjs/testing'; import { Test } from '@nestjs/testing'; -import { LdapService } from './ldap.service'; describe('LdapService', () => { let service: LdapService; diff --git a/apps/api/src/ldap/ldap.service.ts b/apps/api/src/ldap/ldap.service.ts index bc7f88d..059aace 100644 --- a/apps/api/src/ldap/ldap.service.ts +++ b/apps/api/src/ldap/ldap.service.ts @@ -1,22 +1,22 @@ +import type { User } from '../types/user'; +import type { LdapUser } from './types/user'; import { Injectable } from '@nestjs/common'; import type { AuthenticationOptions } from 'ldap-authentication'; import { authenticate } from 'ldap-authentication'; -import type { User } from '../types/user'; -import type { LdapUser } from './types/user'; @Injectable() export class LdapService { async authenticate(login: string, password?: string) { const options: AuthenticationOptions = { + adminDn: process.env.LDAP_BIND_DN, + adminPassword: process.env.LDAP_BIND_CREDENTIALS, ldapOpts: { url: process.env.LDAP_URL, }, - adminDn: process.env.LDAP_BIND_DN, - adminPassword: process.env.LDAP_BIND_CREDENTIALS, - userSearchBase: process.env.LDAP_BASE, - usernameAttribute: process.env.LDAP_ATTRIBUTE, - username: login, userPassword: password, + userSearchBase: process.env.LDAP_BASE, + username: login, + usernameAttribute: process.env.LDAP_ATTRIBUTE, verifyUserExists: password === undefined, }; @@ -29,13 +29,13 @@ export class LdapService { }: LdapUser = await authenticate(options); const user: User = { - username, - domain: process.env.LDAP_DOMAIN, - displayName, department, - position: title, - mail, + displayName, + domain: process.env.LDAP_DOMAIN, domainName: `${process.env.LDAP_DOMAIN}\\${username}`, + mail, + position: title, + username, }; return user; diff --git a/apps/api/src/ldap/types/user.ts b/apps/api/src/ldap/types/user.ts index ef30e2f..76368c8 100644 --- a/apps/api/src/ldap/types/user.ts +++ b/apps/api/src/ldap/types/user.ts @@ -1,63 +1,63 @@ export type LdapUser = { - dn: string; - controls: any[]; - objectClass: string[]; - cn: string; - sn: string; - c: string; - title: string; - physicalDeliveryOfficeName: string; - givenName: string; - distinguishedName: string; - instanceType: string; - whenCreated: string; - whenChanged: string; - displayName: string; - uSNCreated: string; - memberOf: string[]; - uSNChanged: string; - co: string; - department: string; - proxyAddresses: string[]; - name: string; - objectGUID: string; - userAccountControl: string; - badPwdCount: string; - codePage: string; - countryCode: string; - employeeID: string; + accountExpires: string; badPasswordTime: string; + badPwdCount: string; + c: string; + cn: string; + co: string; + codePage: string; + controls: unknown[]; + countryCode: string; + dSCorePropagationData: string[]; + department: string; + displayName: string; + distinguishedName: string; + dn: string; + employeeID: string; + extensionAttribute1: string; + extensionAttribute13: string; + extensionAttribute2: string; + givenName: string; + instanceType: string; lastLogoff: string; lastLogon: string; - pwdLastSet: string; - primaryGroupID: string; - objectSid: string; - accountExpires: string; + lastLogonTimestamp: string; + legacyExchangeDN: string; + lockoutTime: string; logonCount: string; + 'mS-DS-ConsistencyGuid': string; + mail: string; + mailNickname: string; + memberOf: string[]; + middleName: string; + 'msDS-KeyCredentialLink': string; + msExchMailboxGuid: string; + msExchPoliciesIncluded: string[]; + msExchRecipientDisplayType: string; + msExchRecipientTypeDetails: string; + msExchRemoteRecipientType: string; + msExchUMDtmfMap: string[]; + msExchVersion: string; + name: string; + objectCategory: string; + objectClass: string[]; + objectGUID: string; + objectSid: string; + physicalDeliveryOfficeName: string; + preferredLanguage: string; + primaryGroupID: string; + proxyAddresses: string[]; + pwdLastSet: string; sAMAccountName: string; sAMAccountType: string; showInAddressBook: string[]; - legacyExchangeDN: string; - userPrincipalName: string; - lockoutTime: string; - objectCategory: string; - dSCorePropagationData: string[]; - 'mS-DS-ConsistencyGuid': string; - lastLogonTimestamp: string; - 'msDS-KeyCredentialLink': string; - mail: string; - middleName: string; - preferredLanguage: string; - extensionAttribute2: string; - msExchVersion: string; - msExchRecipientDisplayType: string; - msExchRecipientTypeDetails: string; - extensionAttribute1: string; - msExchMailboxGuid: string; + sn: string; targetAddress: string; - msExchPoliciesIncluded: string[]; - extensionAttribute13: string; - mailNickname: string; - msExchRemoteRecipientType: string; - msExchUMDtmfMap: string[]; + title: string; + uSNChanged: string; + uSNCreated: string; + userAccountControl: string; + userPrincipalName: string; + whenChanged: string; + whenCreated: string; }; diff --git a/apps/api/src/main.ts b/apps/api/src/main.ts index 1122bc3..9b98573 100644 --- a/apps/api/src/main.ts +++ b/apps/api/src/main.ts @@ -1,9 +1,9 @@ /* eslint-disable unicorn/prefer-top-level-await */ -import fastifyCookie from '@fastify/cookie'; +import { AppModule } from './app.module'; +import { fastifyCookie } from '@fastify/cookie'; import { NestFactory } from '@nestjs/core'; import type { NestFastifyApplication } from '@nestjs/platform-fastify'; import { FastifyAdapter } from '@nestjs/platform-fastify'; -import { AppModule } from './app.module'; async function bootstrap() { const app = await NestFactory.create( diff --git a/apps/api/src/types/user.ts b/apps/api/src/types/user.ts index d6f1b84..8fb227d 100644 --- a/apps/api/src/types/user.ts +++ b/apps/api/src/types/user.ts @@ -1,9 +1,9 @@ export type User = { - displayName: string; - username: string; department: string; - position: string; - mail: string; + displayName: string; domain: string; domainName: string; + mail: string; + position: string; + username: string; }; diff --git a/apps/api/src/users/users.cache.ts b/apps/api/src/users/users.cache.ts index 1433e84..95d0f12 100644 --- a/apps/api/src/users/users.cache.ts +++ b/apps/api/src/users/users.cache.ts @@ -1,14 +1,12 @@ +import type { User } from '../types/user'; import { CACHE_MANAGER, Inject, Injectable } from '@nestjs/common'; import { Cache } from 'cache-manager'; -import type { User } from '../types/user'; @Injectable() export class UsersCache { constructor(@Inject(CACHE_MANAGER) private readonly cacheManager: Cache) {} async getUser(username: string) { - const user = (await this.cacheManager.get(username)) as User; - - return user; + return (await this.cacheManager.get(username)) as User; } async addUser(username: string, user: User) { diff --git a/apps/api/src/users/users.controller.spec.ts b/apps/api/src/users/users.controller.spec.ts index dabfea5..71c1341 100644 --- a/apps/api/src/users/users.controller.spec.ts +++ b/apps/api/src/users/users.controller.spec.ts @@ -1,7 +1,7 @@ -import type { TestingModule } from '@nestjs/testing'; -import { Test } from '@nestjs/testing'; import { UsersController } from './users.controller'; import { UsersService } from './users.service'; +import type { TestingModule } from '@nestjs/testing'; +import { Test } from '@nestjs/testing'; describe('UsersController', () => { let controller: UsersController; diff --git a/apps/api/src/users/users.controller.ts b/apps/api/src/users/users.controller.ts index 6785a23..909ec7a 100644 --- a/apps/api/src/users/users.controller.ts +++ b/apps/api/src/users/users.controller.ts @@ -1,9 +1,9 @@ /* eslint-disable class-methods-use-this */ /* eslint-disable import/no-extraneous-dependencies */ -import { Controller, Get, Req, Res } from '@nestjs/common'; -import { FastifyReply, FastifyRequest } from 'fastify'; import { COOKIE_TOKEN_NAME } from '../auth/lib/constants'; import { UsersService } from './users.service'; +import { Controller, Get, Req, Res } from '@nestjs/common'; +import { FastifyReply, FastifyRequest } from 'fastify'; @Controller() export class UsersController { diff --git a/apps/api/src/users/users.module.ts b/apps/api/src/users/users.module.ts index 1528709..58541f9 100644 --- a/apps/api/src/users/users.module.ts +++ b/apps/api/src/users/users.module.ts @@ -1,23 +1,24 @@ -import { CacheModule, Module } from '@nestjs/common'; -import * as redisStore from 'cache-manager-ioredis'; -import type { RedisOptions } from 'ioredis'; import { LdapModule } from '../ldap/ldap.module'; import { UsersCache } from './users.cache'; import { UsersController } from './users.controller'; import { UsersService } from './users.service'; +import { CacheModule, Module } from '@nestjs/common'; +import * as redisStore from 'cache-manager-ioredis'; +import type { RedisOptions } from 'ioredis'; @Module({ + controllers: [UsersController], + exports: [UsersCache], imports: [ CacheModule.register({ - store: redisStore, host: process.env.REDIS_HOST, port: Number.parseInt(process.env.REDIS_PORT, 10) || 6379, + store: redisStore, ttl: Number.parseInt(process.env.CACHE_TTL, 10), }), LdapModule, ], - controllers: [UsersController], providers: [UsersService, UsersCache], - exports: [UsersCache], }) +// eslint-disable-next-line @typescript-eslint/no-extraneous-class export class UsersModule {} diff --git a/apps/api/src/users/users.service.spec.ts b/apps/api/src/users/users.service.spec.ts index 594c5ab..c619357 100644 --- a/apps/api/src/users/users.service.spec.ts +++ b/apps/api/src/users/users.service.spec.ts @@ -1,6 +1,6 @@ +import { UsersService } from './users.service'; import type { TestingModule } from '@nestjs/testing'; import { Test } from '@nestjs/testing'; -import { UsersService } from './users.service'; describe('UsersService', () => { let service: UsersService; diff --git a/apps/api/src/users/users.service.ts b/apps/api/src/users/users.service.ts index 2a48f00..78f253c 100644 --- a/apps/api/src/users/users.service.ts +++ b/apps/api/src/users/users.service.ts @@ -1,8 +1,8 @@ +import type { DecodedToken } from '../auth/types/jwt'; +import { LdapService } from '../ldap/ldap.service'; +import { UsersCache } from './users.cache'; import { Injectable } from '@nestjs/common'; import { JwtService } from '@nestjs/jwt'; -import { LdapService } from '../ldap/ldap.service'; -import type { DecodedToken } from '../auth/types/jwt'; -import { UsersCache } from './users.cache'; @Injectable() export class UsersService { diff --git a/apps/api/test/app.e2e-spec.ts b/apps/api/test/app.e2e-spec.ts index 2573169..bb7dced 100644 --- a/apps/api/test/app.e2e-spec.ts +++ b/apps/api/test/app.e2e-spec.ts @@ -1,8 +1,8 @@ +import { AppModule } from '../src/app.module'; +import type { INestApplication } from '@nestjs/common'; import type { TestingModule } from '@nestjs/testing'; import { Test } from '@nestjs/testing'; -import type { INestApplication } from '@nestjs/common'; import * as request from 'supertest'; -import { AppModule } from '../src/app.module'; describe('AppController (e2e)', () => { let app: INestApplication; @@ -16,8 +16,5 @@ describe('AppController (e2e)', () => { await app.init(); }); - it('/ (GET)', () => request(app.getHttpServer()) - .get('/') - .expect(200) - .expect('Hello World!')); + it('/ (GET)', () => request(app.getHttpServer()).get('/').expect(200).expect('Hello World!')); }); diff --git a/apps/web/components/Form.jsx b/apps/web/components/Form.jsx index 05be22a..f62988d 100644 --- a/apps/web/components/Form.jsx +++ b/apps/web/components/Form.jsx @@ -1,18 +1,18 @@ -import Input from 'elements/Input'; -import Button from 'elements/Button'; import styles from './Form.module.scss'; -import { H3 } from 'elements/H'; -import { useRouter } from 'next/router'; -import Error from 'elements/Error'; -import getConfig from 'next/config'; import axios from 'axios'; +import Button from 'elements/Button'; +import Error from 'elements/Error'; +import { H3 } from 'elements/H'; +import Input from 'elements/Input'; +import getConfig from 'next/config'; +import { useRouter } from 'next/router'; import { useState } from 'react'; const { publicRuntimeConfig: config } = getConfig(); export default function Form() { const router = useRouter(); - const [hasError, setError] = useState(false); + const [hasError, setHasError] = useState(false); const error = hasError ? Неверный логин или пароль : null; return ( @@ -31,7 +31,7 @@ export default function Form() { router.reload(); }) .catch(() => { - setError(true); + setHasError(true); }); }} > diff --git a/apps/web/components/Login.jsx b/apps/web/components/Login.jsx index 50afd5a..bc4830f 100644 --- a/apps/web/components/Login.jsx +++ b/apps/web/components/Login.jsx @@ -1,6 +1,6 @@ import Form from './Form'; -import Logo from 'elements/Logo'; import styles from './Login.module.scss'; +import Logo from 'elements/Logo'; export default function Login() { return ( diff --git a/apps/web/elements/Button.tsx b/apps/web/elements/Button.tsx index ec778dd..8a230f3 100644 --- a/apps/web/elements/Button.tsx +++ b/apps/web/elements/Button.tsx @@ -4,7 +4,7 @@ type ButtonProps = JSX.IntrinsicElements['button']; export default function Button({ children, ...props }: ButtonProps) { return ( - ); diff --git a/apps/web/elements/Logo.jsx b/apps/web/elements/Logo.jsx index 94420f7..f45e4e1 100644 --- a/apps/web/elements/Logo.jsx +++ b/apps/web/elements/Logo.jsx @@ -1,5 +1,5 @@ -import logo from 'public/assets/images/logo-primary.svg'; import Image from 'next/image'; +import logo from 'public/assets/images/logo-primary.svg'; export default function Logo() { return logo; diff --git a/apps/web/pages/_app.tsx b/apps/web/pages/_app.tsx index 1cd013d..1e67015 100644 --- a/apps/web/pages/_app.tsx +++ b/apps/web/pages/_app.tsx @@ -1,9 +1,10 @@ -import type { AppProps } from 'next/app'; +/* eslint-disable react/no-unknown-property */ import 'normalize.css'; -import Head from 'next/head'; import '@fontsource/montserrat/400.css'; import '@fontsource/montserrat/600.css'; import '@fontsource/montserrat/700.css'; +import type { AppProps } from 'next/app'; +import Head from 'next/head'; export default function App({ Component, pageProps }: AppProps) { return ( diff --git a/package.json b/package.json index 6c034c8..dd77be9 100644 --- a/package.json +++ b/package.json @@ -3,14 +3,14 @@ "version": "0.0.0", "private": true, "workspaces": [ - "apps/*", - "packages/*" + "apps/*" ], "scripts": { "build": "turbo run build", "dev": "turbo run dev --parallel", "lint": "turbo run lint", "lint:fix": "turbo run lint:fix", + "clean": "turbo run clean", "format": "prettier --write \"**/*.{ts,tsx,md}\"" }, "devDependencies": { @@ -22,4 +22,4 @@ }, "dependencies": {}, "packageManager": "yarn@1.22.19" -} \ No newline at end of file +} diff --git a/turbo.json b/turbo.json index 8b58071..6c04f24 100644 --- a/turbo.json +++ b/turbo.json @@ -17,6 +17,9 @@ "dev": { "cache": false, "persistent": true + }, + "clean": { + "cache": false } } }