Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

Renamed "Auth*" classes to "OldAuth*"

Yevhenii Kulisidif5f4ba5c51ea
diff --git a/src/app.module.ts b/src/app.module.ts
index a4d4cfba7..e0813e964 100644
--- a/src/app.module.ts
+++ b/src/app.module.ts
@@ -4,7 +4,7 @@ import { ConfigModule } from '@nestjs/config'
import { ScheduleModule } from '@nestjs/schedule'
import { TelegrafModule } from 'nestjs-telegraf'
-import { AuthModule } from './auth/auth.module'
+import { OldAuthModule } from './old-auth/auth.module'
import { UserModule } from './user/user.module'
import { AnalyticsModule } from './analytics/analytics.module'
import { ProjectModule } from './project/project.module'
@@ -32,7 +32,7 @@ const modules = [
}),
ScheduleModule.forRoot(),
TaskManagerModule,
- AuthModule,
+ OldAuthModule,
UserModule,
MailerModule,
ActionTokensModule,
diff --git a/src/auth/auth.controller.spec.ts b/src/old-auth/auth.controller.spec.ts
similarity index 91%
rename from src/auth/auth.controller.spec.ts
rename to src/old-auth/auth.controller.spec.ts
index 32c97fbab..c41754b43 100644
--- a/src/auth/auth.controller.spec.ts
+++ b/src/old-auth/auth.controller.spec.ts
@@ -1,7 +1,7 @@
import { getRepositoryToken } from '@nestjs/typeorm'
-import { AuthController } from './auth.controller'
+import { OldAuthController } from './auth.controller'
import { UserService } from '../user/user.service'
-import { AuthService } from './auth.service'
+import { OldAuthService } from './auth.service'
import { MailerService } from '../mailer/mailer.service'
import { ActionTokensService } from '../action-tokens/action-tokens.service'
import { ProjectService } from '../project/project.service'
@@ -13,8 +13,8 @@ import { Project } from '../project/entity/project.entity'
import { ProjectShare } from '../project/entity/project-share.entity'
import { Test, TestingModule } from '@nestjs/testing'
-describe('AuthController', () => {
- let controller: AuthController
+describe('OldAuthController', () => {
+ let controller: OldAuthController
const USER_REPOSITORY_TOKEN = getRepositoryToken(User)
const ACTION_TOKEN_REPOSITORY_TOKEN = getRepositoryToken(ActionToken)
@@ -23,9 +23,9 @@ describe('AuthController', () => {
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
- controllers: [AuthController],
+ controllers: [OldAuthController],
providers: [
- AuthService,
+ OldAuthService,
UserService,
{
provide: USER_REPOSITORY_TOKEN,
@@ -69,7 +69,7 @@ describe('AuthController', () => {
],
}).compile()
- controller = module.get<AuthController>(AuthController)
+ controller = module.get<OldAuthController>(OldAuthController)
})
describe('root', () => {
diff --git a/src/auth/auth.controller.ts b/src/old-auth/auth.controller.ts
similarity index 91%
rename from src/auth/auth.controller.ts
rename to src/old-auth/auth.controller.ts
index bbc09bcee..b766a9908 100644
--- a/src/auth/auth.controller.ts
+++ b/src/old-auth/auth.controller.ts
@@ -14,7 +14,7 @@ import {
import { Request } from 'express'
import { ApiTags } from '@nestjs/swagger'
-import { AuthService } from './auth.service'
+import { OldAuthService } from './auth.service'
import { UserLoginDTO } from './dto/user-login.dto'
import { SignupUserDTO } from './dto/user-signup.dto'
import { UserService } from '../user/user.service'
@@ -48,9 +48,9 @@ import ct from 'countries-and-timezones'
// TODO: Add logout endpoint to invalidate the token
@ApiTags('Auth')
@Controller('auth')
-export class AuthController {
+export class OldAuthController {
constructor(
- private authService: AuthService,
+ private oldAuthService: OldAuthService,
private userService: UserService,
private mailerService: MailerService,
private actionTokensService: ActionTokensService,
@@ -78,7 +78,7 @@ export class AuthController {
},
relations: ['project'],
})
- user = this.authService.processUser(
+ user = this.oldAuthService.processUser(
await this.userService.findOneWhere({ id: user_id }),
)
@@ -99,7 +99,7 @@ export class AuthController {
headers['cf-connecting-ip'] || headers['x-forwarded-for'] || reqIP || ''
await checkRateLimit(ip, 'login', 10, 1800)
const { 'user-agent': userAgent } = headers
- // await this.authService.checkCaptcha(userLoginDTO.recaptcha)
+ // await this.oldAuthService.checkCaptcha(userLoginDTO.recaptcha)
if (isSelfhosted) {
if (
@@ -108,18 +108,18 @@ export class AuthController {
) {
throw new UnprocessableEntityException('Email or password is incorrect')
}
- return this.authService.login({
+ return this.oldAuthService.login({
email: SELFHOSTED_EMAIL,
})
} else {
- const user = await this.authService.validateUser(
+ const user = await this.oldAuthService.validateUser(
userLoginDTO.email,
userLoginDTO.password,
)
if (user.isTwoFactorAuthenticationEnabled) {
- const processedUser = this.authService.postLoginProcess(user)
- return this.authService.login(processedUser)
+ const processedUser = this.oldAuthService.postLoginProcess(user)
+ return this.oldAuthService.login(processedUser)
}
const sharedProjects = await this.projectService.findShare({
@@ -167,7 +167,7 @@ export class AuthController {
)
}
- return this.authService.login(user)
+ return this.oldAuthService.login(user)
}
}
@@ -184,12 +184,12 @@ export class AuthController {
headers['cf-connecting-ip'] || headers['x-forwarded-for'] || reqIP || ''
if (userDTO.checkIfLeaked) {
- await this.authService.checkIfPasswordLeaked(userDTO.password)
+ await this.oldAuthService.checkIfPasswordLeaked(userDTO.password)
}
await checkRateLimit(ip, 'register', 6)
- // await this.authService.checkCaptcha(recaptcha)
+ // await this.oldAuthService.checkCaptcha(recaptcha)
this.userService.validatePassword(userDTO.password)
const doesEmailExist = await this.userService.findOneWhere({
@@ -200,7 +200,7 @@ export class AuthController {
throw new BadRequestException('emailRegistered')
}
- userDTO.password = await this.authService.hashPassword(userDTO.password)
+ userDTO.password = await this.oldAuthService.hashPassword(userDTO.password)
try {
const userToUpdate = _pick(userDTO, ['email', 'password'])
@@ -215,7 +215,7 @@ export class AuthController {
})
user.sharedProjects = []
- return this.authService.login(user)
+ return this.oldAuthService.login(user)
} catch (e) {
this.logger.log(
`[ERROR WHILE CREATING ACCOUNT]: ${e}`,
@@ -326,7 +326,7 @@ export class AuthController {
}
if (actionToken.action === ActionTokenType.PASSWORD_RESET) {
- const password = await this.authService.hashPassword(body.password)
+ const password = await this.oldAuthService.hashPassword(body.password)
await this.userService.update(actionToken.user.id, {
...actionToken.user,
diff --git a/src/auth/auth.module.ts b/src/old-auth/auth.module.ts
similarity index 68%
rename from src/auth/auth.module.ts
rename to src/old-auth/auth.module.ts
index a17cc47c3..833858003 100644
--- a/src/auth/auth.module.ts
+++ b/src/old-auth/auth.module.ts
@@ -1,7 +1,7 @@
import { Module, forwardRef } from '@nestjs/common'
-import { AuthService } from './auth.service'
+import { OldAuthService } from './auth.service'
import { UserModule } from '../user/user.module'
-import { AuthController } from './auth.controller'
+import { OldAuthController } from './auth.controller'
import { MailerModule } from '../mailer/mailer.module'
import { ProjectModule } from '../project/project.module'
import { ActionTokensModule } from '../action-tokens/action-tokens.module'
@@ -15,8 +15,8 @@ import { AppLoggerModule } from '../logger/logger.module'
AppLoggerModule,
ProjectModule,
],
- controllers: [AuthController],
- providers: [AuthService],
- exports: [AuthService],
+ controllers: [OldAuthController],
+ providers: [OldAuthService],
+ exports: [OldAuthService],
})
-export class AuthModule {}
+export class OldAuthModule {}
diff --git a/src/auth/auth.service.spec.ts b/src/old-auth/auth.service.spec.ts
similarity index 96%
rename from src/auth/auth.service.spec.ts
rename to src/old-auth/auth.service.spec.ts
index 28aa49e54..5ce3bf115 100644
--- a/src/auth/auth.service.spec.ts
+++ b/src/old-auth/auth.service.spec.ts
@@ -5,11 +5,11 @@ import { User } from 'src/user/entities/user.entity'
import { UserService } from 'src/user/user.service'
import { Util } from 'src/Util/Util'
import { Repository } from 'typeorm'
-import { AuthService } from './auth.service'
+import { OldAuthService } from './auth.service'
import * as bcrypt from 'bcrypt'
-describe('AuthService', () => {
- let service: AuthService
+describe('OldAuthService', () => {
+ let service: OldAuthService
let repository: Repository<User>
let util = new Util()
const USER_REPOSITORY_TOKEN = getRepositoryToken(User)
@@ -17,7 +17,7 @@ describe('AuthService', () => {
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
- AuthService,
+ OldAuthService,
UserService,
{
provide: USER_REPOSITORY_TOKEN,
@@ -28,7 +28,7 @@ describe('AuthService', () => {
}).compile()
repository = module.get<Repository<User>>(USER_REPOSITORY_TOKEN)
- service = module.get<AuthService>(AuthService)
+ service = module.get<OldAuthService>(OldAuthService)
})
describe('root', () => {
it('should be defined service', () => {
diff --git a/src/auth/auth.service.ts b/src/old-auth/auth.service.ts
similarity index 99%
rename from src/auth/auth.service.ts
rename to src/old-auth/auth.service.ts
index 71281829f..965e1e52c 100644
--- a/src/auth/auth.service.ts
+++ b/src/old-auth/auth.service.ts
@@ -32,7 +32,7 @@ const httpsOptions = {
}
@Injectable()
-export class AuthService {
+export class OldAuthService {
constructor(
private userService: UserService,
private readonly logger: AppLoggerService,
diff --git a/src/auth/dto/password-change.dto.ts b/src/old-auth/dto/password-change.dto.ts
similarity index 100%
rename from src/auth/dto/password-change.dto.ts
rename to src/old-auth/dto/password-change.dto.ts
diff --git a/src/auth/dto/request-pass-change.dto.ts b/src/old-auth/dto/request-pass-change.dto.ts
similarity index 100%
rename from src/auth/dto/request-pass-change.dto.ts
rename to src/old-auth/dto/request-pass-change.dto.ts
diff --git a/src/auth/dto/user-login.dto.ts b/src/old-auth/dto/user-login.dto.ts
similarity index 100%
rename from src/auth/dto/user-login.dto.ts
rename to src/old-auth/dto/user-login.dto.ts
diff --git a/src/auth/dto/user-signup.dto.ts b/src/old-auth/dto/user-signup.dto.ts
similarity index 100%
rename from src/auth/dto/user-signup.dto.ts
rename to src/old-auth/dto/user-signup.dto.ts
diff --git a/src/twoFactorAuth/twoFactorAuth.controller.spec.ts b/src/twoFactorAuth/twoFactorAuth.controller.spec.ts
index 93407c637..a2042f210 100644
--- a/src/twoFactorAuth/twoFactorAuth.controller.spec.ts
+++ b/src/twoFactorAuth/twoFactorAuth.controller.spec.ts
@@ -1,6 +1,6 @@
import { Test, TestingModule } from '@nestjs/testing'
import { getRepositoryToken } from '@nestjs/typeorm'
-import { AuthService } from 'src/auth/auth.service'
+import { OldAuthService } from 'src/old-auth/auth.service'
import { AppLoggerService } from 'src/logger/logger.service'
import { MailerService } from 'src/mailer/mailer.service'
import { User } from 'src/user/entities/user.entity'
@@ -22,7 +22,7 @@ describe('TwoFactorAuthController', () => {
provide: USER_REPOSITORY_TOKEN,
useValue: { create: jest.fn(), save: jest.fn(), findOne: jest.fn() },
},
- AuthService,
+ OldAuthService,
AppLoggerService,
MailerService,
],
diff --git a/src/twoFactorAuth/twoFactorAuth.controller.ts b/src/twoFactorAuth/twoFactorAuth.controller.ts
index e58142fba..3e96ec952 100644
--- a/src/twoFactorAuth/twoFactorAuth.controller.ts
+++ b/src/twoFactorAuth/twoFactorAuth.controller.ts
@@ -12,7 +12,7 @@ import { ApiTags } from '@nestjs/swagger'
import { TwoFactorAuthService } from './twoFactorAuth.service'
import { UserService } from '../user/user.service'
-import { AuthService } from '../auth/auth.service'
+import { OldAuthService } from '../old-auth/auth.service'
import { UserType } from '../user/entities/user.entity'
import { AppLoggerService } from '../logger/logger.service'
import { MailerService } from '../mailer/mailer.service'
@@ -31,7 +31,7 @@ export class TwoFactorAuthController {
constructor(
private twoFactorAuthService: TwoFactorAuthService,
private userService: UserService,
- private authService: AuthService,
+ private oldAuthService: OldAuthService,
private readonly logger: AppLoggerService,
private readonly mailerService: MailerService,
) {}
@@ -90,7 +90,7 @@ export class TwoFactorAuthController {
user.isTwoFactorAuthenticationEnabled = true
- const authData = this.authService.login(user, true)
+ const authData = this.oldAuthService.login(user, true)
return {
twoFactorRecoveryCode,
@@ -170,6 +170,6 @@ export class TwoFactorAuthController {
throw new BadRequestException('Wrong authentication code')
}
- return this.authService.login(user, true)
+ return this.oldAuthService.login(user, true)
}
}
diff --git a/src/twoFactorAuth/twoFactorAuth.module.ts b/src/twoFactorAuth/twoFactorAuth.module.ts
index ab13390ec..3c9d70c9e 100644
--- a/src/twoFactorAuth/twoFactorAuth.module.ts
+++ b/src/twoFactorAuth/twoFactorAuth.module.ts
@@ -1,13 +1,13 @@
import { Module } from '@nestjs/common'
import { TwoFactorAuthService } from './twoFactorAuth.service'
import { UserModule } from '../user/user.module'
-import { AuthModule } from '../auth/auth.module'
+import { OldAuthModule } from '../old-auth/auth.module'
import { TwoFactorAuthController } from './twoFactorAuth.controller'
import { AppLoggerModule } from '../logger/logger.module'
import { MailerModule } from '../mailer/mailer.module'
@Module({
- imports: [UserModule, AppLoggerModule, AuthModule, MailerModule],
+ imports: [UserModule, AppLoggerModule, OldAuthModule, MailerModule],
controllers: [TwoFactorAuthController],
providers: [TwoFactorAuthService],
exports: [TwoFactorAuthService],
diff --git a/src/user/user.controller.spec.ts b/src/user/user.controller.spec.ts
index 04cabdb13..6bee2520a 100644
--- a/src/user/user.controller.spec.ts
+++ b/src/user/user.controller.spec.ts
@@ -2,7 +2,7 @@ import { Test, TestingModule } from '@nestjs/testing'
import { getRepositoryToken } from '@nestjs/typeorm'
import { ActionToken } from 'src/action-tokens/action-token.entity'
import { ActionTokensService } from 'src/action-tokens/action-tokens.service'
-import { AuthService } from 'src/auth/auth.service'
+import { OldAuthService } from 'src/old-auth/auth.service'
import { AppLoggerService } from 'src/logger/logger.service'
import { MailerService } from 'src/mailer/mailer.service'
import { ProjectShare } from 'src/project/entity/project-share.entity'
@@ -27,7 +27,7 @@ describe('UserController', () => {
provide: USER_REPOSITORY_TOKEN,
useValue: { create: jest.fn(), save: jest.fn(), findOne: jest.fn() },
},
- AuthService,
+ OldAuthService,
ProjectService,
{
provide: PROJECT_REPOSITORY_TOKEN,
diff --git a/src/user/user.controller.ts b/src/user/user.controller.ts
index e7fe293ed..f00ba7e4a 100644
--- a/src/user/user.controller.ts
+++ b/src/user/user.controller.ts
@@ -49,7 +49,7 @@ import { CurrentUserId } from '../common/decorators/current-user-id.decorator'
import { ActionTokensService } from '../action-tokens/action-tokens.service'
import { MailerService } from '../mailer/mailer.service'
import { ActionTokenType } from '../action-tokens/action-token.entity'
-import { AuthService } from '../auth/auth.service'
+import { OldAuthService } from '../old-auth/auth.service'
import { LetterTemplate } from '../mailer/letter'
import { AppLoggerService } from '../logger/logger.service'
import { UserProfileDTO } from './dto/user.dto'
@@ -67,7 +67,7 @@ export type TelegrafContext = Scenes.SceneContext
export class UserController {
constructor(
private readonly userService: UserService,
- private readonly authService: AuthService,
+ private readonly oldAuthService: OldAuthService,
private readonly projectService: ProjectService,
private readonly actionTokensService: ActionTokensService,
private readonly mailerService: MailerService,
@@ -120,7 +120,7 @@ export class UserController {
async create(@Body() userDTO: UserProfileDTO): Promise<User> {
this.logger.log({ userDTO }, 'POST /user')
this.userService.validatePassword(userDTO.password)
- userDTO.password = await this.authService.hashPassword(userDTO.password)
+ userDTO.password = await this.oldAuthService.hashPassword(userDTO.password)
try {
const user = await this.userService.create({ ...userDTO, isActive: true })
@@ -372,7 +372,7 @@ export class UserController {
if (userDTO.password) {
this.userService.validatePassword(userDTO.password)
- userDTO.password = await this.authService.hashPassword(userDTO.password)
+ userDTO.password = await this.oldAuthService.hashPassword(userDTO.password)
}
const user = await this.userService.findOneWhere({ id })
@@ -431,7 +431,7 @@ export class UserController {
if (!_isEmpty(userDTO.password) && _isString(userDTO.password)) {
this.userService.validatePassword(userDTO.password)
- userDTO.password = await this.authService.hashPassword(userDTO.password)
+ userDTO.password = await this.oldAuthService.hashPassword(userDTO.password)
await this.mailerService.sendEmail(
userDTO.email,
LetterTemplate.PasswordChanged,
diff --git a/src/user/user.module.ts b/src/user/user.module.ts
index bac4f81f7..ff84bbd59 100644
--- a/src/user/user.module.ts
+++ b/src/user/user.module.ts
@@ -6,7 +6,7 @@ import { UserService } from './user.service'
import { User } from './entities/user.entity'
import { ActionTokensModule } from '../action-tokens/action-tokens.module'
import { MailerModule } from '../mailer/mailer.module'
-import { AuthModule } from '../auth/auth.module'
+import { OldAuthModule } from '../old-auth/auth.module'
import { AppLoggerModule } from '../logger/logger.module'
import { ProjectModule } from '../project/project.module'
@@ -15,7 +15,7 @@ import { ProjectModule } from '../project/project.module'
TypeOrmModule.forFeature([User]),
ActionTokensModule,
MailerModule,
- forwardRef(() => AuthModule),
+ forwardRef(() => OldAuthModule),
AppLoggerModule,
ProjectModule,
],