LeoneBacciu / django-email-verification

A Django app that takes care of verifying a users's email address and activating their profile.
MIT License
353 stars 57 forks source link

Empty link #56

Closed dima23113 closed 2 years ago

dima23113 commented 2 years ago

Hey! Why is the link empty?

views.py ` class UserRegisterView(View):

def get(self, request, *args, **kwargs):
    if request.user.is_authenticated:
        return redirect('shop:index')
    else:
        form = UserRegisterForm()
        return render(request, 'account/register.html', context={'form': form})

def post(self, request, *args, **kwargs):
    form = UserRegisterForm(request.POST)
    if form.is_valid():
        cd = form.cleaned_data
        if cd['password'] != cd['confirm_password']:
            messages.error(request, 'Пароли не совпадают!')
            return redirect('account:register')
        elif CustomUser.objects.filter(email=cd['email']).exists():
            messages.error(request, 'Пользователь с таким email существует!')
            return redirect('account:register')
        else:
            user = CustomUser.objects.create_user(email=cd['email'], password=cd['password'])
            user.is_active = False
            send_email(user)
            messages.add_message(request, messages.INFO,
                                 'Вам на почту отправлено письмо с подтвержением регистрациии!')
            return redirect('shop:index')

`

I get this msg

<h1>You are almost there, namedima28@gmail.com!</h1><br>
<h2>Please click <a href="">here</a> to confirm your account</h2>
<h2>The token expires on 19:47</h2>
LeoneBacciu commented 2 years ago

Hello 👋. Which version are you using? Also do you see anything particular in the logs?

dima23113 commented 2 years ago

I use django 4.0 and python 3.9

Hello, the log is below. In general, something is wrong in the line of code if k is verify and v[0][0][1][0]: because I don't get anything from there

def send_email(user, thread=True, **kwargs):
    try:
        user.save()

        if kwargs.get('custom_salt'):
            default_token_generator.key_salt = kwargs['custom_salt']

        expiry_ = kwargs.get('expiry')
        token, expiry = default_token_generator.make_token(user, expiry_)

        print(token)  # it' ok

        sender = _get_validated_field('EMAIL_FROM_ADDRESS')
        domain = _get_validated_field('EMAIL_PAGE_DOMAIN')
        subject = _get_validated_field('EMAIL_MAIL_SUBJECT')
        mail_plain = _get_validated_field('EMAIL_MAIL_PLAIN')
        mail_html = _get_validated_field('EMAIL_MAIL_HTML')

        args = (user, token, expiry, sender, domain, subject, mail_plain, mail_html)
        print(args)  # it' ok
        if thread:
            t = Thread(target=send_email_thread, args=args)
            print(t)  # it' ok
            t.start()
        else:
            send_email_thread(*args)
            print(send_email_thread)  # it' ok
    except AttributeError:
        print('hi')  # it' ok
        raise InvalidUserModel('The user model you provided is invalid')
def send_email_thread(user, token, expiry, sender, domain, subject, mail_plain, mail_html):
    domain += '/' if not domain.endswith('/') else ''
    print(domain)  # it' ok
    from .views import verify
    link = ''
    print(get_resolver(None).reverse_dict.items())  # it' ok
    for k, v in get_resolver(None).reverse_dict.items():
        print(k, v)  # nothing
        if k is verify and v[0][0][1][0]:
            print(v[0][0][1][0])  # nothing
            addr = str(v[0][0][0])
            print(addr)  # nothing
            link = domain + addr[0: addr.index('%')] + token
            print(link)  # nothing
        else:
            print('not verify')  # else doesn't work, then it's ok?
    context = {'link': link, 'expiry': expiry, 'user': user}
    print(context)  #  everything except  link`

bmFtZWRpbWFhMTNAZ21haWwuY29t-azbl9s-f774f2c2a2f6297fa5428fc27a066f6a972e3671 - token (<CustomUser: namedimaa13@gmail.com>, 'bmFtZWRpbWFhMTNAZ21haWwuY29t-azbl9s-f774f2c2a2f6297fa5428fc27a066f6a972e3671', datetime.datetime(1991, 1, 16, 5, 25, 4), 'noreply@aliasaddress.com', 'http://127.0.0.1:8000/', 'Confirm your email', 'mail_body.txt', 'mail_body.html') - args <Thread(Thread-2, initial daemon)> - Thread method http://127.0.0.1:8000/ -domain <generator object MultiValueDict.items at 0x000001BDC3182B30> - get_resolver(None).reverse_dict.items() {'link': '', 'expiry': datetime.datetime(1991, 1, 16, 5, 25, 4), 'user': <CustomUser: namedimaa13@gmail.com>} - context

dima23113 commented 2 years ago

I tried to install version 3.2 and it did not solve the problem

LeoneBacciu commented 2 years ago

Try installing version 0.1.1rc1 of this library. Also have you included the library urls in your urls.py?

dima23113 commented 2 years ago

It works! Thank you very much :3