diff --git a/main.py b/main.py index 0b44c25057e71329819f877bbff1bd4df1f1cbd3..e1dbb96634e6651996d9ff01ecd533531a231253 100644 --- a/main.py +++ b/main.py @@ -10,7 +10,7 @@ from io import BytesIO #Needed for base64 encoding of the image from PIL import Image #Needed for QR generation from flask_github import GitHub #github oauth library import json #used for github oauth - +from html import escape #This is used to escape characters, if they are send in the url app = Flask(__name__) domain_to_index = {} @@ -135,10 +135,8 @@ def grecaptcha_verify(request): #This function is used to verify the google reca @app.route('/', methods=['GET']) def home_get(): try: - userID = request.cookies.get('userID') loginbar = "Hello " + request.cookies.get('username') + ' (<a href="/user/logout" style="color:white">logout</a>)' except: - userID = "null" loginbar = '<a href="/user/login" style="color:white">login</a>' return render_template('home.html', builddate=builddate, version=version, domain=domain_prepared, recaptchaPublicKey=recaptchaPublicKey, showDomainSelect=showDomainSelect, loginbar=loginbar) #return the default site to create a new shorten link @@ -237,6 +235,27 @@ def logout(): resp.set_cookie('username', "", max_age=0) return resp +@app.route('/user/links') +def ownLinks(): + try: + userID = request.cookies.get('userID') + loginbar = "Hello " + request.cookies.get('username') + ' (<a href="/user/logout" style="color:white">logout</a>)' + except: + return redirect("/user/login") + + with sqlite3.connect('db/urls.db') as conn: #Get the original URL from the database + cursor = conn.cursor() + res = cursor.execute('SELECT LONG_URL, SHORT_URL FROM WEB_URL WHERE USERNAME=?', [userID]) + response = '<table id="t01">\n<tr>\n<th>Long URL</th>\n<th>Short URL</th>\n<th>Action</th>\n</tr>\n' + try: + for entries in res.fetchall(): + response = response + "<tr>\n<td>" + entries[0] + "</td>\n<td>" + entries[1] + '</td>\n<td><a id="red" href="/user/delete?link=' + escape(entries[1]) + '">delete</a></tr>\n' + except: + abort(500) + response = response + "</table>" + return render_template('editEntries.html', content=response, loginbar=loginbar) + + if __name__ == '__main__': table_check()# This code checks whether database table is created or not if production: #Check if production variable is set to true use the waitress webserver, else use the buildin flask webserver, with more debug output diff --git a/static/style.css b/static/style.css index e2b3d429d8b7590dd300cd11546c64c069c5c4d0..bedcc8ff4cf824e8e5b006370b668b4033e2bba3 100644 --- a/static/style.css +++ b/static/style.css @@ -64,11 +64,11 @@ margin: auto; position: relative; z-index: 1; background: #FFFFFF; -max-width: 360px; margin: 0 auto 100px; padding: 45px; text-align: center; box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0 rgba(0, 0, 0, 0.24); +display: table; } .form input { font-family: "Roboto", sans-serif; @@ -190,6 +190,27 @@ animation: fadein 0.5s, fadeout 0.5s 2.5s; font-size: 17px; } +table, th, td { + border: 1px solid black; + border-collapse: collapse; +} +th, td { + padding: 15px; + text-align: left; +} +table#t01 tr:nth-child(even) { + background-color: #eee; +} +table#t01 tr:nth-child(odd) { + background-color: #fff; +} +table#t01 th { + background-color: black; + color: white; +} +a#red { + color: red; +} @-webkit-keyframes fadein { from {bottom: 0; opacity: 0;} to {bottom: 30px; opacity: 1;} diff --git a/templates/editEntries.html b/templates/editEntries.html new file mode 100644 index 0000000000000000000000000000000000000000..c460bdfb748cd1857c877a0d282f58161bb8f35f --- /dev/null +++ b/templates/editEntries.html @@ -0,0 +1,16 @@ +<!DOCTYPE html> +<html lang="en"> + <head> + <link href="{{ url_for('static', filename='style.css') }}" rel="stylesheet"> + <title>URL shorter</title> + </head> + + <body> + <div id="loginbar">{{loginbar | safe}}</div> + <div class="login-page"> + <div class="form"> + {{content | safe}} + </div> + </div> + </body> +</html> \ No newline at end of file