diff --git a/tiny0/forms.py b/tiny0/forms.py index 797c675..da184ea 100644 --- a/tiny0/forms.py +++ b/tiny0/forms.py @@ -1,5 +1,5 @@ from flask_wtf import FlaskForm -from wtforms import StringField, SubmitField, ValidationError +from wtforms import StringField, SubmitField, TextAreaField, ValidationError from wtforms.validators import DataRequired, Length, Optional from tiny0.config import WEBSITE_DOMAIN from tiny0 import db @@ -105,4 +105,11 @@ class URLForm(FlaskForm): class ShortURLForm(FlaskForm): url = StringField(validators=[DataRequired(), Length(min=len(WEBSITE_DOMAIN) + 7, max=len(WEBSITE_DOMAIN) + 25, message="Invalid short URL"), validate_short_URL]) - submit = SubmitField("Track") + submit = SubmitField("Submit") + +class ReportForm(FlaskForm): + url = StringField(validators=[DataRequired(), Length(min=len(WEBSITE_DOMAIN) + 7, max=len(WEBSITE_DOMAIN) + 25, message="Invalid short URL"), validate_short_URL]) + + message = TextAreaField(validators=[DataRequired(), Length(1, 200, message="Message too short or too long")]) + + submit = SubmitField("Submit") diff --git a/tiny0/models.py b/tiny0/models.py index aba4602..718788f 100644 --- a/tiny0/models.py +++ b/tiny0/models.py @@ -8,3 +8,11 @@ class URL(db.Model): def __repr__(self): return f"'{self.id}' '{self.token}' '{self.url}' '{self.clicks}'" + +class Reports(db.Model): + id = db.Column(db.Integer, primary_key=True) + token = db.Column(db.String(16), index=True, nullable=False) + message = db.Column(db.String(200), nullable=False) + + def __repr__(self): + return f"'{self.id}' '{self.token}' '{self.message}'" diff --git a/tiny0/routes.py b/tiny0/routes.py index eb56775..2bc3b37 100644 --- a/tiny0/routes.py +++ b/tiny0/routes.py @@ -1,7 +1,7 @@ from flask import render_template, redirect, url_for from tiny0 import app, db -from tiny0.forms import URLForm, ShortURLForm -from tiny0.models import URL +from tiny0.forms import URLForm, ShortURLForm, ReportForm +from tiny0.models import URL, Reports from tiny0.token import gen_valid_token from tiny0.config import WEBSITE_DOMAIN @@ -95,9 +95,29 @@ def lookup(): # Else if the form was invalid or not submitted else: - # Return the tracker page with the form + # Return the lookup page with the form return render_template("lookup.html", form=form) +# url report route +@app.route("/report", methods=['GET', 'POST']) +def report(): + # Create a instance of the form + form = ReportForm() + + # If the form was valid + if form.validate_on_submit(): + # Add the report to the database + db.session.add(Reports(token=form.url.data, message=form.message.data)) + db.session.commit() + + # Return the thanks page + return render_template("thanks.html") + + # Else if the form was invalid or not submitted + else: + # Return the report page with the form + return render_template("report.html", form=form) + # Donate route @app.route("/donate") def donate(): diff --git a/tiny0/static/style.css b/tiny0/static/style.css index 3ed42fa..82b53c7 100644 --- a/tiny0/static/style.css +++ b/tiny0/static/style.css @@ -216,7 +216,7 @@ body { .clicks { color: #f68741; text-align: center; - margin-top: 230px; + margin-top: 20vh; } .clicks h1 { @@ -227,6 +227,12 @@ body { font-size: 25px; } +.thanks { + color: #f68741; + text-align: center; + margin-top: 20vh; +} + .donation { color: #ffffff; text-align: center; diff --git a/tiny0/templates/index.html b/tiny0/templates/index.html index 43b7802..24d53af 100644 --- a/tiny0/templates/index.html +++ b/tiny0/templates/index.html @@ -5,7 +5,7 @@

< URL Shortener >

{{ form.hidden_tag() }} {{ form.url(placeholder="Enter the URL here", autofocus=true, class="feedback-input") }} - {{ form.token(placeholder="Enter the token (optional)", autofocus=true, class="feedback-input") }} + {{ form.token(placeholder="Enter the token (optional)", class="feedback-input") }}
What's a token?

tiny0.cc/token

Token must be between 6 and 16 characters long

It can only contain letters, numbers, underscores(_) and dashes(-)

diff --git a/tiny0/templates/layout.html b/tiny0/templates/layout.html index a96c82f..2bb4efd 100644 --- a/tiny0/templates/layout.html +++ b/tiny0/templates/layout.html @@ -20,7 +20,7 @@
  • Shortener
  • Tracker
  • Lookup
  • -
  • Report
  • +
  • Report
  • Donate
  • diff --git a/tiny0/templates/report.html b/tiny0/templates/report.html new file mode 100644 index 0000000..9067d06 --- /dev/null +++ b/tiny0/templates/report.html @@ -0,0 +1,21 @@ +{% extends "layout.html" %} + +{% block body %} +
    +

    < Report >

    + {{ form.hidden_tag() }} + {{ form.url(placeholder="Enter the short URL", autofocus=true, class="feedback-input") }} + {{ form.message(placeholder="Enter a short message explaining the reason for your report", class="feedback-input") }} + {{ form.submit(class="button") }} + {% if form.errors %} +
    + {% for error in form.url.errors %} +

    {{ error }}

    + {% endfor %} + {% for error in form.message.errors %} +

    {{ error }}

    + {% endfor %} +
    + {% endif %} +
    +{% endblock %} diff --git a/tiny0/templates/thanks.html b/tiny0/templates/thanks.html new file mode 100644 index 0000000..7bce953 --- /dev/null +++ b/tiny0/templates/thanks.html @@ -0,0 +1,7 @@ +{% extends "layout.html" %} + +{% block body %} +
    +

    Your report has been submitted

    +
    +{% endblock %}