Exemplo n.º 1
0
 def get(self, request):
     token = request.GET.get('token')
     if not token:
         return http.HttpResponseBadRequest('缺少token')
     user = check_verify_email_token(token)
     if not user:
         return http.HttpResponseForbidden('无效的token')
     try:
         user.email_active = True
         user.save()
     except Exception as e:
         logger.error(e)
         return http.HttpResponseServerError('激活失败')
     return redirect(reverse('users:info'))
Exemplo n.º 2
0
 def get(self, request):
     # 接收参数
     token = request.GET.get('token')
     # 校验参数
     if not token:
         return http.HttpResponseForbidden('缺少token')
     # 从token中提取用户的信息 user_id ==> user
     user = check_verify_email_token(token)
     if not user:
         return http.HttpResponseBadRequest('无效的token')
     # 将用户的email_active字段设置为true
     try:
         user.email_active = True
         user.save()
     except Exception as e:
         logger.error(e)
         return http.HttpResponseServerError('激活邮件失败')
     # 响应结果  重定向到用户中心
     return redirect('users:info')
Exemplo n.º 3
0
    def get(self, request):
        """实现邮箱验证逻辑"""
        # 接收参数
        token = request.GET.get('token')

        # 校验参数:判断token是否为空和过期,提取user
        if not token:
            return http.HttpResponseBadRequest('缺少token')

        user = check_verify_email_token(token)
        if not user:
            return http.HttpResponseForbidden('无效的token')

        # 修改email_active的值为True
        try:
            user.email_active = True
            user.save()
        except Exception as e:
            logger.error(e)
            return http.HttpResponseServerError('激活邮件失败')

        # 返回邮箱验证结果
        return redirect(reverse('users:info'))