You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How can I add some custom verification at the time of login? What I want to do is to send an email at the time of user registration and if the user verifies the email then only he can log in. For eg in Django auth, we can achieve like -
user = authenticate(request, email=email, password=password)
if user is not None:
if user.email_verification:
login(request, user)
return JsonResponse({"status":"success", "message":"login success"})
else:
return JsonResponse({"status":"fail", "message":"verify email"})
in django-rest-framework-simplejwt user directly gets login by calling url- path('login', jwt_views.TokenObtainPairView.as_view(), name='token_obtain_pair'),
How can I achieve email verification status check?
The text was updated successfully, but these errors were encountered:
Hi @amity29, not sure if this is still an issue for you, but if you are using the TokenObtainPairSerializer, then you could override the validate method there and add a check for the user's verification status like in this snippet below:
class UserLoginSerializer(TokenObtainPairSerializer):
def validate(self, attrs):
data = super().validate(attrs)
# do your extra validation here
username_field = get_user_model().USERNAME_FIELD
username = attrs[username_field]
user = get_user_model().objects.get(**{username_field: username]})
if not user.email_verification:
raise exceptions.AuthenticationFailed({"status":"fail", "message":"verify email"})
login(request, user)
return data
I would do something like this, but there are probably better ways too. Hope this helps
How can I add some custom verification at the time of login? What I want to do is to send an email at the time of user registration and if the user verifies the email then only he can log in. For eg in Django auth, we can achieve like -
in django-rest-framework-simplejwt user directly gets login by calling url-
path('login', jwt_views.TokenObtainPairView.as_view(), name='token_obtain_pair'),
How can I achieve email verification status check?
The text was updated successfully, but these errors were encountered: