def get(self, request, **kwargs):
"""
Validate account from link sent by email.
This endpoint tests if the token is in the database and
if it's not expired, correspond to the correct user and
if it's not consumed yet, then the user account will be
validate after that.
"""
try:
token = EmailValidationToken.objects.get(token=request.GET['token'])
if not token.is_valid(request.GET['email']):
raise ValueError('invalid token')
token.consume()
if not request.user.is_authenticated:
self.login_user(token.user)
messages.success(request, 'Email validated')
return redirect('main:index')
except (EmailValidationToken.DoesNotExist, ValueError) as e:
print(e)
return HttpResponseBadRequest('Something went wrong with your token, please try again')
评论列表
文章目录