From e8f0487e057aae1ccbbd16724a35b82407047be0 Mon Sep 17 00:00:00 2001 From: ditaajipratama Date: Mon, 17 Jun 2024 21:33:07 +0700 Subject: [PATCH] Notme features --- app/handler.py | 22 ++++++++++++++++++++++ app/modules/api/auth.py | 10 +++------- app/modules/public/notme.py | 28 ++++++++++++++++++++++++++++ app/pages/email/message.html | 1 + app/pages/public/notme.html | 14 ++++++++++++++ app/static/js/auth/notme.js | 4 ++-- 6 files changed, 70 insertions(+), 9 deletions(-) create mode 100644 app/modules/public/notme.py create mode 100644 app/pages/email/message.html create mode 100644 app/pages/public/notme.html diff --git a/app/handler.py b/app/handler.py index 86912b4..094627b 100644 --- a/app/handler.py +++ b/app/handler.py @@ -15,6 +15,7 @@ import templates.postcard.main as template_email import modules.public.home as public_home import modules.public.register as public_register +import modules.public.notme as public_notme import modules.api.auth as api_auth @@ -39,6 +40,14 @@ def index(roles): } return public_register.register().html(params) +@app.route('/notme', method='GET') +def index(): + params = { + "mako" : { + "website" : template_public.main(directory.page["public"], "notme") + } + } + return public_notme.notme().html(params) @app.route('/api/auth/registration/register/', method='POST') def index(roles): @@ -53,3 +62,16 @@ def index(roles): except Exception as e: print(str(e)) return json.dumps({}, indent = 2).encode() + +@app.route('/api/auth/registration/notme', method='POST') +def index(): + try: + params = request.json + params["mako" ] = { + "email" : template_email.main(directory.page["email"], "message") + } + response.content_type = 'application/json' + return json.dumps(api_auth.auth().notme(params), indent = 2).encode() + except Exception as e: + print(str(e)) + return json.dumps({}, indent = 2).encode() diff --git a/app/modules/api/auth.py b/app/modules/api/auth.py index a4f17cc..6e84805 100644 --- a/app/modules/api/auth.py +++ b/app/modules/api/auth.py @@ -255,16 +255,13 @@ class auth: self.cursor.execute("BEGIN;") try: loggorilla.prcss(APIADDR, "Decrypt token") - # TODO: Config SSH key for tokenguard payload = tokenguard.decode(token_encrypt, globalvar.ssh['key']['public']) token = payload['token'] - loggorilla.prcss(APIADDR, "Get dependency data") self.cursor.execute(f"SELECT COUNT(*) AS `count`, auth_profile_verification.verified FROM auth_profile_verification INNER JOIN auth_profile ON auth_profile.id = auth_profile_verification.auth_profile WHERE auth_profile.token = %s AND auth_profile_verification.type = 'email' ; ", (token,) ) result_verification = self.cursor.fetchone() self.cursor.execute("SELECT COUNT(*) AS `count`, token, id, email FROM auth_profile WHERE token = %s ; ", (token,) ) result_profile = self.cursor.fetchone() - loggorilla.prcss(APIADDR, "Validation") if result_verification['verified'] == 1: response["status" ] = "failed" @@ -280,11 +277,10 @@ class auth: self.smtpconfig['subject' ] = f"{globalvar.title} - Thanks for the reporting" self.smtpconfig['to' ] = result_profile['email'] self.smtpconfig['text' ] = "Thanks for your report. Now your data will be deleted from our system." - self.smtpconfig['html' ] = Template(params["mako"]["email"]['template']).render( + self.smtpconfig['html' ] = Template(params["mako"]["email"]['index']).render( title = globalvar.title, - heading = self.smtpconfig['subject'], - image = "https://colorlib.com/etc/email-template/10/images/email.png", - unsubscribe = "#", + header = globalvar.title, + copyright = globalvar.copyright, container = Template(params["mako"]["email"]['container']).render( message = "Thanks for your report. Now your data will be deleted from our system." ) diff --git a/app/modules/public/notme.py b/app/modules/public/notme.py new file mode 100644 index 0000000..7c7053c --- /dev/null +++ b/app/modules/public/notme.py @@ -0,0 +1,28 @@ +import mysql.connector as mariadb +from mako.template import Template +from config import globalvar, database + +class notme: + + def __init__(self): + self.db_main = mariadb.connect(**database.db_main) + self.cursor = self.db_main.cursor(dictionary=True) + self.user_roles = [0] # Cari user roles disini + + def html(self, params): + active_page = None + return Template(params["mako"]["website"]['index']).render( + title = globalvar.title, + header = globalvar.header, + navbar = Template(params["mako"]["website"]['navbar']).render( + menu = globalvar.menu['public']['navbar'], + user_roles = self.user_roles, + active_page = active_page + ), + footer = Template(params["mako"]["website"]['footer']).render( + copyright = globalvar.copyright, + ), + container = Template(params["mako"]["website"]['container']).render( + title = globalvar.title + ) + ) diff --git a/app/pages/email/message.html b/app/pages/email/message.html new file mode 100644 index 0000000..c0e5212 --- /dev/null +++ b/app/pages/email/message.html @@ -0,0 +1 @@ +

${message}

diff --git a/app/pages/public/notme.html b/app/pages/public/notme.html new file mode 100644 index 0000000..cc86dc4 --- /dev/null +++ b/app/pages/public/notme.html @@ -0,0 +1,14 @@ +

Not me

+ + + +

I hereby declare that I have never registered with ${title} and will delete the data that uses my email

+ + + + + diff --git a/app/static/js/auth/notme.js b/app/static/js/auth/notme.js index 28839d8..ebab172 100644 --- a/app/static/js/auth/notme.js +++ b/app/static/js/auth/notme.js @@ -29,8 +29,8 @@ function notme() { const queryString = window.location.search; const urlParams = new URLSearchParams(queryString); const token = urlParams.get('token') - var url = "/api/auth/registration/notme"; - var payload = { + var url = "/api/auth/registration/notme"; + var payload = { "token" : token }; sendHttpRequest(url, "POST", payload, function (error, response) {