mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
dev: error codes for authentication
This commit is contained in:
parent
6c09e6dbde
commit
61f47258ee
@ -3,7 +3,6 @@ import os
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
# Django imports
|
# Django imports
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
# Third party imports
|
# Third party imports
|
||||||
@ -16,16 +15,7 @@ from plane.db.models import (
|
|||||||
WorkspaceMemberInvite,
|
WorkspaceMemberInvite,
|
||||||
)
|
)
|
||||||
from plane.license.utils.instance_value import get_configuration_value
|
from plane.license.utils.instance_value import get_configuration_value
|
||||||
|
from .error import AuthenticationException, AUTHENTICATION_ERROR_CODES
|
||||||
|
|
||||||
class AuthenticationException(Exception):
|
|
||||||
|
|
||||||
error_code = None
|
|
||||||
error_message = None
|
|
||||||
|
|
||||||
def __init__(self, error_code, error_message):
|
|
||||||
self.error_code = error_code
|
|
||||||
self.error_message = error_message
|
|
||||||
|
|
||||||
|
|
||||||
class Adapter:
|
class Adapter:
|
||||||
@ -75,8 +65,10 @@ class Adapter:
|
|||||||
email=email,
|
email=email,
|
||||||
).exists()
|
).exists()
|
||||||
):
|
):
|
||||||
raise ImproperlyConfigured(
|
raise AuthenticationException(
|
||||||
"Account creation is disabled for this instance please contact your admin"
|
error_code=AUTHENTICATION_ERROR_CODES["SIGNUP_DISABLED"],
|
||||||
|
error_message="SIGNUP_DISABLED",
|
||||||
|
payload={"email": email},
|
||||||
)
|
)
|
||||||
user = User(email=email, username=uuid.uuid4().hex)
|
user = User(email=email, username=uuid.uuid4().hex)
|
||||||
|
|
||||||
@ -89,8 +81,11 @@ class Adapter:
|
|||||||
results = zxcvbn(self.code)
|
results = zxcvbn(self.code)
|
||||||
if results["score"] < 3:
|
if results["score"] < 3:
|
||||||
raise AuthenticationException(
|
raise AuthenticationException(
|
||||||
error_message="The password is not a valid password",
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
error_code="INVALID_PASSWORD",
|
"INVALID_PASSWORD"
|
||||||
|
],
|
||||||
|
error_message="INVALID_PASSWORD",
|
||||||
|
payload={"email": email},
|
||||||
)
|
)
|
||||||
|
|
||||||
user.set_password(self.code)
|
user.set_password(self.code)
|
||||||
|
58
apiserver/plane/authentication/adapter/error.py
Normal file
58
apiserver/plane/authentication/adapter/error.py
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
AUTHENTICATION_ERROR_CODES = {
|
||||||
|
"INSTANCE_NOT_CONFIGURED": 5000,
|
||||||
|
"SIGNUP_DISABLED": 5001,
|
||||||
|
"INVALID_PASSWORD": 5002,
|
||||||
|
"USER_ALREADY_EXIST": 5003,
|
||||||
|
"USER_DOES_NOT_EXIST": 5004,
|
||||||
|
"AUTHENTICATION_FAILED_SIGN_IN": 5005,
|
||||||
|
"AUTHENTICATION_FAILED_SIGN_UP": 5006,
|
||||||
|
"SMTP_NOT_CONFIGURED": 5007,
|
||||||
|
"INVALID_MAGIC_CODE": 5008,
|
||||||
|
"EXPIRED_MAGIC_CODE": 5009,
|
||||||
|
"GOOGLE_NOT_CONFIGURED": 5010,
|
||||||
|
"GITHUB_NOT_CONFIGURED": 5011,
|
||||||
|
"INVALID_EMAIL": 5012,
|
||||||
|
"EMAIL_REQUIRED": 5013,
|
||||||
|
"REQUIRED_EMAIL_PASSWORD_SIGN_IN": 5014,
|
||||||
|
"INVALID_EMAIL_SIGN_IN": 5015,
|
||||||
|
"INVALID_EMAIL_SIGN_UP": 5016,
|
||||||
|
"INVALID_EMAIL_MAGIC_SIGN_IN": 5017,
|
||||||
|
"INVALID_EMAIL_MAGIC_SIGN_UP": 5018,
|
||||||
|
"GITHUB_OAUTH_PROVIDER_ERROR": 5019,
|
||||||
|
"GOOGLE_OAUTH_PROVIDER_ERROR": 5020,
|
||||||
|
"MAGIC_SIGN_IN_EMAIL_CODE_REQUIRED": 5021,
|
||||||
|
"MAGIC_SIGN_UP_EMAIL_CODE_REQUIRED": 5022,
|
||||||
|
"INVALID_PASSWORD_TOKEN": 5023,
|
||||||
|
"EXPIRED_PASSWORD_TOKEN": 5024,
|
||||||
|
"INCORRECT_OLD_PASSWORD": 5025,
|
||||||
|
"INVALID_NEW_PASSWORD": 5026,
|
||||||
|
"PASSWORD_ALREADY_SET": 5027,
|
||||||
|
"ADMIN_ALREADY_EXIST": 5028,
|
||||||
|
"REQUIRED_ADMIN_EMAIL_PASSWORD_FIRST_NAME": 5029,
|
||||||
|
"INVALID_ADMIN_EMAIL": 5030,
|
||||||
|
"INVALID_ADMIN_PASSWORD": 5031,
|
||||||
|
"REQUIRED_ADMIN_EMAIL_PASSWORD": 5032,
|
||||||
|
"ADMIN_AUTHENTICATION_FAILED": 5034,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class AuthenticationException(Exception):
|
||||||
|
|
||||||
|
error_code = None
|
||||||
|
error_message = None
|
||||||
|
payload = {}
|
||||||
|
|
||||||
|
def __init__(self, error_code, error_message, payload={}):
|
||||||
|
self.error_code = error_code
|
||||||
|
self.error_message = error_message
|
||||||
|
self.payload = payload
|
||||||
|
|
||||||
|
def get_error_dict(self):
|
||||||
|
error = {
|
||||||
|
"error_code": self.error_code,
|
||||||
|
"error_message": self.error_message,
|
||||||
|
}
|
||||||
|
for key in self.payload:
|
||||||
|
error[key] = self.payload[key]
|
||||||
|
|
||||||
|
return error
|
@ -1,7 +1,10 @@
|
|||||||
# Module imports
|
# Module imports
|
||||||
from plane.authentication.adapter.base import AuthenticationException
|
|
||||||
from plane.authentication.adapter.credential import CredentialAdapter
|
from plane.authentication.adapter.credential import CredentialAdapter
|
||||||
from plane.db.models import User
|
from plane.db.models import User
|
||||||
|
from plane.authentication.adapter.error import (
|
||||||
|
AUTHENTICATION_ERROR_CODES,
|
||||||
|
AuthenticationException,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class EmailProvider(CredentialAdapter):
|
class EmailProvider(CredentialAdapter):
|
||||||
@ -25,8 +28,10 @@ class EmailProvider(CredentialAdapter):
|
|||||||
# Check if the user already exists
|
# Check if the user already exists
|
||||||
if User.objects.filter(email=self.key).exists():
|
if User.objects.filter(email=self.key).exists():
|
||||||
raise AuthenticationException(
|
raise AuthenticationException(
|
||||||
error_message="User with this email already exists",
|
error_message="USER_ALREADY_EXIST",
|
||||||
error_code="USER_ALREADY_EXIST",
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
|
"USER_ALREADY_EXIST"
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
super().set_user_data(
|
super().set_user_data(
|
||||||
@ -46,18 +51,35 @@ class EmailProvider(CredentialAdapter):
|
|||||||
user = User.objects.filter(
|
user = User.objects.filter(
|
||||||
email=self.key,
|
email=self.key,
|
||||||
).first()
|
).first()
|
||||||
# Existing user
|
|
||||||
|
# User does not exists
|
||||||
if not user:
|
if not user:
|
||||||
raise AuthenticationException(
|
raise AuthenticationException(
|
||||||
error_message="Sorry, we could not find a user with the provided credentials. Please try again.",
|
error_message="USER_DOES_NOT_EXIST",
|
||||||
error_code="AUTHENTICATION_FAILED",
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
|
"USER_DOES_NOT_EXIST"
|
||||||
|
],
|
||||||
|
payload={
|
||||||
|
"email": self.key,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check user password
|
# Check user password
|
||||||
if not user.check_password(self.code):
|
if not user.check_password(self.code):
|
||||||
raise AuthenticationException(
|
raise AuthenticationException(
|
||||||
error_message="Sorry, we could not find a user with the provided credentials. Please try again.",
|
error_message=(
|
||||||
error_code="AUTHENTICATION_FAILED",
|
"AUTHENTICATION_FAILED_SIGN_UP"
|
||||||
|
if self.is_signup
|
||||||
|
else "AUTHENTICATION_FAILED_SIGN_IN"
|
||||||
|
),
|
||||||
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
|
(
|
||||||
|
"AUTHENTICATION_FAILED_SIGN_UP"
|
||||||
|
if self.is_signup
|
||||||
|
else "AUTHENTICATION_FAILED_SIGN_IN"
|
||||||
|
)
|
||||||
|
],
|
||||||
|
payload={"email": self.key},
|
||||||
)
|
)
|
||||||
|
|
||||||
super().set_user_data(
|
super().set_user_data(
|
||||||
|
@ -4,14 +4,15 @@ import os
|
|||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
|
|
||||||
# Django imports
|
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
|
||||||
|
|
||||||
# Module imports
|
# Module imports
|
||||||
from plane.authentication.adapter.base import AuthenticationException
|
|
||||||
from plane.authentication.adapter.credential import CredentialAdapter
|
from plane.authentication.adapter.credential import CredentialAdapter
|
||||||
from plane.license.utils.instance_value import get_configuration_value
|
from plane.license.utils.instance_value import get_configuration_value
|
||||||
from plane.settings.redis import redis_instance
|
from plane.settings.redis import redis_instance
|
||||||
|
from plane.authentication.adapter.error import (
|
||||||
|
AUTHENTICATION_ERROR_CODES,
|
||||||
|
AuthenticationException,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class MagicCodeProvider(CredentialAdapter):
|
class MagicCodeProvider(CredentialAdapter):
|
||||||
@ -45,8 +46,10 @@ class MagicCodeProvider(CredentialAdapter):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if not (EMAIL_HOST):
|
if not (EMAIL_HOST):
|
||||||
raise ImproperlyConfigured(
|
raise AuthenticationException(
|
||||||
"SMTP is not configured. Please contact the support team."
|
error_code=AUTHENTICATION_ERROR_CODES["SMTP_NOT_CONFIGURED"],
|
||||||
|
error_message="SMTP_NOT_CONFIGURED",
|
||||||
|
payload={"email": str(self.key)},
|
||||||
)
|
)
|
||||||
|
|
||||||
super().__init__(request, self.provider)
|
super().__init__(request, self.provider)
|
||||||
@ -113,11 +116,15 @@ class MagicCodeProvider(CredentialAdapter):
|
|||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
raise AuthenticationException(
|
raise AuthenticationException(
|
||||||
error_message="The token is not valid.",
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
error_code="INVALID_TOKEN",
|
"INVALID_MAGIC_CODE"
|
||||||
|
],
|
||||||
|
error_message="INVALID_MAGIC_CODE",
|
||||||
|
payload={"email": str(self.key)},
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
raise AuthenticationException(
|
raise AuthenticationException(
|
||||||
error_message="The token has expired. Please regenerate the token and try again.",
|
error_code=AUTHENTICATION_ERROR_CODES["EXPIRED_MAGIC_CODE"],
|
||||||
error_code="EXPIRED_TOKEN",
|
error_message="EXPIRED_MAGIC_CODE",
|
||||||
|
payload={"email": str(self.key)},
|
||||||
)
|
)
|
||||||
|
@ -6,12 +6,13 @@ from urllib.parse import urlencode
|
|||||||
import pytz
|
import pytz
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
# Django imports
|
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
|
||||||
|
|
||||||
# Module imports
|
# Module imports
|
||||||
from plane.authentication.adapter.oauth import OauthAdapter
|
from plane.authentication.adapter.oauth import OauthAdapter
|
||||||
from plane.license.utils.instance_value import get_configuration_value
|
from plane.license.utils.instance_value import get_configuration_value
|
||||||
|
from plane.authentication.adapter.error import (
|
||||||
|
AuthenticationException,
|
||||||
|
AUTHENTICATION_ERROR_CODES,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class GitHubOAuthProvider(OauthAdapter):
|
class GitHubOAuthProvider(OauthAdapter):
|
||||||
@ -37,8 +38,9 @@ class GitHubOAuthProvider(OauthAdapter):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if not (GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET):
|
if not (GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET):
|
||||||
raise ImproperlyConfigured(
|
raise AuthenticationException(
|
||||||
"Google is not configured. Please contact the support team."
|
error_code=AUTHENTICATION_ERROR_CODES["GITHUB_NOT_CONFIGURED"],
|
||||||
|
error_message="GITHUB_NOT_CONFIGURED",
|
||||||
)
|
)
|
||||||
|
|
||||||
client_id = GITHUB_CLIENT_ID
|
client_id = GITHUB_CLIENT_ID
|
||||||
|
@ -5,12 +5,13 @@ from urllib.parse import urlencode
|
|||||||
|
|
||||||
import pytz
|
import pytz
|
||||||
|
|
||||||
# Django imports
|
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
|
||||||
|
|
||||||
# Module imports
|
# Module imports
|
||||||
from plane.authentication.adapter.oauth import OauthAdapter
|
from plane.authentication.adapter.oauth import OauthAdapter
|
||||||
from plane.license.utils.instance_value import get_configuration_value
|
from plane.license.utils.instance_value import get_configuration_value
|
||||||
|
from plane.authentication.adapter.error import (
|
||||||
|
AUTHENTICATION_ERROR_CODES,
|
||||||
|
AuthenticationException,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class GoogleOAuthProvider(OauthAdapter):
|
class GoogleOAuthProvider(OauthAdapter):
|
||||||
@ -34,8 +35,9 @@ class GoogleOAuthProvider(OauthAdapter):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if not (GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET):
|
if not (GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET):
|
||||||
raise ImproperlyConfigured(
|
raise AuthenticationException(
|
||||||
"Google is not configured. Please contact the support team."
|
error_code=AUTHENTICATION_ERROR_CODES["GOOGLE_NOT_CONFIGURED"],
|
||||||
|
error_message="GOOGLE_NOT_CONFIGURED",
|
||||||
)
|
)
|
||||||
|
|
||||||
client_id = GOOGLE_CLIENT_ID
|
client_id = GOOGLE_CLIENT_ID
|
||||||
|
@ -11,6 +11,10 @@ from rest_framework.views import APIView
|
|||||||
## Module imports
|
## Module imports
|
||||||
from plane.db.models import User
|
from plane.db.models import User
|
||||||
from plane.license.models import Instance
|
from plane.license.models import Instance
|
||||||
|
from plane.authentication.adapter.error import (
|
||||||
|
AuthenticationException,
|
||||||
|
AUTHENTICATION_ERROR_CODES,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class EmailCheckSignUpEndpoint(APIView):
|
class EmailCheckSignUpEndpoint(APIView):
|
||||||
@ -23,11 +27,14 @@ class EmailCheckSignUpEndpoint(APIView):
|
|||||||
# Check instance configuration
|
# Check instance configuration
|
||||||
instance = Instance.objects.first()
|
instance = Instance.objects.first()
|
||||||
if instance is None or not instance.is_setup_done:
|
if instance is None or not instance.is_setup_done:
|
||||||
|
exc = AuthenticationException(
|
||||||
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
|
"INSTANCE_NOT_CONFIGURED"
|
||||||
|
],
|
||||||
|
error_message="INSTANCE_NOT_CONFIGURED",
|
||||||
|
)
|
||||||
return Response(
|
return Response(
|
||||||
{
|
exc.get_error_dict(),
|
||||||
"error_code": "INSTANCE_NOT_CONFIGURED",
|
|
||||||
"error_message": "Instance is not configured",
|
|
||||||
},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -35,8 +42,12 @@ class EmailCheckSignUpEndpoint(APIView):
|
|||||||
|
|
||||||
# Return error if email is not present
|
# Return error if email is not present
|
||||||
if not email:
|
if not email:
|
||||||
|
exc = AuthenticationException(
|
||||||
|
error_code=AUTHENTICATION_ERROR_CODES["EMAIL_REQUIRED"],
|
||||||
|
error_message="EMAIL_REQUIRED",
|
||||||
|
)
|
||||||
return Response(
|
return Response(
|
||||||
{"error": "Email is required"},
|
exc.get_error_dict(),
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -44,21 +55,24 @@ class EmailCheckSignUpEndpoint(APIView):
|
|||||||
try:
|
try:
|
||||||
validate_email(email)
|
validate_email(email)
|
||||||
except ValidationError:
|
except ValidationError:
|
||||||
|
exc = AuthenticationException(
|
||||||
|
error_code=AUTHENTICATION_ERROR_CODES["INVALID_EMAIL"],
|
||||||
|
error_message="INVALID_EMAIL",
|
||||||
|
)
|
||||||
return Response(
|
return Response(
|
||||||
{
|
exc.get_error_dict(),
|
||||||
"error": "Email is invalid please provide a valid email address"
|
|
||||||
},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
)
|
)
|
||||||
|
|
||||||
existing_user = User.objects.filter(email=email).first()
|
existing_user = User.objects.filter(email=email).first()
|
||||||
|
|
||||||
if existing_user:
|
if existing_user:
|
||||||
|
exc = AuthenticationException(
|
||||||
|
error_code=AUTHENTICATION_ERROR_CODES["USER_ALREADY_EXIST"],
|
||||||
|
error_message="USER_ALREADY_EXIST",
|
||||||
|
)
|
||||||
return Response(
|
return Response(
|
||||||
{
|
exc.get_error_dict(),
|
||||||
"error_code": "USER_ALREADY_EXIST",
|
|
||||||
"error_message": "User already exists with the email.",
|
|
||||||
},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
)
|
)
|
||||||
return Response(
|
return Response(
|
||||||
@ -77,11 +91,14 @@ class EmailCheckSignInEndpoint(APIView):
|
|||||||
# Check instance configuration
|
# Check instance configuration
|
||||||
instance = Instance.objects.first()
|
instance = Instance.objects.first()
|
||||||
if instance is None or not instance.is_setup_done:
|
if instance is None or not instance.is_setup_done:
|
||||||
|
exc = AuthenticationException(
|
||||||
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
|
"INSTANCE_NOT_CONFIGURED"
|
||||||
|
],
|
||||||
|
error_message="INSTANCE_NOT_CONFIGURED",
|
||||||
|
)
|
||||||
return Response(
|
return Response(
|
||||||
{
|
exc.get_error_dict(),
|
||||||
"error_code": "INSTANCE_NOT_CONFIGURED",
|
|
||||||
"error_message": "Instance is not configured",
|
|
||||||
},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -89,8 +106,12 @@ class EmailCheckSignInEndpoint(APIView):
|
|||||||
|
|
||||||
# Return error if email is not present
|
# Return error if email is not present
|
||||||
if not email:
|
if not email:
|
||||||
|
exc = AuthenticationException(
|
||||||
|
error_code=AUTHENTICATION_ERROR_CODES["EMAIL_REQUIRED"],
|
||||||
|
error_message="EMAIL_REQUIRED",
|
||||||
|
)
|
||||||
return Response(
|
return Response(
|
||||||
{"error": "Email is required"},
|
exc.get_error_dict(),
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -98,10 +119,12 @@ class EmailCheckSignInEndpoint(APIView):
|
|||||||
try:
|
try:
|
||||||
validate_email(email)
|
validate_email(email)
|
||||||
except ValidationError:
|
except ValidationError:
|
||||||
|
exc = AuthenticationException(
|
||||||
|
error_code=AUTHENTICATION_ERROR_CODES["INVALID_EMAIL"],
|
||||||
|
error_message="INVALID_EMAIL",
|
||||||
|
)
|
||||||
return Response(
|
return Response(
|
||||||
{
|
exc.get_error_dict(),
|
||||||
"error": "Email is invalid please provide a valid email address"
|
|
||||||
},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -115,10 +138,11 @@ class EmailCheckSignInEndpoint(APIView):
|
|||||||
},
|
},
|
||||||
status=status.HTTP_200_OK,
|
status=status.HTTP_200_OK,
|
||||||
)
|
)
|
||||||
|
exc = AuthenticationException(
|
||||||
|
error_code=AUTHENTICATION_ERROR_CODES["USER_DOES_NOT_EXIST"],
|
||||||
|
error_message="USER_DOES_NOT_EXIST",
|
||||||
|
)
|
||||||
return Response(
|
return Response(
|
||||||
{
|
exc.get_error_dict(),
|
||||||
"error_code": "USER_DOES_NOT_EXIST",
|
|
||||||
"error_message": "User could not be found with the given email.",
|
|
||||||
},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
)
|
)
|
||||||
|
@ -8,7 +8,6 @@ from django.http import HttpResponseRedirect
|
|||||||
from django.views import View
|
from django.views import View
|
||||||
|
|
||||||
# Module imports
|
# Module imports
|
||||||
from plane.authentication.adapter.base import AuthenticationException
|
|
||||||
from plane.authentication.provider.credentials.email import EmailProvider
|
from plane.authentication.provider.credentials.email import EmailProvider
|
||||||
from plane.authentication.utils.login import user_login
|
from plane.authentication.utils.login import user_login
|
||||||
from plane.license.models import Instance
|
from plane.license.models import Instance
|
||||||
@ -18,6 +17,10 @@ from plane.authentication.utils.workspace_project_join import (
|
|||||||
process_workspace_project_invitations,
|
process_workspace_project_invitations,
|
||||||
)
|
)
|
||||||
from plane.db.models import User
|
from plane.db.models import User
|
||||||
|
from plane.authentication.adapter.error import (
|
||||||
|
AuthenticationException,
|
||||||
|
AUTHENTICATION_ERROR_CODES,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class SignInAuthEndpoint(View):
|
class SignInAuthEndpoint(View):
|
||||||
@ -28,10 +31,13 @@ class SignInAuthEndpoint(View):
|
|||||||
instance = Instance.objects.first()
|
instance = Instance.objects.first()
|
||||||
if instance is None or not instance.is_setup_done:
|
if instance is None or not instance.is_setup_done:
|
||||||
# Redirection params
|
# Redirection params
|
||||||
params = {
|
exc = AuthenticationException(
|
||||||
"error_code": "INSTANCE_NOT_CONFIGURED",
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
"error_message": "Instance is not configured",
|
"INSTANCE_NOT_CONFIGURED"
|
||||||
}
|
],
|
||||||
|
error_message="INSTANCE_NOT_CONFIGURED",
|
||||||
|
)
|
||||||
|
params = exc.get_error_dict()
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
# Base URL join
|
# Base URL join
|
||||||
@ -48,10 +54,14 @@ class SignInAuthEndpoint(View):
|
|||||||
## Raise exception if any of the above are missing
|
## Raise exception if any of the above are missing
|
||||||
if not email or not password:
|
if not email or not password:
|
||||||
# Redirection params
|
# Redirection params
|
||||||
params = {
|
exc = AuthenticationException(
|
||||||
"error_code": "REQUIRED_EMAIL_PASSWORD",
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
"error_message": "Both email and password are required",
|
"REQUIRED_EMAIL_PASSWORD_SIGN_IN"
|
||||||
}
|
],
|
||||||
|
error_message="REQUIRED_EMAIL_PASSWORD_SIGN_IN",
|
||||||
|
payload={"email": str(email)},
|
||||||
|
)
|
||||||
|
params = exc.get_error_dict()
|
||||||
# Next path
|
# Next path
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
@ -66,10 +76,12 @@ class SignInAuthEndpoint(View):
|
|||||||
try:
|
try:
|
||||||
validate_email(email)
|
validate_email(email)
|
||||||
except ValidationError:
|
except ValidationError:
|
||||||
params = {
|
exc = AuthenticationException(
|
||||||
"error_code": "INVALID_EMAIL",
|
error_code=AUTHENTICATION_ERROR_CODES["INVALID_EMAIL_SIGN_IN"],
|
||||||
"error_message": "Please provide a valid email address.",
|
error_message="INVALID_EMAIL_SIGN_IN",
|
||||||
}
|
payload={"email": str(email)},
|
||||||
|
)
|
||||||
|
params = exc.get_error_dict()
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -79,10 +91,12 @@ class SignInAuthEndpoint(View):
|
|||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
if not User.objects.filter(email=email).exists():
|
if not User.objects.filter(email=email).exists():
|
||||||
params = {
|
exc = AuthenticationException(
|
||||||
"error_code": "USER_DOES_NOT_EXIST",
|
error_code=AUTHENTICATION_ERROR_CODES["USER_DOES_NOT_EXIST"],
|
||||||
"error_message": "User could not be found with the given email.",
|
error_message="USER_DOES_NOT_EXIST",
|
||||||
}
|
payload={"email": str(email)},
|
||||||
|
)
|
||||||
|
params = exc.get_error_dict()
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -110,11 +124,7 @@ class SignInAuthEndpoint(View):
|
|||||||
url = urljoin(base_host(request=request), path)
|
url = urljoin(base_host(request=request), path)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
except AuthenticationException as e:
|
except AuthenticationException as e:
|
||||||
params = {
|
params = e.get_error_dict()
|
||||||
"email": email,
|
|
||||||
"error_code": str(e.error_code),
|
|
||||||
"error_message": str(e.error_message),
|
|
||||||
}
|
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -131,10 +141,14 @@ class SignUpAuthEndpoint(View):
|
|||||||
# Check instance configuration
|
# Check instance configuration
|
||||||
instance = Instance.objects.first()
|
instance = Instance.objects.first()
|
||||||
if instance is None or not instance.is_setup_done:
|
if instance is None or not instance.is_setup_done:
|
||||||
params = {
|
# Redirection params
|
||||||
"error_code": "INSTANCE_NOT_CONFIGURED",
|
exc = AuthenticationException(
|
||||||
"error_message": "Instance is not configured",
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
}
|
"INSTANCE_NOT_CONFIGURED"
|
||||||
|
],
|
||||||
|
error_message="INSTANCE_NOT_CONFIGURED",
|
||||||
|
)
|
||||||
|
params = exc.get_error_dict()
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -147,10 +161,15 @@ class SignUpAuthEndpoint(View):
|
|||||||
password = request.POST.get("password", False)
|
password = request.POST.get("password", False)
|
||||||
## Raise exception if any of the above are missing
|
## Raise exception if any of the above are missing
|
||||||
if not email or not password:
|
if not email or not password:
|
||||||
params = {
|
# Redirection params
|
||||||
"error_code": "REQUIRED_EMAIL_PASSWORD",
|
exc = AuthenticationException(
|
||||||
"error_message": "Both email and password are required",
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
}
|
"REQUIRED_EMAIL_PASSWORD_SIGN_UP"
|
||||||
|
],
|
||||||
|
error_message="REQUIRED_EMAIL_PASSWORD_SIGN_UP",
|
||||||
|
payload={"email": str(email)},
|
||||||
|
)
|
||||||
|
params = exc.get_error_dict()
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -163,10 +182,13 @@ class SignUpAuthEndpoint(View):
|
|||||||
try:
|
try:
|
||||||
validate_email(email)
|
validate_email(email)
|
||||||
except ValidationError:
|
except ValidationError:
|
||||||
params = {
|
# Redirection params
|
||||||
"error_code": "INVALID_EMAIL",
|
exc = AuthenticationException(
|
||||||
"error_message": "Please provide a valid email address.",
|
error_code=AUTHENTICATION_ERROR_CODES["INVALID_EMAIL_SIGN_UP"],
|
||||||
}
|
error_message="INVALID_EMAIL_SIGN_UP",
|
||||||
|
payload={"email": str(email)},
|
||||||
|
)
|
||||||
|
params = exc.get_error_dict()
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -176,10 +198,12 @@ class SignUpAuthEndpoint(View):
|
|||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
if User.objects.filter(email=email).exists():
|
if User.objects.filter(email=email).exists():
|
||||||
params = {
|
exc = AuthenticationException(
|
||||||
"error_code": "USER_ALREADY_EXIST",
|
error_code=AUTHENTICATION_ERROR_CODES["USER_ALREADY_EXIST"],
|
||||||
"error_message": "User already exists with the email.",
|
error_message="USER_ALREADY_EXIST",
|
||||||
}
|
payload={"email": str(email)},
|
||||||
|
)
|
||||||
|
params = exc.get_error_dict()
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -206,10 +230,7 @@ class SignUpAuthEndpoint(View):
|
|||||||
url = urljoin(base_host(request=request), path)
|
url = urljoin(base_host(request=request), path)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
except AuthenticationException as e:
|
except AuthenticationException as e:
|
||||||
params = {
|
params = e.get_error_dict()
|
||||||
"error_code": str(e.error_code),
|
|
||||||
"error_message": str(e.error_message),
|
|
||||||
}
|
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
|
@ -15,6 +15,10 @@ from plane.authentication.utils.workspace_project_join import (
|
|||||||
)
|
)
|
||||||
from plane.license.models import Instance
|
from plane.license.models import Instance
|
||||||
from plane.authentication.utils.host import base_host
|
from plane.authentication.utils.host import base_host
|
||||||
|
from plane.authentication.adapter.error import (
|
||||||
|
AuthenticationException,
|
||||||
|
AUTHENTICATION_ERROR_CODES,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class GitHubOauthInitiateEndpoint(View):
|
class GitHubOauthInitiateEndpoint(View):
|
||||||
@ -29,10 +33,15 @@ class GitHubOauthInitiateEndpoint(View):
|
|||||||
# Check instance configuration
|
# Check instance configuration
|
||||||
instance = Instance.objects.first()
|
instance = Instance.objects.first()
|
||||||
if instance is None or not instance.is_setup_done:
|
if instance is None or not instance.is_setup_done:
|
||||||
params = {
|
exc = AuthenticationException(
|
||||||
"error_code": "INSTANCE_NOT_CONFIGURED",
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
"error_message": "Instance is not configured",
|
"INSTANCE_NOT_CONFIGURED"
|
||||||
}
|
],
|
||||||
|
error_message="INSTANCE_NOT_CONFIGURED",
|
||||||
|
)
|
||||||
|
params = exc.get_error_dict()
|
||||||
|
if next_path:
|
||||||
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
base_host(request=request),
|
base_host(request=request),
|
||||||
"?" + urlencode(params),
|
"?" + urlencode(params),
|
||||||
@ -44,11 +53,8 @@ class GitHubOauthInitiateEndpoint(View):
|
|||||||
request.session["state"] = state
|
request.session["state"] = state
|
||||||
auth_url = provider.get_auth_url()
|
auth_url = provider.get_auth_url()
|
||||||
return HttpResponseRedirect(auth_url)
|
return HttpResponseRedirect(auth_url)
|
||||||
except ImproperlyConfigured as e:
|
except AuthenticationException as e:
|
||||||
params = {
|
params = e.get_error_dict()
|
||||||
"error_code": "IMPROPERLY_CONFIGURED",
|
|
||||||
"error_message": str(e),
|
|
||||||
}
|
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -67,10 +73,13 @@ class GitHubCallbackEndpoint(View):
|
|||||||
next_path = request.session.get("next_path")
|
next_path = request.session.get("next_path")
|
||||||
|
|
||||||
if state != request.session.get("state", ""):
|
if state != request.session.get("state", ""):
|
||||||
params = {
|
exc = AuthenticationException(
|
||||||
"error_code": "OAUTH_PROVIDER_ERROR",
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
"error_message": "State does not match",
|
"GITHUB_OAUTH_PROVIDER_ERROR"
|
||||||
}
|
],
|
||||||
|
error_message="GITHUB_OAUTH_PROVIDER_ERROR",
|
||||||
|
)
|
||||||
|
params = exc.get_error_dict()
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -80,10 +89,13 @@ class GitHubCallbackEndpoint(View):
|
|||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
if not code:
|
if not code:
|
||||||
params = {
|
exc = AuthenticationException(
|
||||||
"error_code": "OAUTH_PROVIDER_ERROR",
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
"error_message": "Something went wrong while fetching data from OAuth provider. Please try again after sometime.",
|
"GITHUB_OAUTH_PROVIDER_ERROR"
|
||||||
}
|
],
|
||||||
|
error_message="GITHUB_OAUTH_PROVIDER_ERROR",
|
||||||
|
)
|
||||||
|
params = exc.get_error_dict()
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -110,11 +122,8 @@ class GitHubCallbackEndpoint(View):
|
|||||||
# redirect to referer path
|
# redirect to referer path
|
||||||
url = urljoin(base_host, path)
|
url = urljoin(base_host, path)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
except ImproperlyConfigured as e:
|
except AuthenticationException as e:
|
||||||
params = {
|
params = e.get_error_dict()
|
||||||
"error_code": "IMPROPERLY_CONFIGURED",
|
|
||||||
"error_message": str(e),
|
|
||||||
}
|
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
|
@ -17,6 +17,10 @@ from plane.authentication.utils.workspace_project_join import (
|
|||||||
# Module imports
|
# Module imports
|
||||||
from plane.license.models import Instance
|
from plane.license.models import Instance
|
||||||
from plane.authentication.utils.host import base_host
|
from plane.authentication.utils.host import base_host
|
||||||
|
from plane.authentication.adapter.error import (
|
||||||
|
AuthenticationException,
|
||||||
|
AUTHENTICATION_ERROR_CODES,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class GoogleOauthInitiateEndpoint(View):
|
class GoogleOauthInitiateEndpoint(View):
|
||||||
@ -29,10 +33,13 @@ class GoogleOauthInitiateEndpoint(View):
|
|||||||
# Check instance configuration
|
# Check instance configuration
|
||||||
instance = Instance.objects.first()
|
instance = Instance.objects.first()
|
||||||
if instance is None or not instance.is_setup_done:
|
if instance is None or not instance.is_setup_done:
|
||||||
params = {
|
exc = AuthenticationException(
|
||||||
"error_code": "INSTANCE_NOT_CONFIGURED",
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
"error_message": "Instance is not configured",
|
"INSTANCE_NOT_CONFIGURED"
|
||||||
}
|
],
|
||||||
|
error_message="INSTANCE_NOT_CONFIGURED",
|
||||||
|
)
|
||||||
|
params = exc.get_error_dict()
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -47,11 +54,8 @@ class GoogleOauthInitiateEndpoint(View):
|
|||||||
request.session["state"] = state
|
request.session["state"] = state
|
||||||
auth_url = provider.get_auth_url()
|
auth_url = provider.get_auth_url()
|
||||||
return HttpResponseRedirect(auth_url)
|
return HttpResponseRedirect(auth_url)
|
||||||
except ImproperlyConfigured as e:
|
except AuthenticationException as e:
|
||||||
params = {
|
params = e.get_error_dict()
|
||||||
"error_code": "IMPROPERLY_CONFIGURED",
|
|
||||||
"error_message": str(e),
|
|
||||||
}
|
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -69,10 +73,13 @@ class GoogleCallbackEndpoint(View):
|
|||||||
next_path = request.session.get("next_path")
|
next_path = request.session.get("next_path")
|
||||||
|
|
||||||
if state != request.session.get("state", ""):
|
if state != request.session.get("state", ""):
|
||||||
params = {
|
exc = AuthenticationException(
|
||||||
"error_code": "OAUTH_PROVIDER_ERROR",
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
"error_message": "State does not match",
|
"GOOGLE_OAUTH_PROVIDER_ERROR"
|
||||||
}
|
],
|
||||||
|
error_message="GOOGLE_OAUTH_PROVIDER_ERROR",
|
||||||
|
)
|
||||||
|
params = exc.get_error_dict()
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -81,10 +88,13 @@ class GoogleCallbackEndpoint(View):
|
|||||||
)
|
)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
if not code:
|
if not code:
|
||||||
params = {
|
exc = AuthenticationException(
|
||||||
"error_code": "OAUTH_PROVIDER_ERROR",
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
"error_message": "Something went wrong while fetching data from OAuth provider. Please try again after sometime.",
|
"GOOGLE_OAUTH_PROVIDER_ERROR"
|
||||||
}
|
],
|
||||||
|
error_message="GOOGLE_OAUTH_PROVIDER_ERROR",
|
||||||
|
)
|
||||||
|
params = exc.get_error_dict()
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = next_path
|
params["next_path"] = next_path
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -107,11 +117,8 @@ class GoogleCallbackEndpoint(View):
|
|||||||
# redirect to referer path
|
# redirect to referer path
|
||||||
url = urljoin(base_host, str(next_path) if next_path else path)
|
url = urljoin(base_host, str(next_path) if next_path else path)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
except ImproperlyConfigured as e:
|
except AuthenticationException as e:
|
||||||
params = {
|
params = e.get_error_dict()
|
||||||
"error_code": "IMPROPERLY_CONFIGURED",
|
|
||||||
"error_message": str(e),
|
|
||||||
}
|
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
from urllib.parse import urlencode, urljoin
|
from urllib.parse import urlencode, urljoin
|
||||||
|
|
||||||
# Django imports
|
# Django imports
|
||||||
from django.core.exceptions import ImproperlyConfigured, ValidationError
|
|
||||||
from django.core.validators import validate_email
|
from django.core.validators import validate_email
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
from django.views import View
|
from django.views import View
|
||||||
@ -14,7 +13,6 @@ from rest_framework.response import Response
|
|||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
|
|
||||||
# Module imports
|
# Module imports
|
||||||
from plane.authentication.adapter.base import AuthenticationException
|
|
||||||
from plane.authentication.provider.credentials.magic_code import (
|
from plane.authentication.provider.credentials.magic_code import (
|
||||||
MagicCodeProvider,
|
MagicCodeProvider,
|
||||||
)
|
)
|
||||||
@ -27,6 +25,10 @@ from plane.bgtasks.magic_link_code_task import magic_link
|
|||||||
from plane.license.models import Instance
|
from plane.license.models import Instance
|
||||||
from plane.authentication.utils.host import base_host
|
from plane.authentication.utils.host import base_host
|
||||||
from plane.db.models import User, Profile
|
from plane.db.models import User, Profile
|
||||||
|
from plane.authentication.adapter.error import (
|
||||||
|
AuthenticationException,
|
||||||
|
AUTHENTICATION_ERROR_CODES,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class MagicGenerateEndpoint(APIView):
|
class MagicGenerateEndpoint(APIView):
|
||||||
@ -39,11 +41,14 @@ class MagicGenerateEndpoint(APIView):
|
|||||||
# Check if instance is configured
|
# Check if instance is configured
|
||||||
instance = Instance.objects.first()
|
instance = Instance.objects.first()
|
||||||
if instance is None or not instance.is_setup_done:
|
if instance is None or not instance.is_setup_done:
|
||||||
|
exc = AuthenticationException(
|
||||||
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
|
"INSTANCE_NOT_CONFIGURED"
|
||||||
|
],
|
||||||
|
error_message="INSTANCE_NOT_CONFIGURED",
|
||||||
|
)
|
||||||
return Response(
|
return Response(
|
||||||
{
|
exc.get_error_dict(), status=status.HTTP_400_BAD_REQUEST
|
||||||
"error_code": "INSTANCE_NOT_CONFIGURED",
|
|
||||||
"error_message": "Instance is not configured",
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
origin = request.META.get("HTTP_ORIGIN", "/")
|
origin = request.META.get("HTTP_ORIGIN", "/")
|
||||||
@ -57,28 +62,10 @@ class MagicGenerateEndpoint(APIView):
|
|||||||
# If the smtp is configured send through here
|
# If the smtp is configured send through here
|
||||||
magic_link.delay(email, key, token, origin)
|
magic_link.delay(email, key, token, origin)
|
||||||
return Response({"key": str(key)}, status=status.HTTP_200_OK)
|
return Response({"key": str(key)}, status=status.HTTP_200_OK)
|
||||||
except ImproperlyConfigured as e:
|
|
||||||
return Response(
|
|
||||||
{
|
|
||||||
"error_code": "IMPROPERLY_CONFIGURED",
|
|
||||||
"error_message": str(e),
|
|
||||||
},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
|
||||||
)
|
|
||||||
except AuthenticationException as e:
|
except AuthenticationException as e:
|
||||||
|
params = e.get_error_dict()
|
||||||
return Response(
|
return Response(
|
||||||
{
|
params,
|
||||||
"error_code": str(e.error_code),
|
|
||||||
"error_message": str(e.error_message),
|
|
||||||
},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
|
||||||
)
|
|
||||||
except ValidationError:
|
|
||||||
return Response(
|
|
||||||
{
|
|
||||||
"error_code": "INVALID_EMAIL",
|
|
||||||
"error_message": "Valid email is required for generating a magic code",
|
|
||||||
},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -93,10 +80,13 @@ class MagicSignInEndpoint(View):
|
|||||||
next_path = request.POST.get("next_path")
|
next_path = request.POST.get("next_path")
|
||||||
|
|
||||||
if code == "" or email == "":
|
if code == "" or email == "":
|
||||||
params = {
|
exc = AuthenticationException(
|
||||||
"error_code": "EMAIL_CODE_REQUIRED",
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
"error_message": "Email and code are required",
|
"MAGIC_SIGN_IN_EMAIL_CODE_REQUIRED"
|
||||||
}
|
],
|
||||||
|
error_message="MAGIC_SIGN_IN_EMAIL_CODE_REQUIRED",
|
||||||
|
)
|
||||||
|
params = exc.get_error_dict()
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -106,10 +96,11 @@ class MagicSignInEndpoint(View):
|
|||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
if not User.objects.filter(email=email).exists():
|
if not User.objects.filter(email=email).exists():
|
||||||
params = {
|
exc = AuthenticationException(
|
||||||
"error_code": "USER_DOES_NOT_EXIST",
|
error_code=AUTHENTICATION_ERROR_CODES["USER_DOES_NOT_EXIST"],
|
||||||
"error_message": "User could not be found with the given email.",
|
error_message="USER_DOES_NOT_EXIST",
|
||||||
}
|
)
|
||||||
|
params = exc.get_error_dict()
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -142,10 +133,7 @@ class MagicSignInEndpoint(View):
|
|||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
except AuthenticationException as e:
|
except AuthenticationException as e:
|
||||||
params = {
|
params = e.get_error_dict()
|
||||||
"error_code": str(e.error_code),
|
|
||||||
"error_message": str(e.error_message),
|
|
||||||
}
|
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -165,10 +153,13 @@ class MagicSignUpEndpoint(View):
|
|||||||
next_path = request.POST.get("next_path")
|
next_path = request.POST.get("next_path")
|
||||||
|
|
||||||
if code == "" or email == "":
|
if code == "" or email == "":
|
||||||
params = {
|
exc = AuthenticationException(
|
||||||
"error_code": "EMAIL_CODE_REQUIRED",
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
"error_message": "Email and code are required",
|
"MAGIC_SIGN_UP_EMAIL_CODE_REQUIRED"
|
||||||
}
|
],
|
||||||
|
error_message="MAGIC_SIGN_UP_EMAIL_CODE_REQUIRED",
|
||||||
|
)
|
||||||
|
params = exc.get_error_dict()
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -178,10 +169,11 @@ class MagicSignUpEndpoint(View):
|
|||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
if User.objects.filter(email=email).exists():
|
if User.objects.filter(email=email).exists():
|
||||||
params = {
|
exc = AuthenticationException(
|
||||||
"error_code": "USER_ALREADY_EXIST",
|
error_code=AUTHENTICATION_ERROR_CODES["USER_ALREADY_EXIST"],
|
||||||
"error_message": "User already exists with the email.",
|
error_message="USER_ALREADY_EXIST",
|
||||||
}
|
)
|
||||||
|
params = exc.get_error_dict()
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -209,10 +201,7 @@ class MagicSignUpEndpoint(View):
|
|||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
except AuthenticationException as e:
|
except AuthenticationException as e:
|
||||||
params = {
|
params = e.get_error_dict()
|
||||||
"error_code": str(e.error_code),
|
|
||||||
"error_message": str(e.error_message),
|
|
||||||
}
|
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
|
@ -34,6 +34,10 @@ from plane.db.models import User
|
|||||||
from plane.license.models import Instance
|
from plane.license.models import Instance
|
||||||
from plane.license.utils.instance_value import get_configuration_value
|
from plane.license.utils.instance_value import get_configuration_value
|
||||||
from plane.authentication.utils.host import base_host
|
from plane.authentication.utils.host import base_host
|
||||||
|
from plane.authentication.adapter.error import (
|
||||||
|
AuthenticationException,
|
||||||
|
AUTHENTICATION_ERROR_CODES,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class CSRFTokenEndpoint(APIView):
|
class CSRFTokenEndpoint(APIView):
|
||||||
@ -69,11 +73,14 @@ class ForgotPasswordEndpoint(APIView):
|
|||||||
# Check instance configuration
|
# Check instance configuration
|
||||||
instance = Instance.objects.first()
|
instance = Instance.objects.first()
|
||||||
if instance is None or not instance.is_setup_done:
|
if instance is None or not instance.is_setup_done:
|
||||||
|
exc = AuthenticationException(
|
||||||
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
|
"INSTANCE_NOT_CONFIGURED"
|
||||||
|
],
|
||||||
|
error_message="INSTANCE_NOT_CONFIGURED",
|
||||||
|
)
|
||||||
return Response(
|
return Response(
|
||||||
{
|
exc.get_error_dict(),
|
||||||
"error_code": "INSTANCE_NOT_CONFIGURED",
|
|
||||||
"error_message": "Instance is not configured",
|
|
||||||
},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -97,22 +104,24 @@ class ForgotPasswordEndpoint(APIView):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if not (EMAIL_HOST):
|
if not (EMAIL_HOST):
|
||||||
|
exc = AuthenticationException(
|
||||||
|
error_message="SMTP_NOT_CONFIGURED",
|
||||||
|
error_code=AUTHENTICATION_ERROR_CODES["SMTP_NOT_CONFIGURED"],
|
||||||
|
)
|
||||||
return Response(
|
return Response(
|
||||||
{
|
exc.get_error_dict(),
|
||||||
"error_code": "SMTP_NOT_CONFIGURED",
|
|
||||||
"error_message": "SMTP is not configured. Please contact your admin",
|
|
||||||
},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
validate_email(email)
|
validate_email(email)
|
||||||
except ValidationError:
|
except ValidationError:
|
||||||
|
exc = AuthenticationException(
|
||||||
|
error_code=AUTHENTICATION_ERROR_CODES["INVALID_EMAIL"],
|
||||||
|
error_message="INVALID_EMAIL",
|
||||||
|
)
|
||||||
return Response(
|
return Response(
|
||||||
{
|
exc.get_error_dict(),
|
||||||
"error_code": "INVALID_EMAIL",
|
|
||||||
"error_message": "Please enter a valid email",
|
|
||||||
},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -130,11 +139,12 @@ class ForgotPasswordEndpoint(APIView):
|
|||||||
{"message": "Check your email to reset your password"},
|
{"message": "Check your email to reset your password"},
|
||||||
status=status.HTTP_200_OK,
|
status=status.HTTP_200_OK,
|
||||||
)
|
)
|
||||||
|
exc = AuthenticationException(
|
||||||
|
error_code=AUTHENTICATION_ERROR_CODES["USER_DOES_NOT_EXIST"],
|
||||||
|
error_message="USER_DOES_NOT_EXIST",
|
||||||
|
)
|
||||||
return Response(
|
return Response(
|
||||||
{
|
exc.get_error_dict(),
|
||||||
"error_code": "INVALID_EMAIL",
|
|
||||||
"error_message": "Please check the email",
|
|
||||||
},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -149,39 +159,43 @@ class ResetPasswordEndpoint(View):
|
|||||||
|
|
||||||
# check if the token is valid for the user
|
# check if the token is valid for the user
|
||||||
if not PasswordResetTokenGenerator().check_token(user, token):
|
if not PasswordResetTokenGenerator().check_token(user, token):
|
||||||
|
exc = AuthenticationException(
|
||||||
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
|
"INVALID_PASSWORD_TOKEN"
|
||||||
|
],
|
||||||
|
error_message="INVALID_PASSWORD_TOKEN",
|
||||||
|
)
|
||||||
|
params = exc.get_error_dict()
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
base_host(request=request),
|
base_host(request=request),
|
||||||
"accounts/reset-password?"
|
"accounts/reset-password?" + urlencode(params),
|
||||||
+ urlencode(
|
|
||||||
{
|
|
||||||
"error_code": "INVALID_TOKEN",
|
|
||||||
"error_message": "Token is invalid",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
password = request.POST.get("password", False)
|
password = request.POST.get("password", False)
|
||||||
|
|
||||||
if not password:
|
if not password:
|
||||||
|
exc = AuthenticationException(
|
||||||
|
error_code=AUTHENTICATION_ERROR_CODES["INVALID_PASSWORD"],
|
||||||
|
error_message="INVALID_PASSWORD",
|
||||||
|
)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
base_host(request=request),
|
base_host(request=request),
|
||||||
"?" + urlencode({"error": "Password is required"}),
|
"?" + urlencode(exc.get_error_dict()),
|
||||||
)
|
)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
# Check the password complexity
|
# Check the password complexity
|
||||||
results = zxcvbn(password)
|
results = zxcvbn(password)
|
||||||
if results["score"] < 3:
|
if results["score"] < 3:
|
||||||
|
exc = AuthenticationException(
|
||||||
|
error_code=AUTHENTICATION_ERROR_CODES["INVALID_PASSWORD"],
|
||||||
|
error_message="INVALID_PASSWORD",
|
||||||
|
)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
base_host(request=request),
|
base_host(request=request),
|
||||||
"accounts/reset-password?"
|
"accounts/reset-password?"
|
||||||
+ urlencode(
|
+ urlencode(exc.get_error_dict()),
|
||||||
{
|
|
||||||
"error_code": "INVALID_PASSWORD",
|
|
||||||
"error_message": "The password is not a valid password",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
@ -196,15 +210,15 @@ class ResetPasswordEndpoint(View):
|
|||||||
)
|
)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
except DjangoUnicodeDecodeError:
|
except DjangoUnicodeDecodeError:
|
||||||
|
exc = AuthenticationException(
|
||||||
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
|
"EXPIRED_PASSWORD_TOKEN"
|
||||||
|
],
|
||||||
|
error_message="EXPIRED_PASSWORD_TOKEN",
|
||||||
|
)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
base_host(request=request),
|
base_host(request=request),
|
||||||
"accounts/reset-password?"
|
"accounts/reset-password?" + urlencode(exc.get_error_dict()),
|
||||||
+ urlencode(
|
|
||||||
{
|
|
||||||
"error_code": "INVALID_TOKEN",
|
|
||||||
"error_message": "The password token is not valid",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
@ -215,19 +229,29 @@ class ChangePasswordEndpoint(APIView):
|
|||||||
user = User.objects.get(pk=request.user.id)
|
user = User.objects.get(pk=request.user.id)
|
||||||
if serializer.is_valid():
|
if serializer.is_valid():
|
||||||
if not user.check_password(serializer.data.get("old_password")):
|
if not user.check_password(serializer.data.get("old_password")):
|
||||||
|
exc = AuthenticationException(
|
||||||
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
|
"INCORRECT_OLD_PASSWORD"
|
||||||
|
],
|
||||||
|
error_message="INCORRECT_OLD_PASSWORD",
|
||||||
|
payload={"error": "Old password is not correct"},
|
||||||
|
)
|
||||||
return Response(
|
return Response(
|
||||||
{"error": "Old password is not correct"},
|
exc.get_error_dict(),
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
)
|
)
|
||||||
|
|
||||||
# check the password score
|
# check the password score
|
||||||
results = zxcvbn(serializer.data.get("new_password"))
|
results = zxcvbn(serializer.data.get("new_password"))
|
||||||
if results["score"] < 3:
|
if results["score"] < 3:
|
||||||
|
exc = AuthenticationException(
|
||||||
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
|
"INVALID_NEW_PASSWORD"
|
||||||
|
],
|
||||||
|
error_message="INVALID_NEW_PASSWORD",
|
||||||
|
)
|
||||||
return Response(
|
return Response(
|
||||||
{
|
exc.get_error_dict(),
|
||||||
"error_code": "INVALID_PASSWORD",
|
|
||||||
"error_message": "Invalid password.",
|
|
||||||
},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -240,11 +264,12 @@ class ChangePasswordEndpoint(APIView):
|
|||||||
{"message": "Password updated successfully"},
|
{"message": "Password updated successfully"},
|
||||||
status=status.HTTP_200_OK,
|
status=status.HTTP_200_OK,
|
||||||
)
|
)
|
||||||
|
exc = AuthenticationException(
|
||||||
|
error_code=AUTHENTICATION_ERROR_CODES["INVALID_PASSWORD"],
|
||||||
|
error_message="INVALID_PASSWORD",
|
||||||
|
)
|
||||||
return Response(
|
return Response(
|
||||||
{
|
exc.get_error_dict(),
|
||||||
"error_code": "INVALID_PASSWORD",
|
|
||||||
"error_message": "Invalid passwords provided",
|
|
||||||
},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -256,30 +281,37 @@ class SetUserPasswordEndpoint(APIView):
|
|||||||
|
|
||||||
# If the user password is not autoset then return error
|
# If the user password is not autoset then return error
|
||||||
if not user.is_password_autoset:
|
if not user.is_password_autoset:
|
||||||
return Response(
|
exc = AuthenticationException(
|
||||||
{
|
error_code=AUTHENTICATION_ERROR_CODES["PASSWORD_ALREADY_SET"],
|
||||||
|
error_message="PASSWORD_ALREADY_SET",
|
||||||
|
payload={
|
||||||
"error": "Your password is already set please change your password from profile"
|
"error": "Your password is already set please change your password from profile"
|
||||||
},
|
},
|
||||||
|
)
|
||||||
|
return Response(
|
||||||
|
exc.get_error_dict(),
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check password validation
|
# Check password validation
|
||||||
if not password and len(str(password)) < 8:
|
if not password:
|
||||||
|
exc = AuthenticationException(
|
||||||
|
error_code=AUTHENTICATION_ERROR_CODES["INVALID_PASSWORD"],
|
||||||
|
error_message="INVALID_PASSWORD",
|
||||||
|
)
|
||||||
return Response(
|
return Response(
|
||||||
{
|
exc.get_error_dict(),
|
||||||
"error_code": "INVALID_PASSWORD",
|
|
||||||
"error_message": "Invalid password.",
|
|
||||||
},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
)
|
)
|
||||||
|
|
||||||
results = zxcvbn(password)
|
results = zxcvbn(password)
|
||||||
if results["score"] < 3:
|
if results["score"] < 3:
|
||||||
|
exc = AuthenticationException(
|
||||||
|
error_code=AUTHENTICATION_ERROR_CODES["INVALID_PASSWORD"],
|
||||||
|
error_message="INVALID_PASSWORD",
|
||||||
|
)
|
||||||
return Response(
|
return Response(
|
||||||
{
|
exc.get_error_dict(),
|
||||||
"error_code": "INVALID_PASSWORD",
|
|
||||||
"error_message": "Invalid password.",
|
|
||||||
},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -11,6 +11,10 @@ from rest_framework.views import APIView
|
|||||||
## Module imports
|
## Module imports
|
||||||
from plane.db.models import User
|
from plane.db.models import User
|
||||||
from plane.license.models import Instance
|
from plane.license.models import Instance
|
||||||
|
from plane.authentication.adapter.error import (
|
||||||
|
AUTHENTICATION_ERROR_CODES,
|
||||||
|
AuthenticationException,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class EmailCheckEndpoint(APIView):
|
class EmailCheckEndpoint(APIView):
|
||||||
@ -23,11 +27,14 @@ class EmailCheckEndpoint(APIView):
|
|||||||
# Check instance configuration
|
# Check instance configuration
|
||||||
instance = Instance.objects.first()
|
instance = Instance.objects.first()
|
||||||
if instance is None or not instance.is_setup_done:
|
if instance is None or not instance.is_setup_done:
|
||||||
|
exc = AuthenticationException(
|
||||||
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
|
"INSTANCE_NOT_CONFIGURED"
|
||||||
|
],
|
||||||
|
error_message="INSTANCE_NOT_CONFIGURED",
|
||||||
|
)
|
||||||
return Response(
|
return Response(
|
||||||
{
|
exc.get_error_dict(),
|
||||||
"error_code": "INSTANCE_NOT_CONFIGURED",
|
|
||||||
"error_message": "Instance is not configured",
|
|
||||||
},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -35,8 +42,12 @@ class EmailCheckEndpoint(APIView):
|
|||||||
|
|
||||||
# Return error if email is not present
|
# Return error if email is not present
|
||||||
if not email:
|
if not email:
|
||||||
|
exc = AuthenticationException(
|
||||||
|
error_code=AUTHENTICATION_ERROR_CODES["EMAIL_REQUIRED"],
|
||||||
|
error_message="EMAIL_REQUIRED",
|
||||||
|
)
|
||||||
return Response(
|
return Response(
|
||||||
{"error": "Email is required"},
|
exc.get_error_dict(),
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -44,13 +55,14 @@ class EmailCheckEndpoint(APIView):
|
|||||||
try:
|
try:
|
||||||
validate_email(email)
|
validate_email(email)
|
||||||
except ValidationError:
|
except ValidationError:
|
||||||
|
exc = AuthenticationException(
|
||||||
|
error_code=AUTHENTICATION_ERROR_CODES["INVALID_EMAIL"],
|
||||||
|
error_message="INVALID_EMAIL",
|
||||||
|
)
|
||||||
return Response(
|
return Response(
|
||||||
{
|
exc.get_error_dict(),
|
||||||
"error": "Email is invalid please provide a valid email address"
|
|
||||||
},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check if a user already exists with the given email
|
# Check if a user already exists with the given email
|
||||||
existing_user = User.objects.filter(email=email).first()
|
existing_user = User.objects.filter(email=email).first()
|
||||||
|
|
||||||
|
@ -8,12 +8,15 @@ from django.http import HttpResponseRedirect
|
|||||||
from django.views import View
|
from django.views import View
|
||||||
|
|
||||||
# Module imports
|
# Module imports
|
||||||
from plane.authentication.adapter.base import AuthenticationException
|
|
||||||
from plane.authentication.provider.credentials.email import EmailProvider
|
from plane.authentication.provider.credentials.email import EmailProvider
|
||||||
from plane.authentication.utils.login import user_login
|
from plane.authentication.utils.login import user_login
|
||||||
from plane.license.models import Instance
|
from plane.license.models import Instance
|
||||||
from plane.authentication.utils.host import base_host
|
from plane.authentication.utils.host import base_host
|
||||||
from plane.db.models import User
|
from plane.db.models import User
|
||||||
|
from plane.authentication.adapter.error import (
|
||||||
|
AUTHENTICATION_ERROR_CODES,
|
||||||
|
AuthenticationException,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class SignInAuthSpaceEndpoint(View):
|
class SignInAuthSpaceEndpoint(View):
|
||||||
@ -23,10 +26,14 @@ class SignInAuthSpaceEndpoint(View):
|
|||||||
# Check instance configuration
|
# Check instance configuration
|
||||||
instance = Instance.objects.first()
|
instance = Instance.objects.first()
|
||||||
if instance is None or not instance.is_setup_done:
|
if instance is None or not instance.is_setup_done:
|
||||||
params = {
|
# Redirection params
|
||||||
"error_code": "INSTANCE_NOT_CONFIGURED",
|
exc = AuthenticationException(
|
||||||
"error_message": "Instance is not configured",
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
}
|
"INSTANCE_NOT_CONFIGURED"
|
||||||
|
],
|
||||||
|
error_message="INSTANCE_NOT_CONFIGURED",
|
||||||
|
)
|
||||||
|
params = exc.get_error_dict()
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -41,10 +48,14 @@ class SignInAuthSpaceEndpoint(View):
|
|||||||
|
|
||||||
## Raise exception if any of the above are missing
|
## Raise exception if any of the above are missing
|
||||||
if not email or not password:
|
if not email or not password:
|
||||||
params = {
|
exc = AuthenticationException(
|
||||||
"error_code": "REQUIRED_EMAIL_PASSWORD",
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
"error_message": "Both email and password are required",
|
"REQUIRED_EMAIL_PASSWORD_SIGN_IN"
|
||||||
}
|
],
|
||||||
|
error_message="REQUIRED_EMAIL_PASSWORD_SIGN_IN",
|
||||||
|
payload={"email": str(email)},
|
||||||
|
)
|
||||||
|
params = exc.get_error_dict()
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -58,10 +69,12 @@ class SignInAuthSpaceEndpoint(View):
|
|||||||
try:
|
try:
|
||||||
validate_email(email)
|
validate_email(email)
|
||||||
except ValidationError:
|
except ValidationError:
|
||||||
params = {
|
exc = AuthenticationException(
|
||||||
"error_code": "INVALID_EMAIL",
|
error_code=AUTHENTICATION_ERROR_CODES["INVALID_EMAIL_SIGN_IN"],
|
||||||
"error_message": "Please provide a valid email address.",
|
error_message="INVALID_EMAIL_SIGN_IN",
|
||||||
}
|
payload={"email": str(email)},
|
||||||
|
)
|
||||||
|
params = exc.get_error_dict()
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -71,10 +84,12 @@ class SignInAuthSpaceEndpoint(View):
|
|||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
if not User.objects.filter(email=email).exists():
|
if not User.objects.filter(email=email).exists():
|
||||||
params = {
|
exc = AuthenticationException(
|
||||||
"error_code": "USER_DOES_NOT_EXIST",
|
error_code=AUTHENTICATION_ERROR_CODES["USER_DOES_NOT_EXIST"],
|
||||||
"error_message": "User could not be found with the given email.",
|
error_message="USER_DOES_NOT_EXIST",
|
||||||
}
|
payload={"email": str(email)},
|
||||||
|
)
|
||||||
|
params = exc.get_error_dict()
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -97,10 +112,7 @@ class SignInAuthSpaceEndpoint(View):
|
|||||||
)
|
)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
except AuthenticationException as e:
|
except AuthenticationException as e:
|
||||||
params = {
|
params = e.get_error_dict()
|
||||||
"error_code": str(e.error_code),
|
|
||||||
"error_message": str(e.error_message),
|
|
||||||
}
|
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -117,10 +129,14 @@ class SignUpAuthSpaceEndpoint(View):
|
|||||||
# Check instance configuration
|
# Check instance configuration
|
||||||
instance = Instance.objects.first()
|
instance = Instance.objects.first()
|
||||||
if instance is None or not instance.is_setup_done:
|
if instance is None or not instance.is_setup_done:
|
||||||
params = {
|
# Redirection params
|
||||||
"error_code": "INSTANCE_NOT_CONFIGURED",
|
exc = AuthenticationException(
|
||||||
"error_message": "Instance is not configured",
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
}
|
"INSTANCE_NOT_CONFIGURED"
|
||||||
|
],
|
||||||
|
error_message="INSTANCE_NOT_CONFIGURED",
|
||||||
|
)
|
||||||
|
params = exc.get_error_dict()
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -133,10 +149,15 @@ class SignUpAuthSpaceEndpoint(View):
|
|||||||
password = request.POST.get("password", False)
|
password = request.POST.get("password", False)
|
||||||
## Raise exception if any of the above are missing
|
## Raise exception if any of the above are missing
|
||||||
if not email or not password:
|
if not email or not password:
|
||||||
params = {
|
# Redirection params
|
||||||
"error_code": "REQUIRED_EMAIL_PASSWORD",
|
exc = AuthenticationException(
|
||||||
"error_message": "Both email and password are required",
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
}
|
"REQUIRED_EMAIL_PASSWORD_SIGN_UP"
|
||||||
|
],
|
||||||
|
error_message="REQUIRED_EMAIL_PASSWORD_SIGN_UP",
|
||||||
|
payload={"email": str(email)},
|
||||||
|
)
|
||||||
|
params = exc.get_error_dict()
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -149,10 +170,13 @@ class SignUpAuthSpaceEndpoint(View):
|
|||||||
try:
|
try:
|
||||||
validate_email(email)
|
validate_email(email)
|
||||||
except ValidationError:
|
except ValidationError:
|
||||||
params = {
|
# Redirection params
|
||||||
"error_code": "INVALID_EMAIL",
|
exc = AuthenticationException(
|
||||||
"error_message": "Please provide a valid email address.",
|
error_code=AUTHENTICATION_ERROR_CODES["INVALID_EMAIL_SIGN_UP"],
|
||||||
}
|
error_message="INVALID_EMAIL_SIGN_UP",
|
||||||
|
payload={"email": str(email)},
|
||||||
|
)
|
||||||
|
params = exc.get_error_dict()
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -162,10 +186,12 @@ class SignUpAuthSpaceEndpoint(View):
|
|||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
if User.objects.filter(email=email).exists():
|
if User.objects.filter(email=email).exists():
|
||||||
params = {
|
exc = AuthenticationException(
|
||||||
"error_code": "USER_ALREADY_EXIST",
|
error_code=AUTHENTICATION_ERROR_CODES["USER_ALREADY_EXIST"],
|
||||||
"error_message": "User already exists with the email.",
|
error_message="USER_ALREADY_EXIST",
|
||||||
}
|
payload={"email": str(email)},
|
||||||
|
)
|
||||||
|
params = exc.get_error_dict()
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -188,10 +214,7 @@ class SignUpAuthSpaceEndpoint(View):
|
|||||||
)
|
)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
except AuthenticationException as e:
|
except AuthenticationException as e:
|
||||||
params = {
|
params = e.get_error_dict()
|
||||||
"error_code": str(e.error_code),
|
|
||||||
"error_message": str(e.error_message),
|
|
||||||
}
|
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
|
@ -12,6 +12,10 @@ from plane.authentication.provider.oauth.github import GitHubOAuthProvider
|
|||||||
from plane.authentication.utils.login import user_login
|
from plane.authentication.utils.login import user_login
|
||||||
from plane.license.models import Instance
|
from plane.license.models import Instance
|
||||||
from plane.authentication.utils.host import base_host
|
from plane.authentication.utils.host import base_host
|
||||||
|
from plane.authentication.adapter.error import (
|
||||||
|
AUTHENTICATION_ERROR_CODES,
|
||||||
|
AuthenticationException,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class GitHubOauthInitiateSpaceEndpoint(View):
|
class GitHubOauthInitiateSpaceEndpoint(View):
|
||||||
@ -26,10 +30,13 @@ class GitHubOauthInitiateSpaceEndpoint(View):
|
|||||||
# Check instance configuration
|
# Check instance configuration
|
||||||
instance = Instance.objects.first()
|
instance = Instance.objects.first()
|
||||||
if instance is None or not instance.is_setup_done:
|
if instance is None or not instance.is_setup_done:
|
||||||
params = {
|
exc = AuthenticationException(
|
||||||
"error_code": "INSTANCE_NOT_CONFIGURED",
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
"error_message": "Instance is not configured",
|
"INSTANCE_NOT_CONFIGURED"
|
||||||
}
|
],
|
||||||
|
error_message="INSTANCE_NOT_CONFIGURED",
|
||||||
|
)
|
||||||
|
params = exc.get_error_dict()
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -44,11 +51,8 @@ class GitHubOauthInitiateSpaceEndpoint(View):
|
|||||||
request.session["state"] = state
|
request.session["state"] = state
|
||||||
auth_url = provider.get_auth_url()
|
auth_url = provider.get_auth_url()
|
||||||
return HttpResponseRedirect(auth_url)
|
return HttpResponseRedirect(auth_url)
|
||||||
except ImproperlyConfigured as e:
|
except AuthenticationException as e:
|
||||||
params = {
|
params = e.get_error_dict()
|
||||||
"error_code": "IMPROPERLY_CONFIGURED",
|
|
||||||
"error_message": str(e),
|
|
||||||
}
|
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -67,10 +71,13 @@ class GitHubCallbackSpaceEndpoint(View):
|
|||||||
next_path = request.session.get("next_path")
|
next_path = request.session.get("next_path")
|
||||||
|
|
||||||
if state != request.session.get("state", ""):
|
if state != request.session.get("state", ""):
|
||||||
params = {
|
exc = AuthenticationException(
|
||||||
"error_code": "OAUTH_PROVIDER_ERROR",
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
"error_message": "State does not match",
|
"GITHUB_OAUTH_PROVIDER_ERROR"
|
||||||
}
|
],
|
||||||
|
error_message="GITHUB_OAUTH_PROVIDER_ERROR",
|
||||||
|
)
|
||||||
|
params = exc.get_error_dict()
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -80,10 +87,13 @@ class GitHubCallbackSpaceEndpoint(View):
|
|||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
if not code:
|
if not code:
|
||||||
params = {
|
exc = AuthenticationException(
|
||||||
"error_code": "OAUTH_PROVIDER_ERROR",
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
"error_message": "Something went wrong while fetching data from OAuth provider. Please try again after sometime.",
|
"GITHUB_OAUTH_PROVIDER_ERROR"
|
||||||
}
|
],
|
||||||
|
error_message="GITHUB_OAUTH_PROVIDER_ERROR",
|
||||||
|
)
|
||||||
|
params = exc.get_error_dict()
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -104,11 +114,8 @@ class GitHubCallbackSpaceEndpoint(View):
|
|||||||
# redirect to referer path
|
# redirect to referer path
|
||||||
url = urljoin(base_host, str(next_path) if next_path else "/")
|
url = urljoin(base_host, str(next_path) if next_path else "/")
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
except ImproperlyConfigured as e:
|
except AuthenticationException as e:
|
||||||
params = {
|
params = e.get_error_dict()
|
||||||
"error_code": "IMPROPERLY_CONFIGURED",
|
|
||||||
"error_message": str(e),
|
|
||||||
}
|
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
|
@ -3,17 +3,18 @@ import uuid
|
|||||||
from urllib.parse import urlencode, urljoin
|
from urllib.parse import urlencode, urljoin
|
||||||
|
|
||||||
# Django import
|
# Django import
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
from django.views import View
|
from django.views import View
|
||||||
|
|
||||||
|
# Module imports
|
||||||
from plane.authentication.provider.oauth.google import GoogleOAuthProvider
|
from plane.authentication.provider.oauth.google import GoogleOAuthProvider
|
||||||
from plane.authentication.utils.login import user_login
|
from plane.authentication.utils.login import user_login
|
||||||
|
|
||||||
|
|
||||||
# Module imports
|
|
||||||
from plane.license.models import Instance
|
from plane.license.models import Instance
|
||||||
from plane.authentication.utils.host import base_host
|
from plane.authentication.utils.host import base_host
|
||||||
|
from plane.authentication.adapter.error import (
|
||||||
|
AuthenticationException,
|
||||||
|
AUTHENTICATION_ERROR_CODES,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class GoogleOauthInitiateSpaceEndpoint(View):
|
class GoogleOauthInitiateSpaceEndpoint(View):
|
||||||
@ -26,10 +27,13 @@ class GoogleOauthInitiateSpaceEndpoint(View):
|
|||||||
# Check instance configuration
|
# Check instance configuration
|
||||||
instance = Instance.objects.first()
|
instance = Instance.objects.first()
|
||||||
if instance is None or not instance.is_setup_done:
|
if instance is None or not instance.is_setup_done:
|
||||||
params = {
|
exc = AuthenticationException(
|
||||||
"error_code": "INSTANCE_NOT_CONFIGURED",
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
"error_message": "Instance is not configured",
|
"INSTANCE_NOT_CONFIGURED"
|
||||||
}
|
],
|
||||||
|
error_message="INSTANCE_NOT_CONFIGURED",
|
||||||
|
)
|
||||||
|
params = exc.get_error_dict()
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -44,11 +48,8 @@ class GoogleOauthInitiateSpaceEndpoint(View):
|
|||||||
request.session["state"] = state
|
request.session["state"] = state
|
||||||
auth_url = provider.get_auth_url()
|
auth_url = provider.get_auth_url()
|
||||||
return HttpResponseRedirect(auth_url)
|
return HttpResponseRedirect(auth_url)
|
||||||
except ImproperlyConfigured as e:
|
except AuthenticationException as e:
|
||||||
params = {
|
params = e.get_error_dict()
|
||||||
"error_code": "IMPROPERLY_CONFIGURED",
|
|
||||||
"error_message": str(e),
|
|
||||||
}
|
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -66,10 +67,13 @@ class GoogleCallbackSpaceEndpoint(View):
|
|||||||
next_path = request.session.get("next_path")
|
next_path = request.session.get("next_path")
|
||||||
|
|
||||||
if state != request.session.get("state", ""):
|
if state != request.session.get("state", ""):
|
||||||
params = {
|
exc = AuthenticationException(
|
||||||
"error_code": "OAUTH_PROVIDER_ERROR",
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
"error_message": "State does not match",
|
"GOOGLE_OAUTH_PROVIDER_ERROR"
|
||||||
}
|
],
|
||||||
|
error_message="GOOGLE_OAUTH_PROVIDER_ERROR",
|
||||||
|
)
|
||||||
|
params = exc.get_error_dict()
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -78,10 +82,13 @@ class GoogleCallbackSpaceEndpoint(View):
|
|||||||
)
|
)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
if not code:
|
if not code:
|
||||||
params = {
|
exc = AuthenticationException(
|
||||||
"error_code": "OAUTH_PROVIDER_ERROR",
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
"error_message": "Something went wrong while fetching data from OAuth provider. Please try again after sometime.",
|
"GOOGLE_OAUTH_PROVIDER_ERROR"
|
||||||
}
|
],
|
||||||
|
error_message="GOOGLE_OAUTH_PROVIDER_ERROR",
|
||||||
|
)
|
||||||
|
params = exc.get_error_dict()
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = next_path
|
params["next_path"] = next_path
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -102,11 +109,8 @@ class GoogleCallbackSpaceEndpoint(View):
|
|||||||
base_host, str(next_path) if next_path else "/spaces"
|
base_host, str(next_path) if next_path else "/spaces"
|
||||||
)
|
)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
except ImproperlyConfigured as e:
|
except AuthenticationException as e:
|
||||||
params = {
|
params = e.get_error_dict()
|
||||||
"error_code": "IMPROPERLY_CONFIGURED",
|
|
||||||
"error_message": str(e),
|
|
||||||
}
|
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
|
@ -14,7 +14,6 @@ from rest_framework.response import Response
|
|||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
|
|
||||||
# Module imports
|
# Module imports
|
||||||
from plane.authentication.adapter.base import AuthenticationException
|
|
||||||
from plane.authentication.provider.credentials.magic_code import (
|
from plane.authentication.provider.credentials.magic_code import (
|
||||||
MagicCodeProvider,
|
MagicCodeProvider,
|
||||||
)
|
)
|
||||||
@ -23,6 +22,10 @@ from plane.bgtasks.magic_link_code_task import magic_link
|
|||||||
from plane.license.models import Instance
|
from plane.license.models import Instance
|
||||||
from plane.authentication.utils.host import base_host
|
from plane.authentication.utils.host import base_host
|
||||||
from plane.db.models import User, Profile
|
from plane.db.models import User, Profile
|
||||||
|
from plane.authentication.adapter.error import (
|
||||||
|
AuthenticationException,
|
||||||
|
AUTHENTICATION_ERROR_CODES,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class MagicGenerateSpaceEndpoint(APIView):
|
class MagicGenerateSpaceEndpoint(APIView):
|
||||||
@ -35,11 +38,14 @@ class MagicGenerateSpaceEndpoint(APIView):
|
|||||||
# Check if instance is configured
|
# Check if instance is configured
|
||||||
instance = Instance.objects.first()
|
instance = Instance.objects.first()
|
||||||
if instance is None or not instance.is_setup_done:
|
if instance is None or not instance.is_setup_done:
|
||||||
|
exc = AuthenticationException(
|
||||||
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
|
"INSTANCE_NOT_CONFIGURED"
|
||||||
|
],
|
||||||
|
error_message="INSTANCE_NOT_CONFIGURED",
|
||||||
|
)
|
||||||
return Response(
|
return Response(
|
||||||
{
|
exc.get_error_dict(), status=status.HTTP_400_BAD_REQUEST
|
||||||
"error_code": "INSTANCE_NOT_CONFIGURED",
|
|
||||||
"error_message": "Instance is not configured",
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
origin = base_host(request=request)
|
origin = base_host(request=request)
|
||||||
@ -53,28 +59,9 @@ class MagicGenerateSpaceEndpoint(APIView):
|
|||||||
# If the smtp is configured send through here
|
# If the smtp is configured send through here
|
||||||
magic_link.delay(email, key, token, origin)
|
magic_link.delay(email, key, token, origin)
|
||||||
return Response({"key": str(key)}, status=status.HTTP_200_OK)
|
return Response({"key": str(key)}, status=status.HTTP_200_OK)
|
||||||
except ImproperlyConfigured as e:
|
|
||||||
return Response(
|
|
||||||
{
|
|
||||||
"error_code": "IMPROPERLY_CONFIGURED",
|
|
||||||
"error_message": str(e),
|
|
||||||
},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
|
||||||
)
|
|
||||||
except AuthenticationException as e:
|
except AuthenticationException as e:
|
||||||
return Response(
|
return Response(
|
||||||
{
|
e.get_error_dict(),
|
||||||
"error_code": str(e.error_code),
|
|
||||||
"error_message": str(e.error_message),
|
|
||||||
},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
|
||||||
)
|
|
||||||
except ValidationError:
|
|
||||||
return Response(
|
|
||||||
{
|
|
||||||
"error_code": "INVALID_EMAIL",
|
|
||||||
"error_message": "Valid email is required for generating a magic code",
|
|
||||||
},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -89,10 +76,13 @@ class MagicSignInSpaceEndpoint(View):
|
|||||||
next_path = request.POST.get("next_path")
|
next_path = request.POST.get("next_path")
|
||||||
|
|
||||||
if code == "" or email == "":
|
if code == "" or email == "":
|
||||||
params = {
|
exc = AuthenticationException(
|
||||||
"error_code": "EMAIL_CODE_REQUIRED",
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
"error_message": "Email and code are required",
|
"MAGIC_SIGN_IN_EMAIL_CODE_REQUIRED"
|
||||||
}
|
],
|
||||||
|
error_message="MAGIC_SIGN_IN_EMAIL_CODE_REQUIRED",
|
||||||
|
)
|
||||||
|
params = exc.get_error_dict()
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -122,26 +112,17 @@ class MagicSignInSpaceEndpoint(View):
|
|||||||
# Login the user and record his device info
|
# Login the user and record his device info
|
||||||
user_login(request=request, user=user)
|
user_login(request=request, user=user)
|
||||||
# redirect to referer path
|
# redirect to referer path
|
||||||
|
profile = Profile.objects.get(user=user)
|
||||||
if user.is_password_autoset and profile.is_onboarded:
|
if user.is_password_autoset and profile.is_onboarded:
|
||||||
path = "spaces/accounts/set-password"
|
path = "spaces/accounts/set-password"
|
||||||
else:
|
else:
|
||||||
# Get the redirection path
|
# Get the redirection path
|
||||||
path = (
|
path = str(next_path) if next_path else "spaces"
|
||||||
str(next_path)
|
url = urljoin(base_host(request=request), path)
|
||||||
if next_path
|
|
||||||
else "spaces"
|
|
||||||
)
|
|
||||||
url = urljoin(
|
|
||||||
base_host(request=request),
|
|
||||||
path
|
|
||||||
)
|
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
except AuthenticationException as e:
|
except AuthenticationException as e:
|
||||||
params = {
|
params = e.get_error_dict()
|
||||||
"error_code": str(e.error_code),
|
|
||||||
"error_message": str(e.error_message),
|
|
||||||
}
|
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -161,10 +142,13 @@ class MagicSignUpSpaceEndpoint(View):
|
|||||||
next_path = request.POST.get("next_path")
|
next_path = request.POST.get("next_path")
|
||||||
|
|
||||||
if code == "" or email == "":
|
if code == "" or email == "":
|
||||||
params = {
|
exc = AuthenticationException(
|
||||||
"error_code": "EMAIL_CODE_REQUIRED",
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
"error_message": "Email and code are required",
|
"MAGIC_SIGN_UP_EMAIL_CODE_REQUIRED"
|
||||||
}
|
],
|
||||||
|
error_message="MAGIC_SIGN_UP_EMAIL_CODE_REQUIRED",
|
||||||
|
)
|
||||||
|
params = exc.get_error_dict()
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -174,10 +158,11 @@ class MagicSignUpSpaceEndpoint(View):
|
|||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
if User.objects.filter(email=email).exists():
|
if User.objects.filter(email=email).exists():
|
||||||
params = {
|
exc = AuthenticationException(
|
||||||
"error_code": "USER_ALREADY_EXIST",
|
error_code=AUTHENTICATION_ERROR_CODES["USER_ALREADY_EXIST"],
|
||||||
"error_message": "User already exists with the email.",
|
error_message="USER_ALREADY_EXIST",
|
||||||
}
|
)
|
||||||
|
params = exc.get_error_dict()
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
@ -201,10 +186,7 @@ class MagicSignUpSpaceEndpoint(View):
|
|||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
except AuthenticationException as e:
|
except AuthenticationException as e:
|
||||||
params = {
|
params = e.get_error_dict()
|
||||||
"error_code": str(e.error_code),
|
|
||||||
"error_message": str(e.error_message),
|
|
||||||
}
|
|
||||||
if next_path:
|
if next_path:
|
||||||
params["next_path"] = str(next_path)
|
params["next_path"] = str(next_path)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
|
@ -29,6 +29,10 @@ from plane.db.models import User, Profile
|
|||||||
from plane.utils.cache import cache_response, invalidate_cache
|
from plane.utils.cache import cache_response, invalidate_cache
|
||||||
from plane.authentication.utils.login import user_login
|
from plane.authentication.utils.login import user_login
|
||||||
from plane.authentication.utils.host import base_host
|
from plane.authentication.utils.host import base_host
|
||||||
|
from plane.authentication.adapter.error import (
|
||||||
|
AUTHENTICATION_ERROR_CODES,
|
||||||
|
AuthenticationException,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class InstanceAdminEndpoint(BaseAPIView):
|
class InstanceAdminEndpoint(BaseAPIView):
|
||||||
@ -95,29 +99,27 @@ class InstanceAdminSignUpEndpoint(View):
|
|||||||
# Check instance first
|
# Check instance first
|
||||||
instance = Instance.objects.first()
|
instance = Instance.objects.first()
|
||||||
if instance is None:
|
if instance is None:
|
||||||
|
exc = AuthenticationException(
|
||||||
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
|
"INSTANCE_NOT_CONFIGURED"
|
||||||
|
],
|
||||||
|
error_message="INSTANCE_NOT_CONFIGURED",
|
||||||
|
)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
base_host(request=request),
|
base_host(request=request),
|
||||||
"god-mode/setup?"
|
"god-mode/setup?" + urlencode(exc.get_error_dict()),
|
||||||
+ urlencode(
|
|
||||||
{
|
|
||||||
"error_code": "INSTANCE_NOT_CONFIGURED",
|
|
||||||
"error_message": "Instance is not configured",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
# check if the instance has already an admin registered
|
# check if the instance has already an admin registered
|
||||||
if InstanceAdmin.objects.first():
|
if InstanceAdmin.objects.first():
|
||||||
|
exc = AuthenticationException(
|
||||||
|
error_code=AUTHENTICATION_ERROR_CODES["ADMIN_ALREADY_EXIST"],
|
||||||
|
error_message="ADMIN_ALREADY_EXIST",
|
||||||
|
)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
base_host(request=request),
|
base_host(request=request),
|
||||||
"god-mode/setup?"
|
"god-mode/setup?" + urlencode(exc.get_error_dict()),
|
||||||
+ urlencode(
|
|
||||||
{
|
|
||||||
"error_code": "ADMIN_ALREADY_EXIST",
|
|
||||||
"error_message": "Admin for the instance has been already registered.",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
@ -131,20 +133,22 @@ class InstanceAdminSignUpEndpoint(View):
|
|||||||
|
|
||||||
# return error if the email and password is not present
|
# return error if the email and password is not present
|
||||||
if not email or not password or not first_name:
|
if not email or not password or not first_name:
|
||||||
|
exc = AuthenticationException(
|
||||||
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
|
"REQUIRED_ADMIN_EMAIL_PASSWORD_FIRST_NAME"
|
||||||
|
],
|
||||||
|
error_message="REQUIRED_ADMIN_EMAIL_PASSWORD_FIRST_NAME",
|
||||||
|
payload={
|
||||||
|
"email": email,
|
||||||
|
"first_name": first_name,
|
||||||
|
"last_name": last_name,
|
||||||
|
"company_name": company_name,
|
||||||
|
"is_telemetry_enabled": is_telemetry_enabled,
|
||||||
|
},
|
||||||
|
)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
base_host(request=request),
|
base_host(request=request),
|
||||||
"god-mode/setup?"
|
"god-mode/setup?" + urlencode(exc.get_error_dict()),
|
||||||
+ urlencode(
|
|
||||||
{
|
|
||||||
"email": email,
|
|
||||||
"first_name": first_name,
|
|
||||||
"last_name": last_name,
|
|
||||||
"company_name": company_name,
|
|
||||||
"is_telemetry_enabled": is_telemetry_enabled,
|
|
||||||
"error_code": "REQUIRED_EMAIL_PASSWORD_FIRST_NAME",
|
|
||||||
"error_message": "Email, name and password are required",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
@ -153,60 +157,62 @@ class InstanceAdminSignUpEndpoint(View):
|
|||||||
try:
|
try:
|
||||||
validate_email(email)
|
validate_email(email)
|
||||||
except ValidationError:
|
except ValidationError:
|
||||||
|
exc = AuthenticationException(
|
||||||
|
error_code=AUTHENTICATION_ERROR_CODES["INVALID_ADMIN_EMAIL"],
|
||||||
|
error_message="INVALID_ADMIN_EMAIL",
|
||||||
|
payload={
|
||||||
|
"email": email,
|
||||||
|
"first_name": first_name,
|
||||||
|
"last_name": last_name,
|
||||||
|
"company_name": company_name,
|
||||||
|
"is_telemetry_enabled": is_telemetry_enabled,
|
||||||
|
},
|
||||||
|
)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
base_host(request=request),
|
base_host(request=request),
|
||||||
"god-mode/setup?"
|
"god-mode/setup?" + urlencode(exc.get_error_dict()),
|
||||||
+ urlencode(
|
|
||||||
{
|
|
||||||
"email": email,
|
|
||||||
"first_name": first_name,
|
|
||||||
"last_name": last_name,
|
|
||||||
"company_name": company_name,
|
|
||||||
"is_telemetry_enabled": is_telemetry_enabled,
|
|
||||||
"error_code": "INVALID_EMAIL",
|
|
||||||
"error_message": "Please provide a valid email address.",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
# Check if already a user exists or not
|
# Check if already a user exists or not
|
||||||
# Existing user
|
# Existing user
|
||||||
if User.objects.filter(email=email).exists():
|
if User.objects.filter(email=email).exists():
|
||||||
|
exc = AuthenticationException(
|
||||||
|
error_code=AUTHENTICATION_ERROR_CODES["USER_ALREADY_EXISTS"],
|
||||||
|
error_message="USER_ALREADY_EXISTS",
|
||||||
|
payload={
|
||||||
|
"email": email,
|
||||||
|
"first_name": first_name,
|
||||||
|
"last_name": last_name,
|
||||||
|
"company_name": company_name,
|
||||||
|
"is_telemetry_enabled": is_telemetry_enabled,
|
||||||
|
},
|
||||||
|
)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
base_host(request=request),
|
base_host(request=request),
|
||||||
"god-mode/setup?"
|
"god-mode/setup?" + urlencode(exc.get_error_dict()),
|
||||||
+ urlencode(
|
|
||||||
{
|
|
||||||
"email": email,
|
|
||||||
"first_name": first_name,
|
|
||||||
"last_name": last_name,
|
|
||||||
"company_name": company_name,
|
|
||||||
"is_telemetry_enabled": is_telemetry_enabled,
|
|
||||||
"error_code": "USER_ALREADY_EXISTS",
|
|
||||||
"error_message": "User already exists.",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
else:
|
else:
|
||||||
|
|
||||||
results = zxcvbn(password)
|
results = zxcvbn(password)
|
||||||
if results["score"] < 3:
|
if results["score"] < 3:
|
||||||
|
exc = AuthenticationException(
|
||||||
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
|
"INVALID_ADMIN_PASSWORD"
|
||||||
|
],
|
||||||
|
error_message="INVALID_ADMIN_PASSWORD",
|
||||||
|
payload={
|
||||||
|
"email": email,
|
||||||
|
"first_name": first_name,
|
||||||
|
"last_name": last_name,
|
||||||
|
"company_name": company_name,
|
||||||
|
"is_telemetry_enabled": is_telemetry_enabled,
|
||||||
|
},
|
||||||
|
)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
base_host(request=request),
|
base_host(request=request),
|
||||||
"god-mode/setup?"
|
"god-mode/setup?" + urlencode(exc.get_error_dict()),
|
||||||
+ urlencode(
|
|
||||||
{
|
|
||||||
"email": email,
|
|
||||||
"first_name": first_name,
|
|
||||||
"last_name": last_name,
|
|
||||||
"company_name": company_name,
|
|
||||||
"is_telemetry_enabled": is_telemetry_enabled,
|
|
||||||
"error_code": "INVALID_PASSWORD",
|
|
||||||
"error_message": "Invalid password provided.",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
@ -254,15 +260,15 @@ class InstanceAdminSignInEndpoint(View):
|
|||||||
# Check instance first
|
# Check instance first
|
||||||
instance = Instance.objects.first()
|
instance = Instance.objects.first()
|
||||||
if instance is None:
|
if instance is None:
|
||||||
|
exc = AuthenticationException(
|
||||||
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
|
"INSTANCE_NOT_CONFIGURED"
|
||||||
|
],
|
||||||
|
error_message="INSTANCE_NOT_CONFIGURED",
|
||||||
|
)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
base_host(request=request),
|
base_host(request=request),
|
||||||
"god-mode/login?"
|
"god-mode/login?" + urlencode(exc.get_error_dict()),
|
||||||
+ urlencode(
|
|
||||||
{
|
|
||||||
"error_code": "INSTANCE_NOT_CONFIGURED",
|
|
||||||
"error_message": "Instance is not configured",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
@ -272,16 +278,18 @@ class InstanceAdminSignInEndpoint(View):
|
|||||||
|
|
||||||
# return error if the email and password is not present
|
# return error if the email and password is not present
|
||||||
if not email or not password:
|
if not email or not password:
|
||||||
|
exc = AuthenticationException(
|
||||||
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
|
"REQUIRED_ADMIN_EMAIL_PASSWORD"
|
||||||
|
],
|
||||||
|
error_message="REQUIRED_ADMIN_EMAIL_PASSWORD",
|
||||||
|
payload={
|
||||||
|
"email": email,
|
||||||
|
},
|
||||||
|
)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
base_host(request=request),
|
base_host(request=request),
|
||||||
"god-mode/login?"
|
"god-mode/login?" + urlencode(exc.get_error_dict()),
|
||||||
+ urlencode(
|
|
||||||
{
|
|
||||||
"email": email,
|
|
||||||
"error_code": "REQUIRED_EMAIL_PASSWORD",
|
|
||||||
"error_message": "Email and password are required",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
@ -290,16 +298,16 @@ class InstanceAdminSignInEndpoint(View):
|
|||||||
try:
|
try:
|
||||||
validate_email(email)
|
validate_email(email)
|
||||||
except ValidationError:
|
except ValidationError:
|
||||||
|
exc = AuthenticationException(
|
||||||
|
error_code=AUTHENTICATION_ERROR_CODES["INVALID_ADMIN_EMAIL"],
|
||||||
|
error_message="INVALID_ADMIN_EMAIL",
|
||||||
|
payload={
|
||||||
|
"email": email,
|
||||||
|
},
|
||||||
|
)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
base_host(request=request),
|
base_host(request=request),
|
||||||
"god-mode/login?"
|
"god-mode/login?" + urlencode(exc.get_error_dict()),
|
||||||
+ urlencode(
|
|
||||||
{
|
|
||||||
"email": email,
|
|
||||||
"error_code": "INVALID_EMAIL",
|
|
||||||
"error_message": "Please provide a valid email address.",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
@ -308,46 +316,50 @@ class InstanceAdminSignInEndpoint(View):
|
|||||||
|
|
||||||
# Error out if the user is not present
|
# Error out if the user is not present
|
||||||
if not user:
|
if not user:
|
||||||
|
exc = AuthenticationException(
|
||||||
|
error_code=AUTHENTICATION_ERROR_CODES["USER_DOES_NOT_EXIST"],
|
||||||
|
error_message="USER_DOES_NOT_EXIST",
|
||||||
|
payload={
|
||||||
|
"email": email,
|
||||||
|
},
|
||||||
|
)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
base_host(request=request),
|
base_host(request=request),
|
||||||
"god-mode/login?"
|
"god-mode/login?" + urlencode(exc.get_error_dict()),
|
||||||
+ urlencode(
|
|
||||||
{
|
|
||||||
"email": email,
|
|
||||||
"error_code": "USER_DOES_NOT_EXIST",
|
|
||||||
"error_message": "User does not exist",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
# Check password of the user
|
# Check password of the user
|
||||||
if not user.check_password(password):
|
if not user.check_password(password):
|
||||||
|
exc = AuthenticationException(
|
||||||
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
|
"ADMIN_AUTHENTICATION_FAILED"
|
||||||
|
],
|
||||||
|
error_message="ADMIN_AUTHENTICATION_FAILED",
|
||||||
|
payload={
|
||||||
|
"email": email,
|
||||||
|
},
|
||||||
|
)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
base_host(request=request),
|
base_host(request=request),
|
||||||
"god-mode/login?"
|
"god-mode/login?" + urlencode(exc.get_error_dict()),
|
||||||
+ urlencode(
|
|
||||||
{
|
|
||||||
"email": email,
|
|
||||||
"error_code": "AUTHENTICATION_FAILED",
|
|
||||||
"error_message": "Sorry, we could not find an admin user with the provided credentials. Please try again.",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
# Check if the user is an instance admin
|
# Check if the user is an instance admin
|
||||||
if not InstanceAdmin.objects.filter(instance=instance, user=user):
|
if not InstanceAdmin.objects.filter(instance=instance, user=user):
|
||||||
|
exc = AuthenticationException(
|
||||||
|
error_code=AUTHENTICATION_ERROR_CODES[
|
||||||
|
"ADMIN_AUTHENTICATION_FAILED"
|
||||||
|
],
|
||||||
|
error_message="ADMIN_AUTHENTICATION_FAILED",
|
||||||
|
payload={
|
||||||
|
"email": email,
|
||||||
|
},
|
||||||
|
)
|
||||||
url = urljoin(
|
url = urljoin(
|
||||||
base_host(request=request),
|
base_host(request=request),
|
||||||
"god-mode/login?"
|
"god-mode/login?" + urlencode(exc.get_error_dict()),
|
||||||
+ urlencode(
|
|
||||||
{
|
|
||||||
"email": email,
|
|
||||||
"error_code": "AUTHENTICATION_FAILED",
|
|
||||||
"error_message": "Sorry, we could not find an admin user with the provided credentials. Please try again.",
|
|
||||||
}
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
# settings last active for the user
|
# settings last active for the user
|
||||||
|
Loading…
Reference in New Issue
Block a user