You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When editing sensitive parts of a website (e.g., changing membership or billing info), it is common to ask the user to login again if they haven't logged in recently. I figured something like what follows would be useful. I got this to work, but I'm a django / python noob, so I'm not sure if this is going to work in many versions of django.
class RecentLoginRequiredMixin(LoginRequiredMixin):
# Maximum time delta since last login in seconds
max_last_login_delta = 1800 # default is 30 mins
def dispatch(self, request, *args, **kwargs):
user = request.user
if user.is_authenticated():
delta = datetime.timedelta(seconds=self.max_last_login_delta)
now = timezone.now() if settings.USE_TZ else datetime.datetime.now()
if now > (user.last_login + delta):
logout_then_login(request)
return super(RecentLoginRequiredMixin, self).dispatch(
request, *args, **kwargs)
The text was updated successfully, but these errors were encountered:
When editing sensitive parts of a website (e.g., changing membership or billing info), it is common to ask the user to login again if they haven't logged in recently. I figured something like what follows would be useful. I got this to work, but I'm a django / python noob, so I'm not sure if this is going to work in many versions of django.
The text was updated successfully, but these errors were encountered: