Django-Verify-Email icon indicating copy to clipboard operation
Django-Verify-Email copied to clipboard

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

Open ralixit opened this issue 3 years ago • 5 comments

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)

ralixit avatar Apr 16 '22 02:04 ralixit

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.

bgorman87 avatar Apr 18 '22 10:04 bgorman87

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.

knownbug06 avatar Apr 18 '22 14:04 knownbug06

Hi can you help me out #53

@bgorman87 @foo290

xAli-1 avatar May 26 '22 07:05 xAli-1

I also have this problem. Any suggestions?

mboboc avatar Jul 17 '22 16:07 mboboc

Did you check https://github.com/foo290/Django-Verify-Email/issues/53 if the solution is the same?

knownbug06 avatar Jul 17 '22 17:07 knownbug06

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})

DedRozs avatar Oct 26 '22 19:10 DedRozs

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

mortazaamer20 avatar Jun 06 '23 11:06 mortazaamer20