Skip to content

Adds 2 factor backend code#169

Merged
mprahl merged 13 commits intomasterfrom
ft-enable_2_factor
Oct 29, 2016
Merged

Adds 2 factor backend code#169
mprahl merged 13 commits intomasterfrom
ft-enable_2_factor

Conversation

@thatarchguy
Copy link
Member

Ripped from #165 because of decision to separate the merge into frontend and backend pieces #165 (comment)

Signed-off-by: Kevin <kevin@stealsyour.pw>
Signed-off-by: Kevin <kevin@stealsyour.pw>
Signed-off-by: Kevin <kevin@stealsyour.pw>
Signed-off-by: Kevin <kevin@stealsyour.pw>
Signed-off-by: Kevin <kevin@stealsyour.pw>
Signed-off-by: Kevin <kevin@stealsyour.pw>
return dict(enabled=admin.otp_active)
elif status.lower() == "true":
raise GenericError("Cannot enable 2 factor from this route - see docs")
raise GenericError("An Invalid parameter was supplied")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lower case I in "invalid"

'error', current_user.username,
'The following error occurred in twofactor_disable: {0}'.format(str(e)))
raise GenericError('The administrator could not be updated')
return dict(enabled=admin.otp_active)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should return anything in this case. Just an HTTP 200.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thatarchguy can you take a look at this?

'error', current_user.username,
'The following error occurred in verify_qrcode: {0}'.format(str(e)))
raise GenericError('The administrator could not be updated')
return dict(status="Success")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should be returning this here. We don't anywhere else in the app. A simple HTTP 200 should do here with no JSON.


from flask_wtf import Form
from wtforms import StringField, PasswordField, SelectField
from wtforms import StringField, PasswordField, SelectField, IntegerField, validators
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of importing validators, import Optional from it on the next line. Alternatively, you can remove the line below and do validators.DataRequired() on line 17, 18, and 20.

"""
username = StringField(label='Username', validators=[DataRequired()])
password = PasswordField(label='Password', validators=[DataRequired(), validate_wtforms_password])
two_factor = IntegerField(label='2 Factor', validators=(validators.Optional(),))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the label be "Two Factor Code"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also thinking that instead of this, we should pop up a modal if two factor authentication is enabled. This is fine for now though.

return {}, 200


@apiv1.route('/admins/<int:admin_id>/2factor', methods=['GET'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change the route to "twofactor"?

return dict(enabled=admin.otp_active)


@apiv1.route('/admins/<int:admin_id>/2factor', methods=['PUT'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change the route to "twofactor"?

raise GenericError("An Invalid parameter was supplied")


@apiv1.route('/admins/<int:admin_id>/2factor/qrcode', methods=['GET'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change the route to "twofactor"?

'Expires': '0'}


@apiv1.route('/admins/<int:admin_id>/2factor/verify', methods=['POST'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change the route to "twofactor"?

assert False, "Not json"
assert "Success" in rv.data
assert rv.status_code == 200
assert "Success" in rv.data
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate line. Please remove.

@mprahl
Copy link
Member

mprahl commented Oct 25, 2016

@thatarchguy nice work. I just have some simple comments you need to address and then we'll merge this.

@mprahl
Copy link
Member

mprahl commented Oct 25, 2016

@thatarchguy also please add to the Change Log.

Signed-off-by: Kevin <kevin@stealsyour.pw>
Signed-off-by: Kevin <kevin@stealsyour.pw>
Signed-off-by: Kevin <kevin@stealsyour.pw>
Signed-off-by: Kevin <kevin@stealsyour.pw>
Signed-off-by: Kevin <kevin@stealsyour.pw>
@mprahl
Copy link
Member

mprahl commented Oct 29, 2016

@thatarchguy LGTM!

Next time, don't merge master into your branch, do:

git checkout master
git pull
git checkout feature-branch-name
git rebase master

This stacks your new commits on top of the latest master.

@mprahl mprahl merged commit b1e046c into master Oct 29, 2016
@mprahl mprahl deleted the ft-enable_2_factor branch October 29, 2016 00:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants