def admin_init(admin_secret_key): if not admin_secret_key == app.config["ADMIN_SECRET_KEY"]: error = 'Bogus admin key, or key timed out.' return render_template("admin/error.html", error=error) try: # if we have anything in the db, we should not be here! if User.query.first(): error = "Root user already created. Begone." return render_template("error.html", error=error) except Exception as error: try: db.create_all() except Exception as error: return render_template("error.html", error=error) if request.method == 'POST': username = request.form['username'] try: if User.query.filter(User.username==username).first(): error = 'User already exists.' return render_template("error.html", error=error) except Exception as error: print(error) error = manifest_user(db, Profile, User, request, "root") if not error: return redirect(url_for("login")) return render_template("error.html", error=error) # if we're here, we are a GET task = "initial database and root user set up" message = "database created. create a new root user." return render_template("admin/init.html", message=message, task=task)
def admin_create_user(): if request.method == 'POST': if User.query.filter(User.username==request.form["username"]).first(): return 'User already exists.' if Profile.query.filter(Profile.username==request.form["username"]).first(): return 'Profile already exists.' error = manifest_user(db, Profile, User, request, "user") if not error: return redirect("/admin/update-user/%s"%request.form["username"]) return render_template("error.html", error=error) return render_template("admin/create-user.html")
def complete_signup(key): if request.method == "POST": email = request.form["email"] username = request.form["username"] password = request.form["password"] if User.query.filter(User.username==username).first(): error = 'User already exists.' return render_template("error.html", error=error) temp_auth = TempAuth.query.filter(TempAuth.key == key).one() error = manifest_user( db, Profile, User, request, "user", email=temp_auth.email) if not error: return render_template("auth/login.html", username=username) return render_template("error.html", error=error) temp_auth = auth_age(TempAuth, key) if not temp_auth: stale = "Key is too old. Please send another signup email." return render_template("auth/login.html", stale = stale) return render_template("admin/create-user.html", temp_auth=temp_auth)