Skip to content

Commit

Permalink
Merge pull request #19 from FeloxleF/felix-calendrier
Browse files Browse the repository at this point in the history
Felix calendrier
FeloxleF authored Apr 11, 2024
2 parents f23c9db + e255855 commit 3f96d72
Showing 11 changed files with 621 additions and 256 deletions.
Binary file modified activmindback/activmind_backup_file.sql
Binary file not shown.
3 changes: 2 additions & 1 deletion activmindback/users/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.urls import path
from rest_framework_nested import routers
# from .views import register_user, login_user, update_password, RegisterUser
from .views import AssociateUserViewSet, RegisterUserViewSet, AuthViewSet, check_token, get_csrf_token
from .views import AssociateUserViewSet, RegisterUserViewSet, AuthViewSet, check_token, get_csrf_token, forgot_password


router = routers.DefaultRouter()
@@ -15,5 +15,6 @@
urlpatterns = urlpatterns + [
path('check_token/', check_token, name='check_token'),
path('csrf_token/', get_csrf_token, name='csrf_token'),
path('forgot_password/', forgot_password, name='forgot_password'),

]
20 changes: 20 additions & 0 deletions activmindback/users/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import re
from django.forms import ValidationError
from rest_framework import status
from rest_framework.response import Response
@@ -90,6 +91,25 @@ def get_csrf_token(request):
return JsonResponse({'csrfToken': token})


@api_view(['POST'])
def forgot_password(request):
email = request.data.get('email')
new_password = request.data.get('password')
if not email:
return JsonResponse({'error': 'Email and password required'}, status=400)
if not User.objects.filter(email=email).exists():
return JsonResponse({'error': 'No user found with this email'}, status=400)
else :
user = User.objects.filter(email=email).first()
regex = r"^[^\s]{8,}$"
password_regex = re.compile(regex)
if re.match(password_regex, new_password) is None:
return JsonResponse({'error': 'Password must be at least 8 characters long'}, status=400)
user.set_password(new_password)
user.save()
return JsonResponse({'message': 'Password reset successfully'}, status=200)


# API endpoints to associate and dissociate users

class AssociateUserViewSet(viewsets.ViewSet):
Loading

0 comments on commit 3f96d72

Please sign in to comment.