示例#1
0
def activate_user(request, uidb64, token, activation_key): # pragma: no cover
    profile = get_object_or_404(Profile, activation_key=activation_key)
    if profile.user:
        if timezone.now() > profile.key_expires:
            resend_url = reverse('common:resend_activation_link', args=(profile.user.id,))
            link_content = '<a href="{}">Click Here</a> to resend the activation link.'.format(
                resend_url)
            message_content = 'Your activation link has expired, {}'.format(
                link_content)
            messages.info(request, message_content)
            return render(request, 'login.html')
        else:
            try:
                uid = force_text(urlsafe_base64_decode(uidb64))
                user = User.objects.get(pk=uid)
            except(TypeError, ValueError, OverflowError, User.DoesNotExist):
                user = None
            if user is not None and account_activation_token.check_token(user, token):
                user.is_active = True
                user.save()
                login(request, user)
                if user.has_sales_access:
                    return HttpResponseRedirect('/')
                elif user.has_marketing_access:
                    return redirect('marketing:dashboard')
                else:
                    return HttpResponseRedirect('/')
                # return HttpResponse('Thank you for your email confirmation. Now you can login your account.')
            else:
                return HttpResponse('Activation link is invalid!')
示例#2
0
 def post(self, request, uid, token, activation_key, format=None):
     profile = get_object_or_404(Profile, activation_key=activation_key)
     if profile.user:
         if timezone.now() > profile.key_expires:
             protocol = request.scheme
             resend_activation_link_to_user.delay(
                 profile.user.email,
                 domain=settings.Domain,
                 protocol=protocol,
             )
             return Response(
                 {
                     "error":
                     False,
                     "message":
                     "Link expired. Please use the Activation link sent now to your mail.",
                 },
                 status=status.HTTP_406_NOT_ACCEPTABLE,
             )
         else:
             try:
                 uid = force_text(urlsafe_base64_decode(uid))
                 user = User.objects.get(pk=uid)
             except (TypeError, ValueError, OverflowError,
                     User.DoesNotExist):
                 user = None
             if user is not None and account_activation_token.check_token(
                     user, token):
                 user.is_active = True
                 user.save()
                 return Response(
                     {
                         "error":
                         False,
                         "message":
                         "Thank you for your email confirmation. Now you can login to your account.",
                     },
                     status=status.HTTP_200_OK,
                 )
             else:
                 return Response(
                     {
                         "error": True,
                         "errors": "Activation link is invalid!"
                     },
                     status=status.HTTP_400_BAD_REQUEST,
                 )