[WEB-1319] fix: handled magic sign_in and sign_up error codes in authentication (#4518)
* dev: differentiate error codes for magic code * fix: handled auth error_codes for magic_sign_in and magic_sign_up --------- Co-authored-by: pablohashescobar <nikhilschacko@gmail.com>
This commit is contained in:
parent
603ebeb123
commit
2138257da0
6 changed files with 261 additions and 98 deletions
|
|
@ -25,9 +25,12 @@ AUTHENTICATION_ERROR_CODES = {
|
|||
"INVALID_EMAIL_MAGIC_SIGN_IN": 5080,
|
||||
"MAGIC_SIGN_IN_EMAIL_CODE_REQUIRED": 5085,
|
||||
# Both Sign in and Sign up for magic
|
||||
"INVALID_MAGIC_CODE": 5090,
|
||||
"EXPIRED_MAGIC_CODE": 5095,
|
||||
"EMAIL_CODE_ATTEMPT_EXHAUSTED": 5100,
|
||||
"INVALID_MAGIC_CODE_SIGN_IN": 5090,
|
||||
"INVALID_MAGIC_CODE_SIGN_UP": 5092,
|
||||
"EXPIRED_MAGIC_CODE_SIGN_IN": 5095,
|
||||
"EXPIRED_MAGIC_CODE_SIGN_UP": 5097,
|
||||
"EMAIL_CODE_ATTEMPT_EXHAUSTED_SIGN_IN": 5100,
|
||||
"EMAIL_CODE_ATTEMPT_EXHAUSTED_SIGN_UP": 5102,
|
||||
# Oauth
|
||||
"GOOGLE_NOT_CONFIGURED": 5105,
|
||||
"GITHUB_NOT_CONFIGURED": 5110,
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ from plane.authentication.adapter.error import (
|
|||
AUTHENTICATION_ERROR_CODES,
|
||||
AuthenticationException,
|
||||
)
|
||||
from plane.db.models import User
|
||||
|
||||
|
||||
class MagicCodeProvider(CredentialAdapter):
|
||||
|
|
@ -86,13 +87,23 @@ class MagicCodeProvider(CredentialAdapter):
|
|||
current_attempt = data["current_attempt"] + 1
|
||||
|
||||
if data["current_attempt"] > 2:
|
||||
raise AuthenticationException(
|
||||
error_code=AUTHENTICATION_ERROR_CODES[
|
||||
"EMAIL_CODE_ATTEMPT_EXHAUSTED"
|
||||
],
|
||||
error_message="EMAIL_CODE_ATTEMPT_EXHAUSTED",
|
||||
payload={"email": self.key},
|
||||
)
|
||||
email = str(self.key).replace("magic_", "", 1)
|
||||
if User.objects.exists(email=email):
|
||||
raise AuthenticationException(
|
||||
error_code=AUTHENTICATION_ERROR_CODES[
|
||||
"EMAIL_CODE_ATTEMPT_EXHAUSTED_SIGN_IN"
|
||||
],
|
||||
error_message="EMAIL_CODE_ATTEMPT_EXHAUSTED_SIGN_IN",
|
||||
payload={"email": str(email)},
|
||||
)
|
||||
else:
|
||||
raise AuthenticationException(
|
||||
error_code=AUTHENTICATION_ERROR_CODES[
|
||||
"EMAIL_CODE_ATTEMPT_EXHAUSTED_SIGN_UP"
|
||||
],
|
||||
error_message="EMAIL_CODE_ATTEMPT_EXHAUSTED_SIGN_UP",
|
||||
payload={"email": self.key},
|
||||
)
|
||||
|
||||
value = {
|
||||
"current_attempt": current_attempt,
|
||||
|
|
@ -132,18 +143,38 @@ class MagicCodeProvider(CredentialAdapter):
|
|||
ri.delete(self.key)
|
||||
return
|
||||
else:
|
||||
email = str(self.key).replace("magic_", "", 1)
|
||||
if User.objects.exists(email=email):
|
||||
raise AuthenticationException(
|
||||
error_code=AUTHENTICATION_ERROR_CODES[
|
||||
"INVALID_MAGIC_CODE_SIGN_IN"
|
||||
],
|
||||
error_message="INVALID_MAGIC_CODE_SIGN_IN",
|
||||
payload={"email": str(email)},
|
||||
)
|
||||
else:
|
||||
raise AuthenticationException(
|
||||
error_code=AUTHENTICATION_ERROR_CODES[
|
||||
"INVALID_MAGIC_CODE_SIGN_UP"
|
||||
],
|
||||
error_message="INVALID_MAGIC_CODE_SIGN_UP",
|
||||
payload={"email": str(email)},
|
||||
)
|
||||
else:
|
||||
email = str(self.key).replace("magic_", "", 1)
|
||||
if User.objects.exists(email=email):
|
||||
raise AuthenticationException(
|
||||
error_code=AUTHENTICATION_ERROR_CODES[
|
||||
"INVALID_MAGIC_CODE"
|
||||
"EXPIRED_MAGIC_CODE_SIGN_IN"
|
||||
],
|
||||
error_message="INVALID_MAGIC_CODE",
|
||||
error_message="EXPIRED_MAGIC_CODE_SIGN_IN",
|
||||
payload={"email": str(email)},
|
||||
)
|
||||
else:
|
||||
raise AuthenticationException(
|
||||
error_code=AUTHENTICATION_ERROR_CODES[
|
||||
"EXPIRED_MAGIC_CODE_SIGN_UP"
|
||||
],
|
||||
error_message="EXPIRED_MAGIC_CODE_SIGN_UP",
|
||||
payload={"email": str(email)},
|
||||
)
|
||||
else:
|
||||
magic_key = str(self.key)
|
||||
email = magic_key.replace("magic_", "", 1)
|
||||
raise AuthenticationException(
|
||||
error_code=AUTHENTICATION_ERROR_CODES["EXPIRED_MAGIC_CODE"],
|
||||
error_message="EXPIRED_MAGIC_CODE",
|
||||
payload={"email": str(email)},
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue