Fix the token generation process
This commit is contained in:
@@ -105,9 +105,10 @@ class UserReplyForm(flask_wtf.FlaskForm):
|
|||||||
|
|
||||||
|
|
||||||
class TokenForm(flask_wtf.FlaskForm):
|
class TokenForm(flask_wtf.FlaskForm):
|
||||||
raw_password = fields.StringField(
|
displayed_password = fields.StringField(
|
||||||
_('Your token (write it down, as it will never be displayed again)')
|
_('Your token (write it down, as it will never be displayed again)')
|
||||||
)
|
)
|
||||||
|
raw_password = fields.HiddenField([validators.DataRequired()])
|
||||||
comment = fields.StringField(_('Comment'))
|
comment = fields.StringField(_('Comment'))
|
||||||
ip = fields.StringField(
|
ip = fields.StringField(
|
||||||
_('Authorized IP'), [validators.Optional(), validators.IPAddress()]
|
_('Authorized IP'), [validators.Optional(), validators.IPAddress()]
|
||||||
|
|||||||
@@ -24,12 +24,14 @@ def token_create(user_email):
|
|||||||
user_email = user_email or flask_login.current_user.email
|
user_email = user_email or flask_login.current_user.email
|
||||||
user = models.User.query.get(user_email) or flask.abort(404)
|
user = models.User.query.get(user_email) or flask.abort(404)
|
||||||
form = forms.TokenForm()
|
form = forms.TokenForm()
|
||||||
form.raw_password.data = pwd.genword(entropy=128, charset="hex")
|
wtforms_components.read_only(form.displayed_password)
|
||||||
wtforms_components.read_only(form.raw_password)
|
if not form.raw_password.data:
|
||||||
|
form.raw_password.data = pwd.genword(entropy=128, charset="hex")
|
||||||
|
form.displayed_password.data = form.raw_password.data
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
token = models.Token(user=user)
|
token = models.Token(user=user)
|
||||||
form.populate_obj(token)
|
|
||||||
token.set_password(form.raw_password.data)
|
token.set_password(form.raw_password.data)
|
||||||
|
form.populate_obj(token)
|
||||||
db.session.add(token)
|
db.session.add(token)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flask.flash('Authentication token created')
|
flask.flash('Authentication token created')
|
||||||
|
|||||||
Reference in New Issue
Block a user