Skip to content

Commit

Permalink
feat: SMSState 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
HyungJu committed May 5, 2024
1 parent 1643f48 commit 6fdaa93
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 3 deletions.
22 changes: 22 additions & 0 deletions apps/server/src/codef/strategies/request-reset-password/mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { NipResetPasswordResponse } from '../../../nip/strategies/resetPassword/
import {
CodefResetPasswordRequest,
CodefTwoWaySecureNoInputRequest,
CodefTwoWaySMSInputRequest,
} from '../../types/reset-password/reset-password.request';

export class Mapper {
Expand Down Expand Up @@ -43,6 +44,27 @@ export class Mapper {
is2Way: true,
};

return codefRequest;
} else if (request.type == 'InputSMS') {
const codefRequest: CodefTwoWaySMSInputRequest = {
organization: '0011',
authMethod: '0',
timeout: '170',
userName: request.name,
identity: request.identity.to9DigitRnnString(),
userPassword: request.newPassword,
telecom: request.telecom.getValue().toString(),
phoneNo: request.phoneNumber,
twoWayInfo: {
jobIndex: request.twoWayInfo.jobIndex,
threadIndex: request.twoWayInfo.threadIndex,
jti: request.twoWayInfo.jti,
twoWayTimestamp: request.twoWayInfo.twoWayTimestamp,
},
smsAuthNo: request.smsAuthNo,
is2Way: true,
};

return codefRequest;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ export type CodefTwoWaySecureNoInputRequest = CodefResetPasswordRequest & {
is2Way: true;
};

export type CodefTwoWaySMSInputRequest = CodefResetPasswordRequest & {
twoWayInfo: TwoWayInfo;
smsAuthNo: string;
is2Way: true;
};

export type CodefRequests =
| CodefResetPasswordRequest
| CodefTwoWaySecureNoInputRequest;
8 changes: 7 additions & 1 deletion apps/server/src/nip/strategies/resetPassword/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ export type NipInputSecureNoRequest = {
} & NipResetPasswordBaseRequest<'InputSecureNo'> &
TwoWayRequest;

export type NipInputSMSRequest = {
smsAuthNo: string;
} & NipResetPasswordBaseRequest<'InputSMS'> &
TwoWayRequest;

export type NipResetPasswordRequest =
| NipRequestResetPasswordRequest
| NipInputSecureNoRequest;
| NipInputSecureNoRequest
| NipInputSMSRequest;
5 changes: 4 additions & 1 deletion apps/server/src/password-reset/context.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { RequestPasswordReset } from './states/RequestPasswordReset';
import { States } from './types/state';
import { ContextRepository } from './context.repository';
import { Context } from './types/context';
import { SMSState } from './states/SMSState';

@Injectable()
export class ContextFactory {
Expand All @@ -17,12 +18,14 @@ export class ContextFactory {
private repository: ContextRepository,
private initialState: InitialState,
private requestPasswordReset: RequestPasswordReset,
private secureNoState: SecureNoState
private secureNoState: SecureNoState,
private smsState: SMSState
) {
this.states = {
[StateType.INITIAL]: this.initialState,
[StateType.REQUEST_PASSWORD_RESET]: this.requestPasswordReset,
[StateType.SECURE_NO]: this.secureNoState,
[StateType.SMS]: this.smsState,
};
}

Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/password-reset/password-reset.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { NipModule } from '../nip/nip.module';
import { ContextMapper } from './mapper/mapper';
import { ContextFactory } from './context.factory';
import { RedisContextRepositoryImpl } from './redis-context.repository';
import { SMSState } from './states/SMSState';

@Module({
imports: [NipModule],
Expand All @@ -19,6 +20,7 @@ import { RedisContextRepositoryImpl } from './redis-context.repository';
SecureNoState,
RedisContextRepositoryImpl,
ContextFactory,
SMSState,
{
provide: 'ContextRepository',
useClass: RedisContextRepositoryImpl,
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/password-reset/password-reset.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export enum StateType {
INITIAL = 'initial',
REQUEST_PASSWORD_RESET = 'requestPasswordReset',
SECURE_NO = 'secureNo',
SMS = 'sms',
}

export abstract class PasswordResetState {
Expand Down
36 changes: 36 additions & 0 deletions apps/server/src/password-reset/states/SMSState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { PasswordResetState, StateType } from '../password-reset.state';
import { Injectable } from '@nestjs/common';

import { NipService } from '../../nip/nip.service';
import { ResetPasswordRequest } from '../types/reset-password.request';

@Injectable()
export class SMSState extends PasswordResetState {
constructor(private nipService: NipService) {
super();
}

public async requestPasswordChange(
request: ResetPasswordRequest
): Promise<boolean> {
this.context.changeState(StateType.INITIAL);
return this.context.state.requestPasswordChange(request);
}

public async inputSMSCode(smsCode: string): Promise<boolean> {
const savedRequest = this.context.data.requestInfo;

const response = await this.nipService.requestPasswordReset({
type: 'InputSMS',
smsAuthNo: smsCode,
name: savedRequest.name,
identity: savedRequest.identity,
newPassword: savedRequest.newPassword,
telecom: savedRequest.telecom,
phoneNumber: savedRequest.phoneNumber,
twoWayInfo: this.context.data.twoWayInfo,
});

return true;
}
}
2 changes: 1 addition & 1 deletion apps/server/src/password-reset/states/SecureNoState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class SecureNoState extends PasswordResetState {

throw new DomainException(ErrorCode.SECURE_NO_ERROR_REFRESHED);
} else if (response.type == 'SMS') {
console.log('SMS State로 전환 !!');
this.context.changeState(StateType.SMS);
return true;
}
} catch (e) {
Expand Down

0 comments on commit 6fdaa93

Please sign in to comment.