Notme features

This commit is contained in:
Dita Aji Pratama 2024-06-17 21:33:07 +07:00
parent bb29d00146
commit e8f0487e05
6 changed files with 70 additions and 9 deletions

View File

@ -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/<roles>', 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()

View File

@ -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."
)

View File

@ -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
)
)

View File

@ -0,0 +1 @@
<p>${message}</p>

View File

@ -0,0 +1,14 @@
<h1>Not me</h1>
<script type="text/javascript" src="/js/carrack.js"></script>
<p>I hereby declare that I have never registered with ${title} and will delete the data that uses my email</p>
<button id="notme-link" onclick="notme()">
Submit
</button>
<div id="alert-response" role="alert">
<b id="alert-status">Loading...</b> <span id="alert-desc">Please wait...</span>
</div>
<script type="text/javascript" src="/js/auth/notme.js"></script>

View File

@ -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) {