Auto Backup & Resend Email

I have django registration and work. I would like to add two additional functions to it, and it’s hard for me to understand the internal workings of the login process.

1) When the user clicks on the activation email address, he activates the account, but does not register the user, how would I do to click on the activation link and make the account active and automatically register the user? Currently it looks like my activate function -

 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 make this work using sessions. Of course, this is not an 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 so that the user can click the button to receive another activation email (if he does not receive the first one). It looks like activation email is sent upon registration -

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

How do I send another activation email address if a user account has already been created?

+6
source share
1 answer

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 .

+14
source

Source: https://habr.com/ru/post/889668/


All Articles