示例#1
0
def register():
    """
    Register new user.
    """
    form = RegisterForm(request.form)
    if form.validate_on_submit():
        u = User(
            username=form.username.data,
            email=form.email.data,
            password=form.password.data,
            first_name=form.first_name.data,
            last_name=form.last_name.data,
        )
        u.enforce_admin()
        u.save()
        if u.active:
            flash("Thanks for registering! You're now logged in.", "success")
            login_user(u)
        else:
            flash(
                "Thanks for registering! You will now need to wait for your admin to approve this account.",
                "success",
            )
        return redirect(url_for("public.home"))
    else:
        flash_errors(form)
    return render_template("public/register.html", form=form)
示例#2
0
文件: views.py 项目: ousamg/MegaQC
def admin_add_users(user, *args, **kwargs):
    data = request.get_json()
    try:
        data["user_id"] = int(data["user_id"])
    except:
        abort(400)
    new_user = User(**data)
    new_user.enforce_admin()
    password = new_user.reset_password()
    new_user.active = True
    new_user.save()
    return jsonify({
        "success": True,
        "password": password,
        "api_token": user.api_token
    })