Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The new user receives a verify email - but when the [verify] link gets clicked it's response is a verification failed page : Invalid Link #49

Closed
ralixit opened this issue Apr 16, 2022 · 7 comments

Comments

@ralixit
Copy link

ralixit commented Apr 16, 2022

Hello when I signup with a new user - The new user receives a verify email - but when the [verify] link gets clicked it's response is a verification failed page : Invalid Link
This link is invalid or been used already, we cannot verify using this link.

http://127.0.0.1:8000/verification/user/verify-email/Ym9hcmRtZW1iZXJAdGllcnJhc2t5LmNvbQ==/YjN5MWRkLWEyMTJkMjY5YzE3OWI3YTgwOWEwMDI1M2E0YjA5NjUz/

This link seems to be missing the -useremail- in -path(f'user/verify-email/-useremail-/-usertoken-/'-

I'm not sure if my custom Member is the issue in regards to :email = models.EmailField(_('email address'), unique=True)

class Member(AbstractBaseUser, PermissionsMixin):

    # INITIAL MEMBER BASIC INFORMATION (05) #
    first_name = models.CharField(_('first name'), max_length=150, blank=True)
    last_name = models.CharField(_('last name'), max_length=150, blank=True)
    phone = models.CharField(_('phone'), max_length=150, blank=True)
    email = models.EmailField(_('email address'), unique=True)
@bgorman87
Copy link

Had this issue. Just looks like url is processing "useremail" but view is looking for "user_email". Worked for me once I made them consistent.

@foo290
Copy link
Owner

foo290 commented Apr 18, 2022

Had this issue. Just looks like url is processing "useremail" but view is looking for "user_email". Worked for me once I made them consistent.

[FIXED]: Nice catch, That's a bug! but that's in resending email.

@xAli-1
Copy link

xAli-1 commented May 26, 2022

Hi
can you help me out #53

@bgorman87
@foo290

@mboboc
Copy link

mboboc commented Jul 17, 2022

I also have this problem. Any suggestions?

@foo290
Copy link
Owner

foo290 commented Jul 17, 2022

Did you check #53 if the solution is the same?

@DedRozs
Copy link

DedRozs commented Oct 26, 2022

I'm also having this issue, I think that I may be having this problem because of my user registration form.

class SignUpForm(UserCreationForm):
username = forms.EmailField(
widget=forms.EmailInput(
attrs={
"placeholder": "Email",
"class": "form-control"
}
))

I tried changing the make token function in the token.py file in site-packages to the following:

def make_token(self, user, expiry, **kwargs):
    """
    Return a token that can be used once to do a password reset
    for the given user.
    Args:
        user (Model): the user
        expiry (datetime | int): optional forced expiry date
        kwargs: extra payload for the token
    Returns:
         (tuple): tuple containing:
            token (str): the token
            expiry (datetime): the expiry datetime
    """
    exp = int(expiry.timestamp()) if isinstance(expiry, datetime) else expiry
    payload = {'email': user.username, 'exp': exp} #Changed email to contain the value of the username
    payload.update(**kwargs)
    return jwt.encode(payload, self.secret, algorithm='HS256'), datetime.fromtimestamp(exp)

Still no luck.

Views.py:

def register_user(request):
msg = None
success = False
if request.method == "POST":
form = SignUpForm(request.POST)
profile_form = UserProfileForm(request.POST,)
if form.is_valid() and profile_form.is_valid():
inactive_user = send_verification_email(request, form)
profile = profile_form.save(commit=False)
if profile.user_id is None:
profile.user_id = inactive_user.id
profile.save()
msg = 'User created - please check your email to activate your account'
success = True
# return redirect("/login/")
else:
msg = 'Form is not valid'
else:
form = SignUpForm()
profile_form = UserProfileForm()
return render(request, "accounts/register.html", {"form": form, "msg": msg, "success": success, 'profile_form':profile_form})

@mortazaamer20
Copy link

you only need to add inactive_user.is_active=False
after inactive_user = send_verification_email(request, form)

@foo290 foo290 closed this as completed Jul 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants