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

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

Closed
ghost opened this issue Jun 9, 2014 · 8 comments
Closed
Labels
Milestone

Comments

@ghost
Copy link

@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
Copy link
Author

@ghost ghost commented Jun 18, 2014

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

@avelis
Copy link

@avelis avelis commented Jun 30, 2014

👍

@mattions
Copy link
Contributor

@mattions mattions commented Jul 2, 2014

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

@ghost
Copy link
Author

@ghost 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
Copy link
Member

@jtauber jtauber commented Jul 8, 2014

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

@paltman
Copy link
Member

@paltman paltman commented Jul 8, 2014

+1

@paltman paltman changed the title Auto login after email confirmation if user is not authenticated 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
Copy link

@k4ml 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

@avelis
Copy link

@avelis 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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
7 participants
You can’t perform that action at this time.