コード例 #1
0
def initial_setup():
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = generate_password_hash(
            form.password.data).decode("utf-8")
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_password)
        user.save()
        flash(
            f"Account created for {form.username.data} -  Bands Added! You can now log in.",
            "success")
        uid = user.id
        if not Towns.objects():
            setup_towns()
        resource_path = os.path.join(app.root_path, 'setup')
        with open(os.path.join(resource_path, 'band.json')) as f:
            file_data = json.load(f)
        bandz = []
        for band in file_data:
            if 'date_created' in band.keys():
                date_created = datetime.strptime(band.pop('date_created'),
                                                 "%Y-%m-%dT%H:%M:%S")
            else:
                date_created = datetime.utcnow
            bandz.append(
                Band(**band, created_by=uid, date_created=date_created))
        bands = Band.objects.insert(bandz)
        return redirect(url_for("user.login"))
    if len(list(Band.objects())) == 0:
        return render_template("setup.html", form=form, fullpage=True)
    else:
        flash(f"Initial Setup Complete", "success")
        return redirect(url_for("public.home"))
コード例 #2
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for("manage.mhome"))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = generate_password_hash(
            form.password.data).decode("utf-8")
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_password)
        user.save()
        flash(
            f"Account created for superuser {form.username.data}! Please restart server.",
            "success")
        return redirect(url_for("user.restart"))
    return render_template("register.html",
                           title="Register",
                           form=form,
                           display_breadcrumbs=True)