Added url reporting
This commit is contained in:
+9
-2
@@ -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")
|
||||
|
||||
@@ -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}'"
|
||||
|
||||
+23
-3
@@ -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():
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<h1>< URL Shortener ></h1>
|
||||
{{ 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") }}
|
||||
<div class="tooltip">
|
||||
What's a token?
|
||||
<span class="tooltiptext"><p>tiny0.cc/token</p><p>Token must be between 6 and 16 characters long</p><p>It can only contain letters, numbers, underscores(_) and dashes(-)</p></span>
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
<li class="items"><a href="{{ url_for('index') }}">Shortener</a></li>
|
||||
<li class="items"><a href="{{ url_for('tracker') }}">Tracker</a></li>
|
||||
<li class="items"><a href="{{ url_for('lookup') }}">Lookup</a></li>
|
||||
<li class="items"><a href="#">Report</a></li>
|
||||
<li class="items"><a href="{{ url_for('report') }}">Report</a></li>
|
||||
<li class="items"><a href="{{ url_for('donate') }}">Donate</a></li>
|
||||
<li class="btn"><a href="#"><i class="fas fa-bars"></i></a></li>
|
||||
</ul>
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
{% extends "layout.html" %}
|
||||
|
||||
{% block body %}
|
||||
<form method="POST" action="" class="url-form">
|
||||
<h1>< Report ></h1>
|
||||
{{ 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 %}
|
||||
<div class="form-errors">
|
||||
{% for error in form.url.errors %}
|
||||
<h4>{{ error }}</h4>
|
||||
{% endfor %}
|
||||
{% for error in form.message.errors %}
|
||||
<h4>{{ error }}</h4>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</form>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,7 @@
|
||||
{% extends "layout.html" %}
|
||||
|
||||
{% block body %}
|
||||
<div class="thanks">
|
||||
<h1>Your report has been submitted</h1>
|
||||
</div>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user