diff --git a/api.py b/api.py index e9d521ad371dc46f74fcdebaa03dd9e7ae6e18c1..8f5630ce340b19225a816d8715f15cbd2e66e9fc 100644 --- a/api.py +++ b/api.py @@ -1,7 +1,8 @@ from flask import jsonify, render_template import sqlite3 +from makeqr import makeQR -def apiGet(request, url_scheme): +def apiGet(request, url_scheme, s, sAPI): try: userID = sAPI.dumps(s.loads(request.cookies.get('userID'))) except: @@ -9,10 +10,11 @@ def apiGet(request, url_scheme): return render_template("apiDocs.html", apikey=userID, domain=request.headers['Host'], url_scheme=url_scheme) -def apiPost(request, domain): +def apiPost(request, url_scheme, domain, sAPI): username = "error" try: username = sAPI.loads(request.form['apikey']) + print(username) except: pass @@ -55,7 +57,6 @@ def apiPost(request, domain): 'INSERT INTO WEB_URL (LONG_URL, SHORT_URL, USERNAME) VALUES (?, ?, ?)', [longURL, short, username] ) - try: request.form['qr'] qr64 = "data:image/jpeg;base64," + makeQR(url_scheme + "://" + short) diff --git a/main.py b/main.py index f9158e2afb256acaeef7495bfa64e8d3e0944f09..3d75d80f7c719bbabfa6cdcb13f713e73934b4d5 100644 --- a/main.py +++ b/main.py @@ -170,12 +170,12 @@ def makeQrCode(): @app.route('/user/api', methods=['POST']) def api(): - return apiPost(request, domain) + return apiPost(request, url_scheme, domain, sAPI) @app.route('/user/api', methods=['GET']) def apiDocs(): - return apiGet(request, url_scheme) + return apiGet(request, url_scheme, s, sAPI) if __name__ == '__main__': diff --git a/templates/editEntries.html b/templates/editEntries.html index bbd79acbdf866a33680386d2c4a59ef05d424646..f3a7b20a0e1673a24210eadf6bbe9622376d63f4 100644 --- a/templates/editEntries.html +++ b/templates/editEntries.html @@ -14,7 +14,7 @@ <div class="login-page"> <div class="form"> {{content | safe}} - <p><a href="/">back</a></p> + <p><a href="/user/api">API</a> <a href="/">back to main page</a></p> </div> </div> <!-- ui-dialog --> diff --git a/userprofile.py b/userprofile.py index 2224612ce8e5d278034711e45f02373753cd505e..f71f865b9b2243172e7a4c18601900e4b94f38f3 100644 --- a/userprofile.py +++ b/userprofile.py @@ -21,7 +21,7 @@ def userProfile(request, cookieNotice, s): calls = str(cursor2.execute('SELECT CALLS FROM ANALYTICS WHERE SHORT_URL=?', [entries[1]]).fetchone()[0]) except: calls = "0" - response = response + "<tr>\n<td>" + entries[0] + "</td>\n<td>" + entries[1] + '</td>\n<td>' + calls + '</td>\n<td><a id="red" href="/user/delete?link=' + escape(entries[1]) + '">delete</a> <a href="#" id="dialog-link" onclick="buttonListener(\'' + entries[1] + '\', this)">QR</a></tr>\n' + response = response + "<tr>\n<td>" + entries[0] + "</td>\n<td><a href=\"" + entries[1] + '">' + entries[1] + '</a></td>\n<td>' + calls + '</td>\n<td><a id="red" href="/user/delete?link=' + escape(entries[1]) + '">delete</a> <a href="#" id="dialog-link" onclick="buttonListener(\'' + entries[1] + '\', this)">QR</a></tr>\n' response = response + "</table>" #Close the table if(len(entriesList) == 0): response = 'you have no shorten links.' #If user has no shorten links make this message except: