Skip to content
Snippets Groups Projects
Commit 9cdb8861 authored by kaiyou's avatar kaiyou
Browse files

Add an api for creating and promoting users

parent 2a2caf19
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,7 @@ import flask
blueprint = flask.Blueprint("user", __name__, template_folder="templates")
from hiboo import models, utils
from hiboo.user import users
from hiboo.user import users, cli
def get_user(**redirect_args):
......
from hiboo.user import blueprint
from hiboo import models
import click
@blueprint.cli.command()
@click.argument("username")
@click.argument("password")
def create(username, password):
assert not models.User.query.filter_by(username=username).first()
auth = models.Auth()
auth.set_password(password)
user = models.User(
username=username,
auths=[auth]
)
models.db.session.add(auth)
models.db.session.add(user)
models.db.session.commit()
@blueprint.cli.command()
@click.argument("username")
def promote(username):
user = models.User.query.filter_by(username=username).first()
assert user
user.is_admin = True
models.db.session.commit()
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