示例#1
0
def create_user():
    # Submitting the form.
    username = request.form.get("username", "")
    name = request.form.get("name", "")
    pw1 = request.form.get("password1", "")
    pw2 = request.form.get("password2", "")
    role = request.form.get("role", "")

    # Default name = username.
    if name == "":
        name = username

    # Lowercase the user.
    username = username.lower()
    if User.exists(username=username):
        flash("That username already exists.")
        return redirect(url_for(".users"))

    # Validate the form.
    errors = validate_create_form(username, pw1, pw2)
    if errors:
        for error in errors:
            flash(error)
        return redirect(url_for(".users"))

    # Create the account.
    uid = User.create(username=username, password=pw1, name=name, role=role)

    flash("User created!")
    return redirect(url_for(".users"))
示例#2
0
def setup():
    """Initial setup to create the Admin user account."""

    # This can't be done if users already exist on the CMS!
    if User.exists(uid=1):
        flash("This website has already been configured (users already created).")
        return redirect(url_for("index"))

    if request.method == "POST":
        # Submitting the form.
        username = request.form.get("username", "")
        name     = request.form.get("name", "")
        pw1      = request.form.get("password1", "")
        pw2      = request.form.get("password2", "")

        # Default name = username.
        if name == "":
            name = username

        # Lowercase the user.
        username = username.lower()
        if User.exists(username=username):
            flash("That username already exists.")
            return redirect(url_for(".setup"))

        # Validate the form.
        errors = validate_create_form(username, pw1, pw2)
        if errors:
            for error in errors:
                flash(error)
            return redirect(url_for(".setup"))

        # Create the account.
        uid = User.create(
            username=username,
            password=pw1,
            name=name,
            role="admin",
        )

        flash("Admin user created! Please log in now.".format(uid))
        return redirect(url_for(".login"))


    return template("account/setup.html")