Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 90 additions & 1 deletion apiserver/plane/api/views/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import random
import string
import json
import requests

# Django imports
from django.utils import timezone
Expand Down Expand Up @@ -85,6 +86,28 @@ def post(self, request):
"user": serialized_user,
}

# Send event to Jitsu for tracking
if settings.JITSU_BASE_API:
_ = requests.post(
settings.JITSU_BASE_API,
headers={
"Content-Type": "application/json",
"X-Auth-Token": settings.JITSU_SECRET_KEY,
},
json={
"event_id": uuid.uuid4().hex,
"event_data": {
"medium": "email",
},
"user": {"email": email},
"device_ctx": {
"ip": request.META.get("REMOTE_ADDR"),
"user_agent": request.META.get("HTTP_USER_AGENT"),
},
"event_type": "SIGN_UP",
},
)

return Response(data, status=status.HTTP_200_OK)
# Sign in Process
else:
Expand Down Expand Up @@ -114,7 +137,27 @@ def post(self, request):
user.save()

access_token, refresh_token = get_tokens_for_user(user)

# Send event to Jitsu for tracking
if settings.JITSU_BASE_API:
_ = requests.post(
settings.JITSU_BASE_API,
headers={
"Content-Type": "application/json",
"X-Auth-Token": settings.JITSU_SECRET_KEY,
},
json={
"event_id": uuid.uuid4().hex,
"event_data": {
"medium": "email",
},
"user": {"email": email},
"device_ctx": {
"ip": request.META.get("REMOTE_ADDR"),
"user_agent": request.META.get("HTTP_USER_AGENT"),
},
"event_type": "SIGN_IN",
},
)
data = {
"access_token": access_token,
"refresh_token": refresh_token,
Expand Down Expand Up @@ -268,13 +311,59 @@ def post(self, request):
if str(token) == str(user_token):
if User.objects.filter(email=email).exists():
user = User.objects.get(email=email)
# Send event to Jitsu for tracking
if settings.JITSU_BASE_API:
_ = requests.post(
settings.JITSU_BASE_API,
headers={
"Content-Type": "application/json",
"X-Auth-Token": settings.JITSU_SECRET_KEY,
},
json={
"event_id": uuid.uuid4().hex,
"event_data": {
"medium": "code",
},
"user": {"email": email},
"device_ctx": {
"ip": request.META.get("REMOTE_ADDR"),
"user_agent": request.META.get(
"HTTP_USER_AGENT"
),
},
"event_type": "SIGN_IN",
},
)
else:
user = User.objects.create(
email=email,
username=uuid.uuid4().hex,
password=make_password(uuid.uuid4().hex),
is_password_autoset=True,
)
# Send event to Jitsu for tracking
if settings.JITSU_BASE_API:
_ = requests.post(
settings.JITSU_BASE_API,
headers={
"Content-Type": "application/json",
"X-Auth-Token": settings.JITSU_SECRET_KEY,
},
json={
"event_id": uuid.uuid4().hex,
"event_data": {
"medium": "code",
},
"user": {"email": email},
"device_ctx": {
"ip": request.META.get("REMOTE_ADDR"),
"user_agent": request.META.get(
"HTTP_USER_AGENT"
),
},
"event_type": "SIGN_UP",
},
)

user.last_active = timezone.now()
user.last_login_time = timezone.now()
Expand Down
42 changes: 41 additions & 1 deletion apiserver/plane/api/views/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

# Django imports
from django.utils import timezone
from django.conf import settings

# Third Party modules
from rest_framework.response import Response
Expand Down Expand Up @@ -204,7 +205,26 @@ def post(self, request):
"last_login_at": timezone.now(),
},
)

if settings.JITSU_BASE_API:
_ = requests.post(
settings.JITSU_BASE_API,
headers={
"Content-Type": "application/json",
"X-Auth-Token": settings.JITSU_SECRET_KEY,
},
json={
"event_id": uuid.uuid4().hex,
"event_data": {
"medium": f"oauth-{medium}",
},
"user": {"email": email},
"device_ctx": {
"ip": request.META.get("REMOTE_ADDR"),
"user_agent": request.META.get("HTTP_USER_AGENT"),
},
"event_type": "SIGN_IN",
},
)
return Response(data, status=status.HTTP_200_OK)

except User.DoesNotExist:
Expand Down Expand Up @@ -253,6 +273,26 @@ def post(self, request):
"user": serialized_user,
"permissions": [],
}
if settings.JITSU_BASE_API:
_ = requests.post(
settings.JITSU_BASE_API,
headers={
"Content-Type": "application/json",
"X-Auth-Token": settings.JITSU_SECRET_KEY,
},
json={
"event_id": uuid.uuid4().hex,
"event_data": {
"medium": f"oauth-{medium}",
},
"user": {"email": email},
"device_ctx": {
"ip": request.META.get("REMOTE_ADDR"),
"user_agent": request.META.get("HTTP_USER_AGENT"),
},
"event_type": "SIGN_UP",
},
)

SocialLoginConnection.objects.update_or_create(
medium=medium,
Expand Down
3 changes: 3 additions & 0 deletions apiserver/plane/settings/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,6 @@

WEB_URL = os.environ.get("WEB_URL", "localhost:3000")
PROXY_BASE_URL = os.environ.get("PROXY_BASE_URL", False)

JITSU_SECRET_KEY = os.environ.get("JITSU_SECRET_KEY", False)
JITSU_BASE_API = os.environ.get("JITSU_BASE_API", False)
3 changes: 3 additions & 0 deletions apiserver/plane/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,6 @@
WEB_URL = os.environ.get("WEB_URL")

PROXY_BASE_URL = os.environ.get("PROXY_BASE_URL", False)

JITSU_SECRET_KEY = os.environ.get("JITSU_SECRET_KEY", False)
JITSU_BASE_API = os.environ.get("JITSU_BASE_API", False)
3 changes: 3 additions & 0 deletions apiserver/plane/settings/staging.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,6 @@
WEB_URL = os.environ.get("WEB_URL")

PROXY_BASE_URL = os.environ.get("PROXY_BASE_URL", False)

JITSU_SECRET_KEY = os.environ.get("JITSU_SECRET_KEY", False)
JITSU_BASE_API = os.environ.get("JITSU_BASE_API", False)