Code Monkey home page Code Monkey logo

Comments (3)

clokep avatar clokep commented on July 20, 2024 1

Depending on what version you're using (...I probably need to do a release soon...) you can check how the access mixin does it:

https://github.com/percipient/django-allauth-2fa/blob/27f6c4cb5a1cf173d01d34ae28b75a77a96512dd/allauth_2fa/mixins.py#L8-L19

Essentially it just checks whether there are any valid 2FA tokens (and then assumes they were used to login):

https://github.com/percipient/django-allauth-2fa/blob/27f6c4cb5a1cf173d01d34ae28b75a77a96512dd/allauth_2fa/utils.py#L44-L46

from django-allauth-2fa.

maxclax avatar maxclax commented on July 20, 2024

Depending on what version you're using (...I probably need to do a release soon...) you can check how the access mixin does it:

django-allauth-2fa/allauth_2fa/mixins.py

Lines 8 to 19 in 27f6c4c
class ValidTOTPDeviceRequiredMixin(AccessMixin):
no_valid_totp_device_url = reverse_lazy('two-factor-setup')

 def dispatch(self, request, *args, **kwargs): 
     if not request.user.is_authenticated: 
         return self.handle_no_permission() 
     if not user_has_valid_totp_device(request.user): 
         return self.handle_missing_totp_device() 
     return super(ValidTOTPDeviceRequiredMixin, self).dispatch(request, *args, **kwargs) 

 def handle_missing_totp_device(self): 
     return HttpResponseRedirect(self.no_valid_totp_device_url) 

Essentially it just checks whether there are any valid 2FA tokens (and then assumes they were used to login):

django-allauth-2fa/allauth_2fa/utils.py

Lines 44 to 46 in 27f6c4c
if not user.is_authenticated:
return False
return user.totpdevice_set.filter(confirmed=True).exists()

Thanks I added in user model this code
def check_2fa(self): return self.totpdevice_set.filter(confirmed=True).exists()

from django-allauth-2fa.

clokep avatar clokep commented on July 20, 2024

Glad you got it working. I'm going to close this!

from django-allauth-2fa.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.