Skip to content

Commit

Permalink
update :: 로그인 로직 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
dkflfkd53 committed Aug 18, 2024
1 parent 39d1ed7 commit 8eb9bd0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.example.whopper.domain.auth.domain.type.UserRole;
import com.example.whopper.domain.auth.dto.request.LoginRequest;
import com.example.whopper.domain.auth.dto.response.TokenResponse;
import com.example.whopper.domain.auth.exception.InvalidUserException;
import com.example.whopper.domain.auth.exception.PasswordMismatchException;
import com.example.whopper.domain.document.application.component.CreateDocumentComponent;
import com.example.whopper.domain.file.domain.DefaultProfileImageProperties;
Expand Down Expand Up @@ -51,6 +52,7 @@ private TokenResponse loginExistingStudent(LoginRequest request) {

private TokenResponse registerAndLoginNewStudent(LoginRequest request) {
XquareUserResponse xquareUserResponse = xquareClient.xquareUser(request);
if(!xquareUserResponse.getUser_role().equals("STU")) throw InvalidUserException.EXCEPTION;
StudentEntity newStudent = createAndSaveNewStudent(xquareUserResponse);

createDocumentComponent.create(newStudent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.example.whopper.domain.auth.domain.type.UserRole;
import com.example.whopper.domain.auth.dto.request.LoginRequest;
import com.example.whopper.domain.auth.dto.response.TokenResponse;
import com.example.whopper.domain.auth.exception.InvalidUserException;
import com.example.whopper.domain.auth.exception.PasswordMismatchException;
import com.example.whopper.domain.teacher.dao.TeacherMongoRepository;
import com.example.whopper.domain.teacher.domain.TeacherEntity;
Expand Down Expand Up @@ -43,6 +44,7 @@ private TokenResponse loginExistingTeacher(LoginRequest request) {

private TokenResponse registerAndLoginNewTeacher(LoginRequest request) {
XquareUserResponse xquareUserResponse = xquareClient.xquareUser(request);
if(!xquareUserResponse.getUser_role().equals("SCH")) throw InvalidUserException.EXCEPTION;
TeacherEntity newTeacher = createAndSaveNewTeacher(xquareUserResponse);

return jwtTokenProvider.receiveToken(newTeacher.getId(), UserRole.TEACHER);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.whopper.domain.auth.exception;

import com.example.whopper.global.error.exception.ErrorCode;
import com.example.whopper.global.error.exception.WhopperException;

public class InvalidUserException extends WhopperException {

public static final WhopperException EXCEPTION = new InvalidUserException();

public InvalidUserException() {
super(ErrorCode.INVALID_USER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public enum ErrorCode {

// auth
PASSWORD_MISMATCH(401, "비밀번호가 일치하지 않습니다."),
INVALID_USER(401, "유효하지 않은 사용자입니다."),

// jwt
EXPIRED_TOKEN(401, "만료된 토큰입니다."),
Expand Down

0 comments on commit 8eb9bd0

Please sign in to comment.