mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-05 02:42:26 -05:00
109638656: Initial implementation for two-factor
This commit is contained in:
@@ -3,4 +3,4 @@ from flask import Blueprint
|
||||
main = Blueprint('main', __name__)
|
||||
|
||||
|
||||
from app.main.views import index, sign_in, register, verify
|
||||
from app.main.views import index, sign_in, register, two_factor, verify
|
||||
|
||||
@@ -41,6 +41,10 @@ class RegisterUserForm(Form):
|
||||
Blacklist(message='That password is blacklisted, too common')])
|
||||
|
||||
|
||||
class TwoFactorForm(Form):
|
||||
sms_code = IntegerField('sms code', validators=[DataRequired(message='Please enter your code')])
|
||||
|
||||
|
||||
class VerifyForm(Form):
|
||||
sms_code = StringField("Text message confirmation code",
|
||||
validators=[DataRequired(message='SMS code can not be empty'),
|
||||
|
||||
@@ -41,11 +41,6 @@ def addservice():
|
||||
return render_template('add-service.html')
|
||||
|
||||
|
||||
@main.route("/two-factor")
|
||||
def twofactor():
|
||||
return render_template('two-factor.html')
|
||||
|
||||
|
||||
@main.route("/send-sms")
|
||||
def sendsms():
|
||||
return render_template('send-sms.html')
|
||||
|
||||
19
app/main/views/two_factor.py
Normal file
19
app/main/views/two_factor.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from flask import render_template, redirect, jsonify
|
||||
|
||||
from app.main import main
|
||||
from app.main.forms import TwoFactorForm
|
||||
|
||||
|
||||
@main.route("/two-factor", methods=['GET'])
|
||||
def render_two_factor():
|
||||
return render_template('two-factor.html', form=TwoFactorForm())
|
||||
|
||||
|
||||
@main.route('/two-factor', methods=['POST'])
|
||||
def process_two_factor():
|
||||
form = TwoFactorForm()
|
||||
|
||||
if form.validate_on_submit():
|
||||
return redirect('/dashboard')
|
||||
else:
|
||||
return jsonify(form.errors), 400
|
||||
14
tests/app/main/views/test_two_factor.py
Normal file
14
tests/app/main/views/test_two_factor.py
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
|
||||
def test_should_render_two_factor_page(notifications_admin, notifications_admin_db):
|
||||
response = notifications_admin.test_client().get('/two-factor')
|
||||
assert response.status_code == 200
|
||||
assert '''We've sent you a text message with a verification code.''' in response.get_data(as_text=True)
|
||||
|
||||
|
||||
def test_should_login_user_and_redirect_to_dashboard(notifications_admin, notifications_admin_db):
|
||||
response = notifications_admin.test_client().post('/two-factor',
|
||||
data={'sms_code': '12345'})
|
||||
|
||||
assert response.status_code == 302
|
||||
assert response.location == 'http://localhost/dashboard'
|
||||
Reference in New Issue
Block a user