app-MAIL-temp/app/developer/views/new_client.py
Adrià Casajús 25022b4ad8
Several fixes (#2157)
* Ensure uploaded pictures are images and delete the previous ones

* Add CSRF protection to admin routes

* Only allow https urls in the client envs

* Close connection to try to get a new one

* Missing parameter

* start_time can be non existant. Set a default value
2024-07-18 12:48:18 +00:00

39 lines
1.2 KiB
Python

from urllib.parse import urlparse
from flask import render_template, redirect, url_for, flash
from flask_login import current_user, login_required
from flask_wtf import FlaskForm
from wtforms import StringField, validators
from app.db import Session
from app.developer.base import developer_bp
from app.models import Client
class NewClientForm(FlaskForm):
name = StringField("Name", validators=[validators.DataRequired()])
url = StringField("Url", validators=[validators.DataRequired()])
@developer_bp.route("/new_client", methods=["GET", "POST"])
@login_required
def new_client():
form = NewClientForm()
if form.validate_on_submit():
client = Client.create_new(form.name.data, current_user.id)
parsed_url = urlparse(form.url.data)
if parsed_url.scheme != "https":
flash("Only https urls are allowed", "error")
return redirect(url_for("developer.new_client"))
client.home_url = form.url.data
Session.commit()
flash("Your website has been created", "success")
return redirect(
url_for("developer.client_detail", client_id=client.id, is_new=1)
)
return render_template("developer/new_client.html", form=form)