From 82f0e8442864cfdbe761282777b3eb6e6e12c5de Mon Sep 17 00:00:00 2001 From: ditaajipratama Date: Tue, 18 Jun 2024 23:36:54 +0700 Subject: [PATCH] Verify features --- app/handler.py | 23 +++++++++++++++++++++++ app/modules/api/auth.py | 8 +++----- app/modules/public/verify.py | 26 ++++++++++++++++++++++++++ app/pages/public/verify.html | 9 +++++++++ 4 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 app/modules/public/verify.py create mode 100644 app/pages/public/verify.html diff --git a/app/handler.py b/app/handler.py index 6655471..1932390 100644 --- a/app/handler.py +++ b/app/handler.py @@ -16,6 +16,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.public.verify as public_verify import modules.api.auth as api_auth @@ -49,6 +50,15 @@ def index(): } return public_notme.notme().html(params) +@app.route('/verify', method='GET') +def index(): + params = { + "mako" : { + "website" : template_public.main(directory.page["public"], "verify") + } + } + return public_verify.verify().html(params) + @app.route('/api/auth/registration/register/', method='POST') def index(roles): try: @@ -90,3 +100,16 @@ def index(): except Exception as e: print(str(e)) return json.dumps({}, indent = 2).encode() + +@app.route('/api/auth/registration/verify', 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().verify(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 469735f..e32b94c 100644 --- a/app/modules/api/auth.py +++ b/app/modules/api/auth.py @@ -306,7 +306,6 @@ 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'] expired = datetime.datetime.fromisoformat(payload['expired']) @@ -339,11 +338,10 @@ class auth: self.smtpconfig['to' ] = result_profile['email'] self.smtpconfig['text' ] = f"Welcome. Now your account is verified." loggorilla.fyinf(APIADDR, "2") - 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 = "Welcome. Now your account is verified." ) diff --git a/app/modules/public/verify.py b/app/modules/public/verify.py new file mode 100644 index 0000000..922ba0c --- /dev/null +++ b/app/modules/public/verify.py @@ -0,0 +1,26 @@ +import mysql.connector as mariadb +from mako.template import Template +from config import globalvar, database + +class verify: + + 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() + ) diff --git a/app/pages/public/verify.html b/app/pages/public/verify.html new file mode 100644 index 0000000..40ec7ab --- /dev/null +++ b/app/pages/public/verify.html @@ -0,0 +1,9 @@ +

Verify

+ + + + + +