Skip to content

Commit

Permalink
Remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
Yakser committed Sep 4, 2023
1 parent 11db4e2 commit 7df0fcd
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 112 deletions.
27 changes: 0 additions & 27 deletions users/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,6 @@
User = get_user_model()


def reset_email(user, request):
access_token = RefreshToken.for_user(user).access_token
refresh_token = RefreshToken.for_user(user)

relative_link = reverse("users:password_reset_sent")

current_site = get_current_site(request).domain
absolute_url = (
f"{PROTOCOL}://{current_site}{relative_link}?"
f"access_token={access_token}&refresh_token={refresh_token}"
)

email_body = (
f"Здравствуйте, {user.first_name} {user.last_name}!"
f" Перейдите по данной ссылке для смены пароля:\n {absolute_url}\n\nС уважением, "
f"Procollab!"
)

data = {
"email_body": email_body,
"email_subject": "Procollab | Сброс пароля",
"to_email": user.email,
}

Email.send_email(data)


def verify_email(user, request):
token = RefreshToken.for_user(user).access_token

Expand Down
85 changes: 0 additions & 85 deletions users/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from datetime import datetime

import jwt
from django.apps import apps
from django.conf import settings
Expand All @@ -14,7 +12,6 @@
ListAPIView,
ListCreateAPIView,
RetrieveUpdateDestroyAPIView,
UpdateAPIView,
RetrieveAPIView,
)
from rest_framework.permissions import AllowAny, IsAuthenticated
Expand All @@ -33,7 +30,6 @@
)
from projects.serializers import ProjectListSerializer
from users.helpers import (
reset_email,
verify_email,
check_related_fields_update,
)
Expand All @@ -48,8 +44,6 @@
from users.serializers import (
AchievementDetailSerializer,
AchievementListSerializer,
EmailSerializer,
PasswordSerializer,
UserDetailSerializer,
UserListSerializer,
VerifyEmailSerializer,
Expand Down Expand Up @@ -222,85 +216,6 @@ def get(self, request):
)


class EmailResetPassword(GenericAPIView):
serializer_class = EmailSerializer
permission_classes = [AllowAny]

def post(self, request, *args, **kwargs):
serializer = self.get_serializer(data=request.data)
serializer.is_valid()

user = User.objects.get(email=serializer.data["email"])

reset_email(user, request)

return Response(serializer.data, status=status.HTTP_201_CREATED)


class ResetCurrentUserPassword(UpdateAPIView):
serializer_class = PasswordSerializer
permission_classes = [AllowAny]

def get(self, request, *args, **kwargs):
refresh_token = request.GET.get("refresh_token")
try:
RefreshToken(refresh_token).check_blacklist()
except TokenError:
return redirect(
"https://procollab.ru/auth/reset_password/",
status=status.HTTP_400_BAD_REQUEST,
message="Used token",
)

return Response({"message": "Enter new password"})

def update(self, request, *args, **kwargs):
serializer = self.get_serializer(data=request.data)
serializer.is_valid()

try:
refresh_token = request.GET.get("refresh_token")
access_token = request.GET.get("access_token")

payload = jwt.decode(
jwt=access_token, key=settings.SECRET_KEY, algorithms=["HS256"]
)
user = User.objects.get(id=payload["user_id"])

# fixme
last_update = user.datetime_updated
frequency_update = datetime.utcnow().minute - last_update.minute
if frequency_update <= 10:
return redirect(
"https://procollab.ru/auth/reset_password/",
status=status.HTTP_400_BAD_REQUEST,
message="You can't change your password so often",
)

user.set_password(serializer.data["new_password"])
user.save()

RefreshToken(refresh_token).blacklist()
return redirect(
"https://app.procollab.ru/auth/reset_password/",
status=status.HTTP_200_OK,
message="Succeed",
)

except jwt.ExpiredSignatureError:
return redirect(
"https://app.procollab.ru/auth/reset_password/",
status=status.HTTP_400_BAD_REQUEST,
message="Activate Expired",
)
except jwt.DecodeError:
return redirect(
"https://app.procollab.ru/auth/reset_password/",
status=status.HTTP_400_BAD_REQUEST,
message="Decode error",
)


class AchievementList(ListCreateAPIView):
queryset = UserAchievement.objects.get_achievements_for_list_view()
serializer_class = AchievementListSerializer
Expand Down

0 comments on commit 7df0fcd

Please sign in to comment.