-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from whatTeamNaeTeam/develop-0.0.4
Develop 0.0.4 into Main
- Loading branch information
Showing
56 changed files
with
1,064 additions
and
270 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from typing import Optional, Set, TypeVar | ||
|
||
from django.contrib.auth.models import AbstractBaseUser | ||
from rest_framework import HTTP_HEADER_ENCODING | ||
from rest_framework_simplejwt.authentication import JWTAuthentication | ||
from rest_framework_simplejwt.tokens import Token | ||
import core.exception.token as exception | ||
from rest_framework_simplejwt.settings import api_settings | ||
from rest_framework_simplejwt.exceptions import TokenError | ||
from rest_framework_simplejwt.models import TokenUser | ||
|
||
AUTH_HEADER_TYPES = api_settings.AUTH_HEADER_TYPES | ||
|
||
AUTH_HEADER_TYPE_BYTES: Set[bytes] = {h.encode(HTTP_HEADER_ENCODING) for h in AUTH_HEADER_TYPES} | ||
|
||
AuthUser = TypeVar("AuthUser", AbstractBaseUser, TokenUser) | ||
|
||
|
||
class CustomJWTAuthentication(JWTAuthentication): | ||
def get_raw_token(self, header: bytes) -> Optional[bytes]: | ||
parts = header.split() | ||
|
||
if len(parts) == 0: | ||
# Empty AUTHORIZATION header sent | ||
raise exception.NoTokenInAuthorizationHeaderError() | ||
|
||
if parts[0] not in AUTH_HEADER_TYPE_BYTES: | ||
# Assume the header does not contain a JSON web token | ||
raise exception.NoTokenInAuthorizationHeaderError() | ||
|
||
if len(parts) != 2: | ||
raise exception.AuthenticationHeaderSpaceError() | ||
|
||
return parts[1] | ||
|
||
def get_validated_token(self, raw_token: bytes) -> Token: | ||
for AuthToken in api_settings.AUTH_TOKEN_CLASSES: | ||
try: | ||
return AuthToken(raw_token) | ||
except TokenError: | ||
raise exception.AccessTokenExpiredError() | ||
|
||
def get_user(self, validated_token: Token) -> AuthUser: | ||
""" | ||
Attempts to find and return a user using the given validated token. | ||
""" | ||
try: | ||
user_id = validated_token[api_settings.USER_ID_CLAIM] | ||
except KeyError: | ||
raise exception.TokenWithNoUserDataError() | ||
|
||
try: | ||
user = self.user_model.objects.get(**{api_settings.USER_ID_FIELD: user_id}) | ||
except self.user_model.DoesNotExist: | ||
raise exception.UserNotFoundInTokenDataError() | ||
|
||
if not user.is_active: | ||
raise exception.UserInactiveInTokenDataError() | ||
|
||
return user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from rest_framework.exceptions import APIException | ||
|
||
|
||
class ClosedApplyError(APIException): | ||
status_code = 400 | ||
default_detail = {"message": "마감된 지원입니다.", "code": "0500"} | ||
|
||
|
||
class DuplicatedApplyError(APIException): | ||
status_code = 400 | ||
default_detail = {"message": "중복된 지원입니다.", "code": "0501"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from rest_framework.exceptions import APIException | ||
|
||
|
||
class UserNameNotValidError(APIException): | ||
status_code = 400 | ||
default_detail = {"message": "이름에 공백, 특수문자 또는 숫자가 포함되어 있습니다.", "code": "0100"} | ||
|
||
|
||
class UserNameTooLongError(APIException): | ||
status_code = 400 | ||
default_detail = {"message": "이름이 너무 짧거나 깁니다.", "code": "0101"} | ||
|
||
|
||
class StudentNumNotValidError(APIException): | ||
status_code = 400 | ||
default_detail = {"message": "학번에 공백,특수문자 또는 문자가 포함되어 있습니다.", "code": "0110"} | ||
|
||
|
||
class StudentNumTooLongError(APIException): | ||
status_code = 400 | ||
default_detail = {"message": "학번이 너무 짧거나 깁니다.", "code": "0111"} | ||
|
||
|
||
class StudentNumDuplicatedError(APIException): | ||
status_code = 400 | ||
default_detail = {"message": "중복된 학번입니다.", "code": "0112"} | ||
|
||
|
||
class PositionNotValidError(APIException): | ||
status_code = 400 | ||
default_detail = {"message": "포지션 기입이 올바르지 않습니다.", "code": "0120"} | ||
|
||
|
||
class EmailCodeNotMatchError(APIException): | ||
status_code = 400 | ||
default_detail = {"message": "이메일 인증 코드 또는 첨부된 이메일이 일치하지 않습니다.", "code": "0130"} | ||
|
||
|
||
class EmailTimeoutError(APIException): | ||
status_code = 400 | ||
default_detail = {"message": "이메일 인증 시간이 초과되었습니다.", "code": "0131"} | ||
|
||
|
||
class EmailCodeNotMatchAfterAuthError(APIException): | ||
status_code = 400 | ||
default_detail = {"message": "인증 시 사용된 코드(이메일)와 Body의 코드(이메일)가 일치하지 않습니다.", "code": "0132"} | ||
|
||
|
||
class EmailCeleryError(APIException): | ||
status_code = 400 | ||
default_detail = {"message": "이메일 발송 도중 문제가 발생했습니다.", "code": "0133"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from rest_framework.exceptions import APIException | ||
|
||
|
||
class UserNotFoundError(APIException): | ||
status_code = 404 | ||
default_detail = {"message": "해당하는 유저가 존재하지 않습니다.", "code": "0000"} | ||
|
||
|
||
class TeamNotFoundError(APIException): | ||
status_code = 404 | ||
default_detail = {"message": "해당하는 팀이 존재하지 않습니다.", "code": "0001"} | ||
|
||
|
||
class TechNotFoundError(APIException): | ||
status_code = 404 | ||
default_detail = {"message": "해당하는 기술스택이 존재하지 않습니다.", "code": "0002"} | ||
|
||
|
||
class ApplyNotFoundError(APIException): | ||
status_code = 404 | ||
default_detail = {"message": "해당하는 지원이 존재하지 않습니다.", "code": "0003"} | ||
|
||
|
||
class TeamUserNotFoundError(APIException): | ||
status_code = 404 | ||
default_detail = {"message": "해당하는 팀원이 존재하지 않습니다.", "code": "0004"} |
Oops, something went wrong.