mirror of
https://github.com/Tivix/django-rest-auth.git
synced 2025-07-26 23:49:46 +03:00
corrections for used in angular 5
This commit is contained in:
parent
a3057b7aa1
commit
13060f0685
|
@ -1,4 +1,6 @@
|
||||||
|
from django.conf import settings
|
||||||
from django.http import HttpRequest
|
from django.http import HttpRequest
|
||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
|
|
||||||
|
@ -17,6 +19,10 @@ except ImportError:
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from requests.exceptions import HTTPError
|
from requests.exceptions import HTTPError
|
||||||
|
|
||||||
|
if not hasattr(settings, 'ACCOUNT_FIRST_NAME_REQUIRED'):
|
||||||
|
settings.ACCOUNT_FIRST_NAME_REQUIRED = False
|
||||||
|
if not hasattr(settings, 'ACCOUNT_LAST_NAME_REQUIRED'):
|
||||||
|
settings.ACCOUNT_LAST_NAME_REQUIRED = False
|
||||||
|
|
||||||
class SocialAccountSerializer(serializers.ModelSerializer):
|
class SocialAccountSerializer(serializers.ModelSerializer):
|
||||||
"""
|
"""
|
||||||
|
@ -169,6 +175,8 @@ class RegisterSerializer(serializers.Serializer):
|
||||||
min_length=allauth_settings.USERNAME_MIN_LENGTH,
|
min_length=allauth_settings.USERNAME_MIN_LENGTH,
|
||||||
required=allauth_settings.USERNAME_REQUIRED
|
required=allauth_settings.USERNAME_REQUIRED
|
||||||
)
|
)
|
||||||
|
first_name = serializers.CharField(required=settings.ACCOUNT_FIRST_NAME_REQUIRED, max_length=30)
|
||||||
|
last_name = serializers.CharField(required=settings.ACCOUNT_LAST_NAME_REQUIRED, max_length=30)
|
||||||
email = serializers.EmailField(required=allauth_settings.EMAIL_REQUIRED)
|
email = serializers.EmailField(required=allauth_settings.EMAIL_REQUIRED)
|
||||||
password1 = serializers.CharField(write_only=True)
|
password1 = serializers.CharField(write_only=True)
|
||||||
password2 = serializers.CharField(write_only=True)
|
password2 = serializers.CharField(write_only=True)
|
||||||
|
@ -198,6 +206,8 @@ class RegisterSerializer(serializers.Serializer):
|
||||||
|
|
||||||
def get_cleaned_data(self):
|
def get_cleaned_data(self):
|
||||||
return {
|
return {
|
||||||
|
'first_name': self.validated_data.get('first_name', ''),
|
||||||
|
'last_name': self.validated_data.get('last_name', ''),
|
||||||
'username': self.validated_data.get('username', ''),
|
'username': self.validated_data.get('username', ''),
|
||||||
'password1': self.validated_data.get('password1', ''),
|
'password1': self.validated_data.get('password1', ''),
|
||||||
'email': self.validated_data.get('email', '')
|
'email': self.validated_data.get('email', '')
|
||||||
|
|
|
@ -3,6 +3,16 @@ from django.conf.urls import url
|
||||||
|
|
||||||
from .views import RegisterView, VerifyEmailView
|
from .views import RegisterView, VerifyEmailView
|
||||||
|
|
||||||
|
|
||||||
|
from django.contrib.sites.shortcuts import get_current_site
|
||||||
|
from django.views.generic.base import RedirectView
|
||||||
|
class ConfirmEmailRedirectView(RedirectView):
|
||||||
|
permanent = False
|
||||||
|
def get_redirect_url(self, *args, **kwargs):
|
||||||
|
current_site = get_current_site(self.request)
|
||||||
|
self.url = '%s://%s/auth/confirm-email/%s' % (self.request.scheme,current_site.domain, kwargs["key"])
|
||||||
|
return super().get_redirect_url(*args, **kwargs)
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^$', RegisterView.as_view(), name='rest_register'),
|
url(r'^$', RegisterView.as_view(), name='rest_register'),
|
||||||
url(r'^verify-email/$', VerifyEmailView.as_view(), name='rest_verify_email'),
|
url(r'^verify-email/$', VerifyEmailView.as_view(), name='rest_verify_email'),
|
||||||
|
@ -18,6 +28,5 @@ urlpatterns = [
|
||||||
# If you don't want to use API on that step, then just use ConfirmEmailView
|
# If you don't want to use API on that step, then just use ConfirmEmailView
|
||||||
# view from:
|
# view from:
|
||||||
# django-allauth https://github.com/pennersr/django-allauth/blob/master/allauth/account/views.py
|
# django-allauth https://github.com/pennersr/django-allauth/blob/master/allauth/account/views.py
|
||||||
url(r'^account-confirm-email/(?P<key>[-:\w]+)/$', TemplateView.as_view(),
|
url(r'^account-confirm-email/(?P<key>[-:\w]+)/$', ConfirmEmailRedirectView.as_view(),name='account_confirm_email'),
|
||||||
name='account_confirm_email'),
|
|
||||||
]
|
]
|
||||||
|
|
|
@ -26,6 +26,12 @@ class LoginSerializer(serializers.Serializer):
|
||||||
|
|
||||||
if email and password:
|
if email and password:
|
||||||
user = authenticate(email=email, password=password)
|
user = authenticate(email=email, password=password)
|
||||||
|
try:
|
||||||
|
username = UserModel.objects.get(email__iexact=email).get_username()
|
||||||
|
user = authenticate(username=username, password=password)
|
||||||
|
except UserModel.DoesNotExist:
|
||||||
|
msg = _('Unable to log in with provided credentials.')
|
||||||
|
raise exceptions.ValidationError(msg)
|
||||||
else:
|
else:
|
||||||
msg = _('Must include "email" and "password".')
|
msg = _('Must include "email" and "password".')
|
||||||
raise exceptions.ValidationError(msg)
|
raise exceptions.ValidationError(msg)
|
||||||
|
@ -48,6 +54,12 @@ class LoginSerializer(serializers.Serializer):
|
||||||
|
|
||||||
if email and password:
|
if email and password:
|
||||||
user = authenticate(email=email, password=password)
|
user = authenticate(email=email, password=password)
|
||||||
|
try:
|
||||||
|
username = UserModel.objects.get(email__iexact=email).get_username()
|
||||||
|
user = authenticate(username=username, password=password)
|
||||||
|
except UserModel.DoesNotExist:
|
||||||
|
msg = _('Unable to log in with provided credentials.')
|
||||||
|
raise exceptions.ValidationError(msg)
|
||||||
elif username and password:
|
elif username and password:
|
||||||
user = authenticate(username=username, password=password)
|
user = authenticate(username=username, password=password)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -5,6 +5,14 @@ from rest_auth.views import (
|
||||||
PasswordResetView, PasswordResetConfirmView
|
PasswordResetView, PasswordResetConfirmView
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from rest_framework import status
|
||||||
|
from rest_framework.decorators import api_view
|
||||||
|
from rest_framework.response import Response
|
||||||
|
|
||||||
|
@api_view()
|
||||||
|
def null_view(request):
|
||||||
|
return Response(status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
# URLs that do not require a session or valid token
|
# URLs that do not require a session or valid token
|
||||||
url(r'^password/reset/$', PasswordResetView.as_view(),
|
url(r'^password/reset/$', PasswordResetView.as_view(),
|
||||||
|
@ -17,4 +25,5 @@ urlpatterns = [
|
||||||
url(r'^user/$', UserDetailsView.as_view(), name='rest_user_details'),
|
url(r'^user/$', UserDetailsView.as_view(), name='rest_user_details'),
|
||||||
url(r'^password/change/$', PasswordChangeView.as_view(),
|
url(r'^password/change/$', PasswordChangeView.as_view(),
|
||||||
name='rest_password_change'),
|
name='rest_password_change'),
|
||||||
|
url(r'^new-password/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', null_view ,name='password_reset_confirm'),
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user