示例#1
0
 def get(self, request, uidb64, token, format=None):
     try:
         uid = force_text(urlsafe_base64_decode(uidb64))
         user = User.objects.get(pk=uid)
     except:
         user = None
     if user is not None and account_activation_token.check_token(
             user, token):
         user.is_active = True
         user.save()
         return Response(status=status.HTTP_200_OK)
     return Response(status=status.HTTP_400_BAD_REQUEST)
示例#2
0
def activate(request, uidb64, token):
    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(update_fields=['is_active'])
        # return redirect('home')
        return HttpResponse('Thank you for your email confirmation. Now you can login your account.')
    else:
        return HttpResponse('Activation link is invalid!')
示例#3
0
    def get(self, request, uidb64, token):
        form = NewPassword()
        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):

            return render(request, 'newpasswordcreate.html', {'form': form})
        else:
            return render(request, 'account_activation_invalid.html')
示例#4
0
def activate(request, uidb64, token):
    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)
        return render(request, 'index.html')
    else:
        return render(request, 'account_activation_invalid.html')
示例#5
0
def set_new_password(request, uidb64, token, password: str = Form(...), confirm_password: str = Form(...)):
    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):
        if(password==confirm_password):
            user.set_password(password)
            user.save(update_fields=['password'])
        else:
            return HttpResponse('Passwords are not same.')
        # return redirect('home')
        return HttpResponse('Your password has been set. Now you can login your account.')
    else:
        return HttpResponse('Link is invalid!')
示例#6
0
    def get(self, request, uidb64, token):
        try:
            uid = force_text(urlsafe_base64_decode(uidb64.encode("utf-8")))
            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()
            # send welcome email to user
            # site_name = get_current_site(self.request)
            # todo: change hard code subject
            subject = 'Getting started with {0}'.format(settings.SITE_TITLE)
            message = render_to_string(
                'app/account_activated_email.html', {
                    'current_date':
                    datetime.datetime.now().strftime('%Y-%m-%d'),
                    'site_title': settings.SITE_TITLE,
                    'user': user,
                })
            # send activation link to the user
            bccs = AdminEmail.objects.all()
            send_bcc = []
            for bcc in bccs:
                send_bcc.append(bcc.email)
            # bcc is not working
            print("   send_bcc ===========   " * 4)
            print(send_bcc)
            # user.email_user(subject, message, None, send_bcc)
            msg = EmailMessage(subject, message, None, [user.email], send_bcc)
            msg.send()

            login(request, user)
            # add membership only
            # profile = user.profile
            # if profile.day_to_live <= 0:
            membership_type, created = MembershipType.objects.get_or_create(
                name='Free')
            membership_add_subscription(user, membership_type, True)

            #    membership.membership_type.add(membership_type)
            #    profile.day_to_live = membership_type.day_to_live

            return HttpResponseRedirect(reverse('accounts'))
        else:
            return render(request, self.template_name)
示例#7
0
def activate(request, uidb64, token):
    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):
        # Activate user account
        user.is_active = True
        user.email_confirmed = True
        user.save()
        login(request, user, backend='django.contrib.auth.backends.ModelBackend')
        # Redirect valid user to his/her profile
        return redirect('/profile/?redirect=activated')
    else:
        # Show error otherwise
        return render(request, 'email/account_activation_invalid.html')
示例#8
0
    def get(self, request, uidb64, token):
        try:
            uid = force_text(urlsafe_base64_decode(uidb64.encode("utf-8")))
            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)
            ## add membership only
            # profile = user.profile
            # if profile.day_to_live <= 0:
            membership_type, created = MembershipType.objects.get_or_create(name='Free')
            membership_add_subscription(user, membership_type, True)

            #    membership.membership_type.add(membership_type)
            #    profile.day_to_live = membership_type.day_to_live

            return HttpResponseRedirect(reverse('accounts'))
        else:
            return render(request, self.template_name)