views.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:ava-website 作者: ava-project 项目源码 文件源码
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')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号