django-allauth: how to properly use email_confirmed signal to set user to active

前端 未结 2 945
予麋鹿
予麋鹿 2020-12-14 11:46

In another post, I mentioned that I was trying to use allauth\'s email_confirmed signal to change the is_active field on the confirmed user to true. However, the following c

2条回答
  •  一整个雨季
    2020-12-14 12:04

    Turns out the email_address returned by the email_confirmed signal isn't actually a string containing the address, but an object -- allauth.account.models.EmailAddress. This wasn't very clear at all from the documentation, but glad it's resolved now. The code that ended up working was:

    @receiver(email_confirmed)
    def email_confirmed_(request, email_address, **kwargs):
    
        user = User.objects.get(email=email_address.email)
        user.is_active = True
    
        user.save()
    

提交回复
热议问题