Skip to content

Commit

Permalink
merge: #391 IP, 이메일 관련 기능 전부 주석 처리
Browse files Browse the repository at this point in the history
[refactor] IP, 이메일 관련 기능 전부 주석 처리
  • Loading branch information
kmi0817 authored Jan 12, 2024
2 parents c673cb4 + 2e2839c commit 5c55098
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 68 deletions.
13 changes: 7 additions & 6 deletions BE/src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Controller, Get, Param, Render, Res } from '@nestjs/common';
import { Controller, Get, Param, Res } from '@nestjs/common';
import { AppService } from './app.service';

@Controller()
Expand All @@ -16,9 +16,10 @@ export class AppController {
response.redirect(url);
}

@Get('ip-process-result')
@Render('ip-process-result.ejs')
ipProcessResult() {
return {};
}
// 추후 수정 예정
// @Get('ip-process-result')
// @Render('ip-process-result.ejs')
// ipProcessResult() {
// return {};
// }
}
26 changes: 12 additions & 14 deletions BE/src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import {
Get,
Req,
UseGuards,
Query,
ParseBoolPipe,
Res,
} from '@nestjs/common';
import { AuthService } from './auth.service';
import { ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
Expand Down Expand Up @@ -72,15 +69,16 @@ export class AuthController {
return this.authService.withdrawal(request, deleteAuthDto);
}

@Get('ip')
async manageIp(
@Res() response,
@Query('id') id: string,
@Query('ip') ip: string,
@Query('allow', ParseBoolPipe) allow: boolean
) {
if (await this.authService.manageIp(id, ip, allow)) {
response.redirect('/ip-process-result');
}
}
// 추후 수정 예정
// @Get('ip')
// async manageIp(
// @Res() response,
// @Query('id') id: string,
// @Query('ip') ip: string,
// @Query('allow', ParseBoolPipe) allow: boolean
// ) {
// if (await this.authService.manageIp(id, ip, allow)) {
// response.redirect('/ip-process-result');
// }
// }
}
108 changes: 60 additions & 48 deletions BE/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,33 +115,35 @@ export class AuthService {
if (!user) {
throw new InternalServerErrorException();
}
} else {
const allowedIpArray = user.allowedIp;
let bannedIpArray;
if (user.bannedIp === null) {
bannedIpArray = [];
} else {
bannedIpArray = user.bannedIp;
}
if (ipAddress in bannedIpArray) {
throw new UnauthorizedException(
'접속하신 IP에서의 계정 접근이 차단되어있습니다.'
);
}
if (!(ipAddress in allowedIpArray)) {
const html = await this.emilService.template('email.ejs', {
username: user.name,
newIp: ipAddress,
id: user.id,
});

await this.emilService.sendEmail(
user.email,
'[traveline] 새로운 환경 로그인 안내',
html
);
}
}
// 추후 수정 예정
// else {
// const allowedIpArray = user.allowedIp;
// let bannedIpArray;
// if (user.bannedIp === null) {
// bannedIpArray = [];
// } else {
// bannedIpArray = user.bannedIp;
// }
// if (ipAddress in bannedIpArray) {
// throw new UnauthorizedException(
// '접속하신 IP에서의 계정 접근이 차단되어있습니다.'
// );
// }
// if (!(ipAddress in allowedIpArray)) {
// const html = await this.emilService.template('email.ejs', {
// username: user.name,
// newIp: ipAddress,
// id: user.id,
// });

// await this.emilService.sendEmail(
// user.email,
// '[traveline] 새로운 환경 로그인 안내',
// html
// );
// }
// }

const payload = { id: user.id };

Expand All @@ -160,29 +162,39 @@ export class AuthService {

if (user) {
const payload = { id };
try {
const html = await this.emilService.template('email.ejs', {
username: user.name,
newIp: '아 이 피',
id: user.id,
});

await this.emilService.sendEmail(
user.email,
'[traveline] 새로운 환경 로그인 안내',
html
);

return {
accessToken: await this.jwtService.signAsync(payload),
refreshToken: await this.jwtService.signAsync(payload, {
expiresIn: '30d',
secret: process.env.JWT_SECRET_REFRESH,
}),
};
} catch (e) {
console.log(e);
}
// 추후 수정 예정
// try {
// const html = await this.emilService.template('email.ejs', {
// username: user.name,
// newIp: '아 이 피',
// id: user.id,
// });

// await this.emilService.sendEmail(
// user.email,
// '[traveline] 새로운 환경 로그인 안내',
// html
// );

// return {
// accessToken: await this.jwtService.signAsync(payload),
// refreshToken: await this.jwtService.signAsync(payload, {
// expiresIn: '30d',
// secret: process.env.JWT_SECRET_REFRESH,
// }),
// };
// } catch (e) {
// console.log(e);
// }

return {
accessToken: await this.jwtService.signAsync(payload),
refreshToken: await this.jwtService.signAsync(payload, {
expiresIn: '30d',
secret: process.env.JWT_SECRET_REFRESH,
}),
};
}

throw new BadRequestException(
Expand Down

0 comments on commit 5c55098

Please sign in to comment.