diff --git a/app/developer/templates/developer/client_details/basic_info.html b/app/developer/templates/developer/client_details/basic_info.html index 2fcf6537..05bd638f 100644 --- a/app/developer/templates/developer/client_details/basic_info.html +++ b/app/developer/templates/developer/client_details/basic_info.html @@ -26,7 +26,8 @@ {% endif %} -
+ {{ form.csrf_token }}

App Info

@@ -36,13 +37,6 @@ {{ render_field_errors(form.name) }} -
- - {{ form.home_url(class="form-control", type="url", value=client.home_url or "", - placeholder="https://mywebsite.com") }} - {{ render_field_errors(form.home_url) }} -
-
App Icon

@@ -55,6 +49,27 @@ {% endif %}

+
+ +
+

Submit for approval

+

Before your app can be used by all SimpleLogin users, it needs to go through an approval process.

+ +
+ {{ approval_form.csrf_token }} + +
+ + {{ approval_form.description( + class="form-control", rows="10", + placeholder="This information is used for approving your application. Please give us as much info as you can, for example where you plan to use SimpleLogin, for which community, etc." + ) }} + {{ render_field_errors(approval_form.description) }} +
+ + +
{% endblock %} \ No newline at end of file diff --git a/app/developer/templates/developer/index.html b/app/developer/templates/developer/index.html index 977fd48f..f54387ae 100644 --- a/app/developer/templates/developer/index.html +++ b/app/developer/templates/developer/index.html @@ -22,8 +22,12 @@
@@ -37,12 +41,21 @@
{% if client.icon_id %} - + {% endif %} {{ client.name }} + {% if client.approved %} + + {% else %} + + 🚫 + + + {% endif %}
diff --git a/app/developer/views/client_detail.py b/app/developer/views/client_detail.py index 8f277a08..4908fd8c 100644 --- a/app/developer/views/client_detail.py +++ b/app/developer/views/client_detail.py @@ -4,10 +4,12 @@ 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 wtforms import StringField, validators, TextAreaField from app import s3 +from app.config import ADMIN_EMAIL from app.developer.base import developer_bp +from app.email_utils import send_email from app.extensions import db from app.log import LOG from app.models import Client, RedirectUri, File @@ -17,7 +19,10 @@ from app.utils import random_string class EditClientForm(FlaskForm): name = StringField("Name", validators=[validators.DataRequired()]) icon = FileField("Icon") - home_url = StringField("Home Url") + + +class ApprovalClientForm(FlaskForm): + description = TextAreaField("Description", validators=[validators.DataRequired()]) # basic info @@ -25,21 +30,22 @@ class EditClientForm(FlaskForm): @login_required def client_detail(client_id): form = EditClientForm() + approval_form = ApprovalClientForm() is_new = "is_new" in request.args + action = request.args.get("action") client = Client.get(client_id) - if not client: - flash("no such client", "warning") - return redirect(url_for("developer.index")) - - if client.user_id != current_user.id: + if not client or client.user_id != current_user.id: flash("you cannot see this app", "warning") return redirect(url_for("developer.index")) - if form.validate_on_submit(): + # can't set value for a textarea field in jinja + if request.method == "GET": + approval_form.description.data = client.description + + if action == "edit" and form.validate_on_submit(): client.name = form.name.data - client.home_url = form.home_url.data if form.icon.data: # todo: remove current icon if any @@ -61,9 +67,34 @@ def client_detail(client_id): return redirect(url_for("developer.client_detail", client_id=client.id)) + if action == "submit" and approval_form.validate_on_submit(): + client.description = approval_form.description.data + db.session.commit() + + send_email( + ADMIN_EMAIL, + subject=f"{client.name} {client.id} submits for approval", + plaintext="", + html=f""" + name: {client.name}
+ created: {client.created_at}
+ user: {current_user.email}
+
+ {client.description} + """, + ) + + flash( + f"Thanks for submitting, we are informed and will come back to you asap!", + "success", + ) + + return redirect(url_for("developer.client_detail", client_id=client.id)) + return render_template( "developer/client_details/basic_info.html", form=form, + approval_form=approval_form, client=client, is_new=is_new, ) diff --git a/app/email_utils.py b/app/email_utils.py index 384c1377..2897d394 100644 --- a/app/email_utils.py +++ b/app/email_utils.py @@ -238,10 +238,11 @@ def send_email( to_email = sanitize_email(to_email) if NOT_SEND_EMAIL: LOG.d( - "send email with subject '%s' to '%s', plaintext: %s", + "send email with subject '%s' to '%s', plaintext: %s, html: %s", subject, to_email, plaintext, + html, ) return