jumpserver/apps/authentication/views/mfa.py

32 lines
899 B
Python
Raw Normal View History

2019-11-05 10:46:29 +00:00
# -*- coding: utf-8 -*-
#
from __future__ import unicode_literals
from django.views.generic.edit import FormView
from .. import forms, errors, mixins
from .utils import redirect_to_guard_view
2020-04-20 02:44:45 +00:00
from common.utils import get_logger
logger = get_logger(__name__)
2019-11-05 10:46:29 +00:00
__all__ = ['UserLoginOtpView']
class UserLoginOtpView(mixins.AuthMixin, FormView):
template_name = 'authentication/login_otp.html'
form_class = forms.UserCheckOtpCodeForm
redirect_field_name = 'next'
def form_valid(self, form):
otp_code = form.cleaned_data.get('otp_code')
try:
self.check_user_mfa(otp_code)
return redirect_to_guard_view()
except errors.MFAFailedError as e:
2019-11-18 10:12:03 +00:00
form.add_error('otp_code', e.msg)
2019-11-05 10:46:29 +00:00
return super().form_invalid(form)
2020-04-20 02:44:45 +00:00
except Exception as e:
logger.error(e)
return redirect_to_guard_view()
2019-11-05 10:46:29 +00:00