issue # 회원가입 로직 구현 완료
This commit is contained in:
6
.env
6
.env
@@ -4,12 +4,12 @@ PGPORT=15454
|
||||
PGDATABASE=scheduler
|
||||
PGUSER=baekyangdan
|
||||
PGPASSWORD=qwas745478!
|
||||
PG_DATABASE_URL=postgres://baekyangdan:qwas745478!@bkdhome.p-e.kr:15454/scheduler
|
||||
PG_DATABASE_URL=postgres://baekyangdan:qwas745478!@bkdhome.p-e.kr:5454/scheduler
|
||||
|
||||
# Redis 설정
|
||||
RD_HOST=bkdhome.p-e.kr
|
||||
RD_PORT=16779
|
||||
RD_URL=redis://bkdhome.p-e.kr:16779
|
||||
RD_PORT=6779
|
||||
RD_URL=redis://bkdhome.p-e.kr:6779
|
||||
|
||||
# Express 서버 포트
|
||||
PORT=3000
|
||||
|
||||
942
.yarn/releases/yarn-4.11.0.cjs
vendored
Normal file
942
.yarn/releases/yarn-4.11.0.cjs
vendored
Normal file
File diff suppressed because one or more lines are too long
2
.yarnrc.yml
Normal file
2
.yarnrc.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
yarnPath: .yarn/releases/yarn-4.11.0.cjs
|
||||
nodeLinker: node-modules
|
||||
@@ -54,7 +54,7 @@ export const account = pgTable("account", {
|
||||
birthday: date(),
|
||||
accountId: varchar("account_id").notNull(),
|
||||
nickname: varchar().notNull(),
|
||||
status: varchar().default('wait').notNull(),
|
||||
status: varchar().default('active').notNull(),
|
||||
isDeleted: boolean("is_deleted").default(false).notNull(),
|
||||
createdAt: date("created_at").defaultNow().notNull(),
|
||||
id: uuid().default(sql`uuid_generate_v4()`).primaryKey().notNull(),
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
"@nestjs/common": "^11.0.1",
|
||||
"@nestjs/core": "^11.0.1",
|
||||
"@nestjs/platform-express": "^11.0.1",
|
||||
"bcrypt": "^6.0.0",
|
||||
"dotenv": "^17.2.3",
|
||||
"drizzle-kit": "^0.31.7",
|
||||
"drizzle-orm": "^0.44.7",
|
||||
@@ -41,6 +42,7 @@
|
||||
"@nestjs/cli": "^11.0.0",
|
||||
"@nestjs/schematics": "^11.0.0",
|
||||
"@nestjs/testing": "^11.0.1",
|
||||
"@types/bcrypt": "^6",
|
||||
"@types/express": "^5.0.0",
|
||||
"@types/ioredis": "^5.0.0",
|
||||
"@types/jest": "^30.0.0",
|
||||
@@ -79,5 +81,6 @@
|
||||
],
|
||||
"coverageDirectory": "../coverage",
|
||||
"testEnvironment": "node"
|
||||
}
|
||||
},
|
||||
"packageManager": "yarn@4.11.0"
|
||||
}
|
||||
|
||||
18
src/main.ts
18
src/main.ts
@@ -6,6 +6,24 @@ dotenv.config();
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule);
|
||||
app.enableCors({
|
||||
origin: (origin, callback) => {
|
||||
// origin이 없는 경우(local file, curl 등) 허용
|
||||
if (!origin) return callback(null, true);
|
||||
|
||||
// 특정 도메인만 막고 싶은 경우 whitelist 가능
|
||||
const whitelist = ["http://localhost:5173", "https://scheduler.bkdhome.p-e.kr"];
|
||||
if (whitelist.includes(origin)) {
|
||||
return callback(null, true);
|
||||
}
|
||||
|
||||
// 그 외 모든 도메인 허용 → 사실상 wildcard
|
||||
return callback(null, true);
|
||||
},
|
||||
credentials: true,
|
||||
});
|
||||
|
||||
|
||||
await app.listen(process.env.PORT ?? 3000);
|
||||
}
|
||||
bootstrap();
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import { Body, Controller, Get, Post, Query } from "@nestjs/common";
|
||||
import { CheckDuplicationRequestDto } from "./dto/checkDuplication/check-duplication-request.dto";
|
||||
import { CheckDuplicationResponseDto } from "./dto/checkDuplication/check-duplication-response.dto";
|
||||
import { AccountService } from "./account.service";
|
||||
import { SendVerificationCodeRequestDto } from "./dto/sendVerification/send-verification-code-request.dto";
|
||||
import { SendVerificationCodeResponseDto } from "./dto/sendVerification/send-verification-code-response.dto";
|
||||
import {
|
||||
CheckDuplicationRequest, CheckDuplicationResponse,
|
||||
SendVerificationCodeRequest, SendVerificationCodeResponse,
|
||||
VerifyCodeRequest, VerifyCodeResponse,
|
||||
LoginRequest, LoginResponse,
|
||||
SignupRequest, SignupResponse
|
||||
} from "./dto";
|
||||
|
||||
@Controller('account')
|
||||
export class AccountController {
|
||||
@@ -15,13 +18,26 @@ export class AccountController {
|
||||
}
|
||||
|
||||
@Get('check-duplication')
|
||||
async checkDuplication(@Query() query: CheckDuplicationRequestDto): Promise<CheckDuplicationResponseDto> {
|
||||
async checkDuplication(@Query() query: CheckDuplicationRequest): Promise<CheckDuplicationResponse> {
|
||||
return await this.accountService.checkDuplication(query);
|
||||
}
|
||||
|
||||
@Post('send-verification-code')
|
||||
async sendVerificationCode(@Body() body: SendVerificationCodeRequestDto): Promise<SendVerificationCodeResponseDto> {
|
||||
async sendVerificationCode(@Body() body: SendVerificationCodeRequest): Promise<SendVerificationCodeResponse> {
|
||||
const result = await this.accountService.sendVerificationCode(body);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Post('verify-code')
|
||||
async verifyCode(@Body() body: VerifyCodeRequest): Promise<VerifyCodeResponse> {
|
||||
console.log(body.email);
|
||||
const result = await this.accountService.verifyCode(body);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Post('signup')
|
||||
async signup(@Body() body: SignupRequest): Promise<LoginResponse> {
|
||||
const result = await this.accountService.signup(body);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -19,17 +19,24 @@ export class AccountRepo {
|
||||
return result[0].count;
|
||||
}
|
||||
|
||||
async activeAccount(email: string) {
|
||||
async signup(
|
||||
accountId: string,
|
||||
name: string,
|
||||
nickname: string,
|
||||
email: string,
|
||||
password: string
|
||||
) {
|
||||
return this
|
||||
.db
|
||||
.update(schema.account)
|
||||
.set({ status: 'active' })
|
||||
.where(
|
||||
and(
|
||||
eq(schema.account.email, email),
|
||||
eq(schema.account.status, 'wait'),
|
||||
eq(schema.account.isDeleted, false)
|
||||
)
|
||||
)
|
||||
.insert(schema.account)
|
||||
.values({
|
||||
accountId: accountId,
|
||||
name: name,
|
||||
nickname: nickname,
|
||||
email: email,
|
||||
password: password
|
||||
});
|
||||
}
|
||||
|
||||
async
|
||||
}
|
||||
@@ -1,14 +1,10 @@
|
||||
import { Inject, Injectable } from "@nestjs/common";
|
||||
import { AccountRepo } from "./account.repo";
|
||||
import { CheckDuplicationRequestDto } from "./dto/checkDuplication/check-duplication-request.dto";
|
||||
import { CheckDuplicationResponseDto } from "./dto/checkDuplication/check-duplication-response.dto";
|
||||
import { SendVerificationCodeRequestDto } from "./dto/sendVerification/send-verification-code-request.dto";
|
||||
import * as DTO from './dto';
|
||||
import { MailerService } from "src/util/mailer/mailer.service";
|
||||
import { Generator } from "src/util/generator";
|
||||
import { SendVerificationCodeResponseDto } from "./dto/sendVerification/send-verification-code-response.dto";
|
||||
import Redis from "ioredis";
|
||||
import { VerifyCodeResponseDto } from "./dto/verifyCode/verify-code-response.dto";
|
||||
import { VerifyCodeRequestDto } from "./dto/verifyCode/verify-code-request.dto";
|
||||
import { Converter } from "src/util/converter";
|
||||
|
||||
@Injectable()
|
||||
export class AccountService {
|
||||
@@ -18,35 +14,60 @@ export class AccountService {
|
||||
, @Inject("REDIS") private readonly redis: Redis
|
||||
) {}
|
||||
|
||||
async checkDuplication(data: CheckDuplicationRequestDto): Promise<CheckDuplicationResponseDto> {
|
||||
const count = await this.accountRepo.checkDuplication(data.type, data.value);
|
||||
async checkDuplication(data: DTO.CheckDuplicationRequest): Promise<DTO.CheckDuplicationResponse> {
|
||||
const { type, value } = data;
|
||||
const count = await this.accountRepo.checkDuplication(type, value);
|
||||
|
||||
return { isDuplicated: count > 0 };
|
||||
}
|
||||
|
||||
async sendVerificationCode(data: SendVerificationCodeRequestDto): Promise<SendVerificationCodeResponseDto> {
|
||||
async sendVerificationCode(data: DTO.SendVerificationCodeRequest): Promise<DTO.SendVerificationCodeResponse> {
|
||||
const { email } = data;
|
||||
const code = Generator.getVerificationCode();
|
||||
const html = `<p>Your verification code is: <strong style="font-size:16px;">${code}</strong></p>`;
|
||||
const result = await this.mailerService.sendMail(data.email, "<Scheduler> 이메일 인증 코드", html);
|
||||
const result = await this.mailerService.sendMail(email, "<Scheduler> 이메일 인증 코드", html);
|
||||
|
||||
if (result.rejected.length > 0) {
|
||||
return { success: false, error: result.response }
|
||||
} else {
|
||||
await this.redis.set(`verify:${data.email}`, code, 'EX', 600);
|
||||
await this.redis.set(`verify:${email}`, code, 'EX', 600);
|
||||
|
||||
return { success: true, message: "이메일 발송 완료" };
|
||||
}
|
||||
}
|
||||
|
||||
async verifyCode(data: VerifyCodeRequestDto): Promise<VerifyCodeResponseDto>{
|
||||
async verifyCode(data: DTO.VerifyCodeRequest): Promise<DTO.VerifyCodeResponse> {
|
||||
const { email, code } = data;
|
||||
|
||||
const storedCode = await this.redis.get(`verify:${email}`);
|
||||
|
||||
if (!storedCode) return { verified: false, error: '잘못된 이메일이거나 코드가 만료되었습니다.'};
|
||||
if (storedCode !== code) return { verified: false, error: "잘못된 코드입니다." };
|
||||
if (!storedCode) {
|
||||
return { verified: false, error: '잘못된 이메일이거나 코드가 만료되었습니다.'};
|
||||
}
|
||||
if (storedCode !== code) {
|
||||
return { verified: false, error: "잘못된 코드입니다." };
|
||||
}
|
||||
|
||||
await this.redis.del(`verify:${email}`);
|
||||
return { verified: true, message: "이메일 인증이 완료되었습니다." };
|
||||
}
|
||||
|
||||
async signup(data: DTO.SignupRequest): Promise<DTO.SignupResponse> {
|
||||
const { accountId, name, nickname, email, password } = data;
|
||||
const hashedPassword = Converter.getHashedPassword(password);
|
||||
const result = await this.accountRepo.signup(accountId, name, nickname, email, hashedPassword);
|
||||
|
||||
if (result.rowCount) {
|
||||
return {
|
||||
success: true,
|
||||
message: "회원가입이 완료되었습니다."
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
success: false,
|
||||
error: "회원가입에 실패하였습니다."
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
14
src/modules/account/dto/index.ts
Normal file
14
src/modules/account/dto/index.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
export { CheckDuplicationRequestDto as CheckDuplicationRequest } from './checkDuplication/check-duplication-request.dto';
|
||||
export { CheckDuplicationResponseDto as CheckDuplicationResponse } from './checkDuplication/check-duplication-response.dto';
|
||||
|
||||
export { SendVerificationCodeRequestDto as SendVerificationCodeRequest } from './sendVerification/send-verification-code-request.dto';
|
||||
export { SendVerificationCodeResponseDto as SendVerificationCodeResponse } from './sendVerification/send-verification-code-response.dto';
|
||||
|
||||
export { VerifyCodeRequestDto as VerifyCodeRequest } from './verifyCode/verify-code-request.dto';
|
||||
export { VerifyCodeResponseDto as VerifyCodeResponse } from './verifyCode/verify-code-response.dto';
|
||||
|
||||
export { SignupRequestDto as SignupRequest } from './signup/signup-request.dto';
|
||||
export { SignupResponseDto as SignupResponse } from './signup/signup-response.dto';
|
||||
|
||||
export { LoginRequestDto as LoginRequest } from './login/login-request.dto';
|
||||
export { LoginResponseDto as LoginResponse } from './login/login-response.dto'
|
||||
11
src/modules/account/dto/login/login-request.dto.ts
Normal file
11
src/modules/account/dto/login/login-request.dto.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { IsString } from "@nestjs/class-validator";
|
||||
|
||||
export class LoginRequestDto {
|
||||
type: 'email' | 'accountId';
|
||||
|
||||
@IsString()
|
||||
id: string;
|
||||
|
||||
@IsString()
|
||||
password: string;
|
||||
}
|
||||
5
src/modules/account/dto/login/login-response.dto.ts
Normal file
5
src/modules/account/dto/login/login-response.dto.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export class LoginResponseDto {
|
||||
success: boolean;
|
||||
message?: string;
|
||||
error?: string;
|
||||
}
|
||||
18
src/modules/account/dto/signup/signup-request.dto.ts
Normal file
18
src/modules/account/dto/signup/signup-request.dto.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { IsEmail, IsString } from "@nestjs/class-validator";
|
||||
|
||||
export class SignupRequestDto {
|
||||
@IsEmail()
|
||||
email: string;
|
||||
|
||||
@IsString()
|
||||
name: string;
|
||||
|
||||
@IsString()
|
||||
nickname: string;
|
||||
|
||||
@IsString()
|
||||
accountId: string;
|
||||
|
||||
@IsString()
|
||||
password: string;
|
||||
}
|
||||
5
src/modules/account/dto/signup/signup-response.dto.ts
Normal file
5
src/modules/account/dto/signup/signup-response.dto.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export class SignupResponseDto {
|
||||
success: boolean;
|
||||
message?: string;
|
||||
error?: string;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import bcrypt from 'bcrypt';
|
||||
|
||||
export class Converter {
|
||||
static getHashedPassword(password: string) {
|
||||
return bcrypt.hashSync(password, 10);
|
||||
}
|
||||
|
||||
static comparePassword(rawPassword: string, hashedPassword: string) {
|
||||
return bcrypt.compareSync(rawPassword, hashedPassword);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user