jazzband / django-two-factor-auth

Complete Two-Factor Authentication for Django providing the easiest integration into most Django projects.
MIT License
1.71k stars 448 forks source link

get_action in EmailMethod raise AttributeError if device has not email value #530

Closed EngFarisAlsmawi closed 2 years ago

EngFarisAlsmawi commented 2 years ago

https://github.com/jazzband/django-two-factor-auth/blob/fe6c940d93a254dd7d2623c3a4752f69ea6ac1db/two_factor/plugins/email/method.py#L40

A method masked_email will be raise AttributeError when invoke get_action method, If you create device instance without email . AttributeError at /account/two_factor/ 'NoneType' object has no attribute 'split'

This is fields is optional , so that you can used user email field as alternative if device email field is null.

claudep commented 2 years ago

Yes, we should do like https://github.com/django-otp/django-otp/blob/master/src/django_otp/plugins/otp_email/models.py#L70, (device.email or device.user.email). Would you like to provide a patch, with a regression test?