Skip to content
Snippets Groups Projects
Commit 1600c09a authored by f00wl's avatar f00wl
Browse files

Update code with the new dict-like auths attribute

parent ec8d5a46
No related branches found
No related tags found
No related merge requests found
......@@ -55,9 +55,9 @@ def signup():
else:
user = models.User()
user.username = form.username.data
auth = models.Auth()
auth = models.Auth("password")
auth.set_password(form.password.data)
user.auths.append(auth)
user.auths = {"password": auth}
models.db.session.add(user)
models.db.session.add(auth)
models.log(models.History.SIGNUP,
......@@ -80,7 +80,7 @@ def reset(token_uuid):
if form.validate_on_submit():
token.expired_at = datetime.datetime.now()
models.db.session.add(token)
auth = token.user.auths[0]
auth = token.user.auths["password"]
auth.set_password(form.password.data)
models.log(models.History.PASSWORD, user=token.user)
models.db.session.add(auth)
......
......@@ -12,7 +12,7 @@ import flask_login
def password():
form = forms.PasswordForm()
if form.validate_on_submit():
auth = flask_login.current_user.auths[0]
auth = flask_login.current_user.auths["password"]
if auth.check_password(form.old.data):
auth.set_password(form.password.data)
models.log(models.History.PASSWORD, user=flask_login.current_user)
......
......@@ -97,9 +97,9 @@ class User(db.Model):
if not user:
return False
auths = user.auths
if not auths:
if not auths["password"]:
return False
if not auths[0].check_password(password):
if not auths["password"].check_password(password):
return False
return user
......
......@@ -9,11 +9,11 @@ import click
@click.argument("password")
def create(username, password):
assert not models.User.query.filter_by(username=username).first()
auth = models.Auth()
auth = models.Auth("password")
auth.set_password(password)
user = models.User(
username=username,
auths=[auth]
auths={auth.realm: auth}
)
models.db.session.add(auth)
models.db.session.add(user)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment