User should be logged in automatically after clicking email confirmation link #130

Closed
ghost opened this Issue Jun 9, 2014 · 8 comments

Comments

Projects
None yet
7 participants
@ghost

ghost commented Jun 9, 2014

Please add ability to auto login after email confirmation if user is not authenticated and email was confirmed well...

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Jun 18, 2014

@brosner , what do you think about this feature?.. Is any pitfalls there?...

ghost commented Jun 18, 2014

@brosner , what do you think about this feature?.. Is any pitfalls there?...

@avelis

This comment has been minimized.

Show comment
Hide comment

avelis commented Jun 30, 2014

👍

@mattions

This comment has been minimized.

Show comment
Hide comment
@mattions

mattions Jul 2, 2014

Contributor

+1 here as well. Got a bunch of user requesting why they have to log in twice

Contributor

mattions commented Jul 2, 2014

+1 here as well. Got a bunch of user requesting why they have to log in twice

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Jul 3, 2014

I did not tested it yet but this is my custom code:

def confirm_email_view(request, key):

    queryset = EmailConfirmation.objects.all()
    queryset = queryset.select_related("email_address__user")
    try:
        confirmation = queryset.get(key=key.lower())
    except EmailConfirmation.DoesNotExist:
        raise Http404()
    if not confirmation.key_expired() and not confirmation.email_address.verified:
        email_address = confirmation.email_address
        email_address.verified = True
        email_address.set_as_primary(conditional=True)
        email_address.save()
        signals.email_confirmed.send(sender=confirmation.__class__, email_address=email_address)
        user = email_address.user
        user.is_active = True
        user.save()
        if request.user.is_authenticated():
            redirect_url = reverse('user', args=[str(request.user.username)])
        else:
            user.backend = 'django.contrib.auth.backends.ModelBackend'
            login(request, user)
            redirect_url = reverse("post-register")
        messages.add_message(
            request,
            messages.SUCCESS,
            "Ты успешно подтвердил(-а) {email}.".format(**{"email": confirmation.email_address.email})
        )
    else:
        redirect_url = "/"
    return redirect(redirect_url)

ghost commented Jul 3, 2014

I did not tested it yet but this is my custom code:

def confirm_email_view(request, key):

    queryset = EmailConfirmation.objects.all()
    queryset = queryset.select_related("email_address__user")
    try:
        confirmation = queryset.get(key=key.lower())
    except EmailConfirmation.DoesNotExist:
        raise Http404()
    if not confirmation.key_expired() and not confirmation.email_address.verified:
        email_address = confirmation.email_address
        email_address.verified = True
        email_address.set_as_primary(conditional=True)
        email_address.save()
        signals.email_confirmed.send(sender=confirmation.__class__, email_address=email_address)
        user = email_address.user
        user.is_active = True
        user.save()
        if request.user.is_authenticated():
            redirect_url = reverse('user', args=[str(request.user.username)])
        else:
            user.backend = 'django.contrib.auth.backends.ModelBackend'
            login(request, user)
            redirect_url = reverse("post-register")
        messages.add_message(
            request,
            messages.SUCCESS,
            "Ты успешно подтвердил(-а) {email}.".format(**{"email": confirmation.email_address.email})
        )
    else:
        redirect_url = "/"
    return redirect(redirect_url)
@jtauber

This comment has been minimized.

Show comment
Hide comment
@jtauber

jtauber Jul 8, 2014

Member

👍 from me on the idea. @lorddaedra's code seems more complex than what is necessary.

Member

jtauber commented Jul 8, 2014

👍 from me on the idea. @lorddaedra's code seems more complex than what is necessary.

@paltman

This comment has been minimized.

Show comment
Hide comment
@paltman

paltman Jul 8, 2014

Member

+1

Member

paltman commented Jul 8, 2014

+1

@paltman paltman changed the title from Auto login after email confirmation if user is not authenticated to User should be logged in automatically after clicking email confirmation link Jul 8, 2014

@brosner brosner modified the milestones: 1.0, 1.1 Sep 18, 2014

@k4ml

This comment has been minimized.

Show comment
Hide comment
@k4ml

k4ml Sep 7, 2015

There should be a flag on this, since some people probably want to force user to login after verifying the email. Similar to django-allauth settings - ACCOUNT_LOGIN_ON_EMAIL_CONFIRMATION.

Pasting the notes from django-allauth here, just in case it also applied:-

ACCOUNT_LOGIN_ON_EMAIL_CONFIRMATION (=False)
The default behaviour is not log users in and to redirect them to ACCOUNT_EMAIL_CONFIRMATION_ANONYMOUS_REDIRECT_URL.

By changing this setting to True, users will automatically be logged in once they confirm their email address. Note however that this only works when confirming the email address immediately after signing up, assuming users didn’t close their browser or used some sort of private browsing mode.

http://django-allauth.readthedocs.org/en/latest/configuration.html

k4ml commented Sep 7, 2015

There should be a flag on this, since some people probably want to force user to login after verifying the email. Similar to django-allauth settings - ACCOUNT_LOGIN_ON_EMAIL_CONFIRMATION.

Pasting the notes from django-allauth here, just in case it also applied:-

ACCOUNT_LOGIN_ON_EMAIL_CONFIRMATION (=False)
The default behaviour is not log users in and to redirect them to ACCOUNT_EMAIL_CONFIRMATION_ANONYMOUS_REDIRECT_URL.

By changing this setting to True, users will automatically be logged in once they confirm their email address. Note however that this only works when confirming the email address immediately after signing up, assuming users didn’t close their browser or used some sort of private browsing mode.

http://django-allauth.readthedocs.org/en/latest/configuration.html

@stevenday stevenday referenced this issue in mysociety/mapit.mysociety.org Sep 24, 2015

Closed

Clicking the emailed confirmation link should confirm #10

@jtauber jtauber modified the milestone: 1.1 Sep 9, 2016

@brosner brosner added this to the 2.0.0 milestone Sep 9, 2016

@brosner brosner closed this in c6f6b5a Oct 18, 2016

@avelis

This comment has been minimized.

Show comment
Hide comment
@avelis

avelis Oct 18, 2016

🎉 @brosner Thanks for contributing this feature!

avelis commented Oct 18, 2016

🎉 @brosner Thanks for contributing this feature!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment