Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto log-in and re-send email

I have a django-registration up and working. I would like to add two additional features to it and am having a bit of difficulty understanding the inner-workings of the log-in process.

1) When a user clicks the activation email, it makes the account active but does not log the user in, how would I make it so clicking the activation link both makes the account active and automatically logs in the user? This is currently what my activate function looks like --

def activate(self, request, activation_key):
    activated = RegistrationProfile.objects.activate_user(activation_key)
    if activated:
        signals.user_activated.send(sender=self.__class__,
                                    user=activated,
                                    request=request)
        login (request, activated) ### if I try this line, it throws an error 'User'        
                                   ### object has no attribute 'backend
    return activated

update: I was able to add a hack to get this working, using sessions. Surely it's not the ideal solution, but here is what I have --

def register(self, request, **kwargs):
    ...        
    new_user.save()
    request.session['username'] = username
    request.session['password'] = password
    return new_user

def activate(self, request, activation_key):
    username = request.session['username']
    password = request.session['password']
    activated = RegistrationProfile.objects.activate_user(activation_key)
    if activated:
        signals.user_activated.send(sender=self.__class__,
                                    user=activated,
                                    request=request)
        user = authenticate(username=username, password=password)
        login(request, user)
    return activated

2) I would like to add an option for a user to be able to click a button to receive another activation email (should he fail to receive the first). It seems the following is where the activation email is sent upon registration --

  signals.user_registered.send(sender=self.__class__,
                                 user=new_user,
                                 request=request)

How would I send another activation email given the user account has already been created?

like image 711
David542 Avatar asked Jun 03 '11 03:06

David542


People also ask

How do I automatically resend an email in Outlook?

Select Mail > Forwarding. Select Enable forwarding, enter the forwarding email address, and select Save. Notes: If you want a copy of the original message to remain in your mailbox, select Keep a copy of forwarded messages.

What is auto resend?

The auto resend campaign will automatically send another email to your subscribers if they have not opened the first email, or if they have not clicked a link in your first email.


1 Answers

1).

from django.contrib.auth import login
from registration import signals

def login_on_activation(user, request, **kwargs):
    user.backend='django.contrib.auth.backends.ModelBackend'
    login(request, user)

signals.user_activated.connect(login_on_activation)

2). registration.models.RegistrationProfile.send_activation_email method.

like image 189
DrTyrsa Avatar answered Oct 16 '22 19:10

DrTyrsa