remove website url and icon when creating new app

This commit is contained in:
Son NK 2019-07-23 19:33:09 +02:00 committed by Son NK
parent daf22b823d
commit fc73267b53
2 changed files with 15 additions and 40 deletions

View File

@ -3,31 +3,26 @@
{% set active_page = "developer" %}
{% block title %}
Developer - Create new client
Developer - Create new app
{% endblock %}
{% block default_content %}
<h1>Create new app</h1>
<p>An app can be a website, a SPA webapp or a mobile application</p>
<small>Let's get started integrating SimpleLogin into your app! </small>
<hr>
<form method="post" enctype="multipart/form-data">
{{ form.csrf_token }}
<div class="form-group">
<label class="form-label">App Name</label>
{{ form.name(class="form-control") }}
<label class="form-label">Display Name</label>
{{ form.name(class="form-control",
placeholder="The name users sees when they click on *Sign in with SimpleLogin*") }}
{{ render_field_errors(form.name) }}
</div>
<div class="form-group">
<label class="form-label">Website Url</label>
{{ form.home_url(class="form-control", type="url") }}
{{ render_field_errors(form.home_url) }}
</div>
<div class="form-group">
<div class="form-label">App Icon</div>
{{ form.icon(class="form-control-file") }}
{{ render_field_errors(form.icon) }}
</div>
<button type="submit" class="btn btn-primary">Create</button>
</form>

View File

@ -1,23 +1,15 @@
from io import BytesIO
from flask import request, render_template, redirect, url_for, flash
from flask_login import current_user, login_required
from flask_wtf import FlaskForm
from flask_wtf.file import FileField
from wtforms import StringField, validators
from app import s3
from app.developer.base import developer_bp
from app.extensions import db
from app.log import LOG
from app.models import Client, File
from app.utils import random_string
from app.models import Client
class NewClientForm(FlaskForm):
name = StringField("Name", validators=[validators.DataRequired()])
icon = FileField("Icon")
home_url = StringField("Home Url")
@developer_bp.route("/new_client", methods=["GET", "POST"])
@ -28,23 +20,11 @@ def new_client():
if request.method == "POST":
if form.validate():
client = Client.create_new(form.name.data, current_user.id)
client.home_url = form.home_url.data
db.session.commit()
flash("Your app has been created", "success")
if form.icon.data:
file_path = random_string(30)
file = File.create(path=file_path)
s3.upload_from_bytesio(file_path, BytesIO(form.icon.data.read()))
db.session.commit()
LOG.d("upload file %s to s3", file)
client.icon_id = file.id
db.session.commit()
flash("New client has been created", "success")
return redirect(url_for("developer.client_detail", client_id=client.id))
return redirect(
url_for("developer.handle_step", client_id=client.id, step="step-0")
)
return render_template("developer/new_client.html", form=form)