Commit 5e0a765a by Kálmán Viktor

dashboard: nicer 2fa login page

parent b83e5628
...@@ -1670,9 +1670,8 @@ class TwoFactorForm(ModelForm): ...@@ -1670,9 +1670,8 @@ class TwoFactorForm(ModelForm):
class TwoFactorConfirmationForm(forms.Form): class TwoFactorConfirmationForm(forms.Form):
confirmation_code = forms.CharField( confirmation_code = forms.CharField(
label=_('Confirmation code'), label=_('Two-factor authentication passcode'),
help_text=_("Get the code from your authenticator to disable " help_text=_("Get the code from your authenticator."))
"two-factor authentication."))
def __init__(self, user, *args, **kwargs): def __init__(self, user, *args, **kwargs):
self.user = user self.user = user
......
...@@ -1549,3 +1549,17 @@ textarea[name="new_members"] { ...@@ -1549,3 +1549,17 @@ textarea[name="new_members"] {
margin-left: 15px; margin-left: 15px;
} }
} }
#two-factor-box {
.help-block {
display: block;
}
h4 {
margin: 0;
}
hr {
margin: 15px 0 2px 0;
}
}
...@@ -622,15 +622,21 @@ class TwoFactorLoginView(FormView): ...@@ -622,15 +622,21 @@ class TwoFactorLoginView(FormView):
return super(TwoFactorLoginView, self).dispatch(*args, **kwargs) return super(TwoFactorLoginView, self).dispatch(*args, **kwargs)
def get_user(self):
return User.objects.get(pk=self.request.session['two-fa-user'])
def get_form_kwargs(self): def get_form_kwargs(self):
kwargs = super(TwoFactorLoginView, self).get_form_kwargs() kwargs = super(TwoFactorLoginView, self).get_form_kwargs()
user_pk = self.request.session['two-fa-user'] kwargs['user'] = self.get_user()
kwargs['user'] = User.objects.get(pk=user_pk)
return kwargs return kwargs
def get_context_data(self, **kwargs):
ctx = super(TwoFactorLoginView, self).get_context_data(**kwargs)
ctx['user'] = self.get_user()
return ctx
def form_valid(self, form): def form_valid(self, form):
user_pk = self.request.session['two-fa-user'] user = self.get_user()
user = User.objects.get(pk=user_pk)
if self.request.session['login-type'] == "saml2": if self.request.session['login-type'] == "saml2":
user.backend = 'common.backends.Saml2Backend' user.backend = 'common.backends.Saml2Backend'
......
...@@ -4,21 +4,24 @@ ...@@ -4,21 +4,24 @@
{% load crispy_forms_tags %} {% load crispy_forms_tags %}
{% get_current_language as LANGUAGE_CODE %} {% get_current_language as LANGUAGE_CODE %}
{% block title-page %}{% trans "Login" %}{% endblock %} {% block title-page %}{% trans "Two-factor authentication" %}{% endblock %}
{% block content_box %} {% block content_box %}
<div class="row"> <div class="row" id="two-factor-box">
<div class="col-md-12"> <div class="col-md-12">
<h4>
{% blocktrans with username=user.username full_name=user.get_full_name %}
Welcome {{ full_name }} ({{ username }})!
{% endblocktrans %}
</h4>
<hr/>
<form action="" method="POST"> <form action="" method="POST">
{% csrf_token %} {% csrf_token %}
{{ form.confirmation_code|as_crispy_field }} {{ form.confirmation_code|as_crispy_field }}
<input type="submit"/> <button type="submit" class="btn btn-success">
{% trans "Confirm" %}
</button>
</form> </form>
</div> </div>
</div> </div>
<style>
.help-block {
display: block;
}
</style>
{% endblock %} {% endblock %}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment