Login and Session features
This commit is contained in:
parent
b64f53ea0e
commit
8d7eefb2e2
@ -17,6 +17,7 @@ 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.public.login as public_login
|
||||
|
||||
import modules.api.auth as api_auth
|
||||
|
||||
@ -59,6 +60,15 @@ def index():
|
||||
}
|
||||
return public_verify.verify().html(params)
|
||||
|
||||
@app.route('/login')
|
||||
def index():
|
||||
params = {
|
||||
"mako" : {
|
||||
"website" : template_public.main(directory.page["public"], "login")
|
||||
}
|
||||
}
|
||||
return public_login.login().html(params)
|
||||
|
||||
@app.route('/api/auth/registration/register/<roles>', method='POST')
|
||||
def index(roles):
|
||||
try:
|
||||
@ -113,3 +123,24 @@ def index():
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
return json.dumps({}, indent = 2).encode()
|
||||
|
||||
@app.route('/api/auth/login', method='POST')
|
||||
def index():
|
||||
try:
|
||||
params = request.json
|
||||
response.content_type = 'application/json'
|
||||
return json.dumps(api_auth.auth().login(params), indent = 2).encode()
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
return json.dumps({}, indent = 2).encode()
|
||||
|
||||
@app.route('/api/auth/session/<type>', method='POST')
|
||||
def index(type):
|
||||
try:
|
||||
params = request.json
|
||||
params["type"] = type
|
||||
response.content_type = 'application/json'
|
||||
return json.dumps(api_auth.auth().session(params), indent = 2).encode()
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
return json.dumps({}, indent = 2).encode()
|
||||
|
@ -419,10 +419,8 @@ class auth:
|
||||
response = {}
|
||||
type = params["type" ] # set / check / out
|
||||
jwt = params["jwt" ]
|
||||
|
||||
payload = tokenguard.decode(jwt, globalvar.ssh['key']['public'])
|
||||
session_id = payload["session"]["id"]
|
||||
|
||||
try:
|
||||
session_beaker = request.environ.get('beaker.session')
|
||||
if type == 'set':
|
||||
|
26
app/modules/public/login.py
Normal file
26
app/modules/public/login.py
Normal file
@ -0,0 +1,26 @@
|
||||
import mysql.connector as mariadb
|
||||
from mako.template import Template
|
||||
from config import globalvar, database
|
||||
|
||||
class login:
|
||||
|
||||
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 = "Login"
|
||||
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()
|
||||
)
|
13
app/pages/public/login.html
Normal file
13
app/pages/public/login.html
Normal file
@ -0,0 +1,13 @@
|
||||
<h1>Login</h1>
|
||||
|
||||
<script type="text/javascript" src="/js/carrack.js"></script>
|
||||
|
||||
<input required type="text" id="form-username" placeholder="Username" > <br>
|
||||
<input required type="password" id="form-password" placeholder="Password" > <br>
|
||||
<button type="button" onclick="onSubmit()">Login</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/login.js"></script>
|
@ -21,7 +21,7 @@ function responseSession(response) {
|
||||
document.getElementById("alert-desc" ).innerHTML = "Welcome!";
|
||||
document.getElementById("alert-response").classList.add('alert-success');
|
||||
document.getElementById("alert-response").style.display = 'block';
|
||||
window.location.replace("/portal/dashboard?msg=Welcome");
|
||||
window.location.replace("/?msg=Welcome");
|
||||
}
|
||||
else {
|
||||
document.getElementById("alert-desc" ).innerHTML = "Internal error";
|
||||
|
Loading…
Reference in New Issue
Block a user