mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
got login working
This commit is contained in:
parent
85a69954ea
commit
25affba2e6
@ -140,6 +140,11 @@ class Helpers:
|
||||
except:
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def get_time_as_string():
|
||||
now = datetime.now()
|
||||
return now.strftime("%m/%d/%Y, %H:%M:%S")
|
||||
|
||||
@staticmethod
|
||||
def check_file_exists(path: str):
|
||||
logger.debug('Looking for path: {}'.format(path))
|
||||
|
@ -92,7 +92,8 @@ class db_builder:
|
||||
Webhooks
|
||||
])
|
||||
|
||||
def default_settings(self):
|
||||
@staticmethod
|
||||
def default_settings():
|
||||
Users.insert({
|
||||
Users.username: 'Admin',
|
||||
Users.password: helper.encode_pass('asdfasdf'),
|
||||
@ -100,4 +101,11 @@ class db_builder:
|
||||
Users.enabled: True
|
||||
}).execute()
|
||||
|
||||
@staticmethod
|
||||
def is_fresh_install():
|
||||
if helper.check_file_exists(helper.db_path):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
installer = db_builder()
|
||||
|
37
app/classes/web/panel_handler.py
Normal file
37
app/classes/web/panel_handler.py
Normal file
@ -0,0 +1,37 @@
|
||||
import json
|
||||
import logging
|
||||
import tornado.web
|
||||
import tornado.escape
|
||||
import bleach
|
||||
|
||||
from app.classes.shared.console import console
|
||||
from app.classes.shared.models import Users
|
||||
from app.classes.web.base_handler import BaseHandler
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class PanelHandler(BaseHandler):
|
||||
|
||||
@tornado.web.authenticated
|
||||
def get(self, page):
|
||||
# name = tornado.escape.json_decode(self.current_user)
|
||||
user_data = json.loads(self.get_secure_cookie("user_data"))
|
||||
|
||||
template = "panel/denied.html"
|
||||
|
||||
page_data = {
|
||||
'version_data': "version_data_here",
|
||||
'user_data': user_data
|
||||
}
|
||||
|
||||
if page == 'unauthorized':
|
||||
template = "panel/denied.html"
|
||||
|
||||
elif page == 'dashboard':
|
||||
template = "panel/dashboard.html"
|
||||
|
||||
self.render(
|
||||
template,
|
||||
data=page_data
|
||||
)
|
@ -1,4 +1,5 @@
|
||||
import sys
|
||||
import json
|
||||
import logging
|
||||
import tornado.web
|
||||
import tornado.escape
|
||||
@ -6,6 +7,7 @@ import tornado.escape
|
||||
from app.classes.shared.helpers import helper
|
||||
from app.classes.web.base_handler import BaseHandler
|
||||
from app.classes.shared.console import console
|
||||
from app.classes.shared.models import Users, fn
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -29,7 +31,7 @@ class PublicHandler(BaseHandler):
|
||||
expire_days = "5"
|
||||
|
||||
if user:
|
||||
self.set_secure_cookie("user", tornado.escape.json_encode(user), expires_days=expire_days)
|
||||
self.set_secure_cookie("user", tornado.escape.json_encode(user), expires_days=int(expire_days))
|
||||
else:
|
||||
self.clear_cookie("user")
|
||||
|
||||
@ -40,9 +42,6 @@ class PublicHandler(BaseHandler):
|
||||
|
||||
# print(page)
|
||||
|
||||
if page is None:
|
||||
self.redirect("public/login")
|
||||
|
||||
error = bleach.clean(self.get_argument('error', ""))
|
||||
|
||||
if error:
|
||||
@ -50,53 +49,69 @@ class PublicHandler(BaseHandler):
|
||||
else:
|
||||
error_msg = ""
|
||||
|
||||
# sensible defaults
|
||||
template = "public/404.html"
|
||||
page_data = "{}"
|
||||
|
||||
# if we have no page, let's go to login
|
||||
if page is None:
|
||||
self.redirect("public/login")
|
||||
|
||||
if page == "login":
|
||||
template = "public/login.html"
|
||||
context = {'error': error_msg}
|
||||
page_data = {'error': error_msg}
|
||||
|
||||
# our default 404 template
|
||||
else:
|
||||
context = {'error': error_msg}
|
||||
page_data = {'error': error_msg}
|
||||
|
||||
self.render(template, data=context)
|
||||
self.render(template, data=page_data)
|
||||
|
||||
def post(self, page=None):
|
||||
|
||||
if page == 'login':
|
||||
next_page = "/public/login"
|
||||
|
||||
entered_email = bleach.clean(self.get_argument('email'))
|
||||
entered_username = bleach.clean(self.get_argument('username'))
|
||||
entered_password = bleach.clean(self.get_argument('password'))
|
||||
|
||||
user_data = Users.get_or_none(Users.email_address == entered_email)
|
||||
user_data = Users.get_or_none(fn.Lower(Users.username) == entered_username.lower())
|
||||
|
||||
# if we already have a user with this email...
|
||||
# if we don't have a user
|
||||
if not user_data:
|
||||
next_page = "/public/login?error=Login_Failed"
|
||||
self.redirect(next_page)
|
||||
return False
|
||||
|
||||
# if they are disabled
|
||||
if not user_data.enabled:
|
||||
next_page = "/public/login?error=Login_Failed"
|
||||
self.redirect(next_page)
|
||||
return False
|
||||
|
||||
login_result = helper.verify_pass(entered_password, user_data.password)
|
||||
|
||||
# Valid Login
|
||||
if login_result:
|
||||
self.set_current_user(entered_email)
|
||||
logger.info("User: {} Logged in from IP: {}".format(entered_email, self.get_remote_ip()))
|
||||
self.set_current_user(entered_username)
|
||||
logger.info("User: {} Logged in from IP: {}".format(user_data, self.get_remote_ip()))
|
||||
|
||||
# record this login
|
||||
Users.update({
|
||||
Users.last_ip: self.get_remote_ip()
|
||||
}).execute()
|
||||
Users.last_ip: self.get_remote_ip(),
|
||||
Users.last_login: helper.get_time_as_string()
|
||||
}).where(Users.username == entered_username).execute()
|
||||
|
||||
cookie_data = {
|
||||
"user_email": user_data.email_address,
|
||||
"user_id": user_data,
|
||||
"account_type": str(user_data.account_type).upper(),
|
||||
"username": user_data.username,
|
||||
"user_id": user_data.id,
|
||||
"account_type": user_data.allowed_servers,
|
||||
|
||||
}
|
||||
|
||||
self.set_secure_cookie('user_data', json.dumps(cookie_data))
|
||||
|
||||
next_page = "/pro/dashboard"
|
||||
next_page = "/panel/dashboard"
|
||||
self.redirect(next_page)
|
||||
else:
|
||||
self.redirect("/public/login")
|
||||
|
@ -19,6 +19,7 @@ try:
|
||||
import tornado.locale
|
||||
import tornado.httpserver
|
||||
from app.classes.web.public_handler import PublicHandler
|
||||
from app.classes.web.panel_handler import PanelHandler
|
||||
|
||||
except ModuleNotFoundError as e:
|
||||
logger.critical("Import Error: Unable to load {} module".format(e, e.name))
|
||||
@ -118,6 +119,7 @@ class webserver:
|
||||
handlers = [
|
||||
(r'/', PublicHandler),
|
||||
(r'/public/(.*)', PublicHandler),
|
||||
(r'/panel/(.*)', PanelHandler),
|
||||
]
|
||||
|
||||
app = tornado.web.Application(
|
||||
|
@ -44,7 +44,7 @@
|
||||
<div class="dropdown-menu dropdown-menu-right navbar-dropdown" aria-labelledby="UserDropdown">
|
||||
<div class="dropdown-header text-center">
|
||||
<img class="img-md rounded-circle" src="/static/assets/images/faces-clipart/pic-1.png" alt="Profile image">
|
||||
<p class="mb-1 mt-3 font-weight-semibold">{{ data['user_data']['user_email'] }}</p>
|
||||
<p class="mb-1 mt-3 font-weight-semibold">{{ data['user_data']['username'] }}</p>
|
||||
<p class="font-weight-light text-muted mb-0">Plan: {{ str(data['user_data']['account_type']).upper() }}</p>
|
||||
</div>
|
||||
<a class="dropdown-item"><i class="dropdown-item-icon mdi mdi-account-outline text-primary"></i> My Profile <span class="badge badge-pill badge-danger">1</span></a>
|
250
app/frontend/templates/panel/dashboard.html
Normal file
250
app/frontend/templates/panel/dashboard.html
Normal file
@ -0,0 +1,250 @@
|
||||
{% extends ../base.html %}
|
||||
|
||||
{% block title %}Crafty Controller - Dashboard{% end %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="content-wrapper">
|
||||
|
||||
<!-- Page Title Header Starts-->
|
||||
<div class="row page-title-header">
|
||||
<div class="col-12">
|
||||
<div class="page-header">
|
||||
<h4 class="page-title">Dashboard</h4>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<!-- Page Title Header Ends-->
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12 grid-margin">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col-lg-3 col-md-6">
|
||||
<div class="d-flex">
|
||||
<div class="wrapper">
|
||||
<h5 class="mb-1 font-weight-medium text-primary"> Nodes</h5>
|
||||
<h3 class="mb-0 font-weight-semibold">2 </h3>
|
||||
|
||||
|
||||
</div>
|
||||
<div class="wrapper my-auto ml-auto ml-lg-4">
|
||||
<p class="mb-0 text-success">1 Online</p>
|
||||
<p class="mb-0 text-danger">1 Offline</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-3 col-md-6 mt-md-0 mt-4">
|
||||
<div class="d-flex">
|
||||
<div class="wrapper">
|
||||
<h5 class="mb-1 font-weight-medium text-primary">Servers</h5>
|
||||
<h3 class="mb-0 font-weight-semibold">5</h3>
|
||||
|
||||
</div>
|
||||
<div class="wrapper my-auto ml-auto ml-lg-4">
|
||||
<p class="mb-0 text-success">3 Online</p>
|
||||
<p class="mb-0 text-warning">1 Shutdown</p>
|
||||
<p class="mb-0 text-danger">1 Crashed</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-3 col-md-6 mt-md-0 mt-4">
|
||||
<div class="d-flex">
|
||||
<div class="wrapper">
|
||||
<h5 class="mb-1 font-weight-medium text-primary">Players</h5>
|
||||
<h3 class="mb-0 font-weight-semibold">18</h3>
|
||||
|
||||
</div>
|
||||
<div class="wrapper my-auto ml-auto ml-lg-4">
|
||||
<p class="mb-0 text-success">35 Max (24 H)</p>
|
||||
<p class="mb-0 text-warning">10 Avg (24 H)</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-3 col-md-6 mt-md-0 mt-4">
|
||||
<div class="d-flex">
|
||||
<div class="wrapper">
|
||||
|
||||
<h5 class="mb-1 font-weight-medium text-primary">Backups</h5>
|
||||
<h3 class="mb-0 font-weight-semibold">7</h3>
|
||||
</div>
|
||||
<div class="wrapper my-auto ml-auto ml-lg-4">
|
||||
<p class="mb-0 text-success">Last: 11-31-2020</p>
|
||||
<p class="mb-0 text-success">Next: 12-05-2020</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12 col-lg-12 grid-margin stretch-card">
|
||||
<div class="card">
|
||||
<div class="card-header header-sm d-flex justify-content-between align-items-center">
|
||||
<h4 class="card-title">All Servers</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
|
||||
<div class="table-responsive">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr class="rounded">
|
||||
<th>Server</th>
|
||||
<th>CPU</th>
|
||||
<th>Memory</th>
|
||||
<th>Disk</th>
|
||||
<th>Players</th>
|
||||
<th>Status</th>
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<i class="fas fa-server"></i> Bedwarz </td>
|
||||
<td>
|
||||
<div class="progress">
|
||||
<div class="progress-bar bg-success" role="progressbar" style="width: 24%" aria-valuenow="24" aria-valuemin="0" aria-valuemax="100"></div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div class="progress">
|
||||
<div class="progress-bar bg-danger" role="progressbar" style="width: 85%" aria-valuenow="24" aria-valuemin="0" aria-valuemax="100"></div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div class="progress">
|
||||
<div class="progress-bar bg-warning" role="progressbar" style="width: 75%" aria-valuenow="24" aria-valuemin="0" aria-valuemax="100"></div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
7
|
||||
</td>
|
||||
<td>
|
||||
<i class="fas fa-thumbs-up"></i> <span class="text-success">Online</span>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
<i class="fas fa-server"></i> Lobby </td>
|
||||
<td>
|
||||
<div class="progress">
|
||||
<div class="progress-bar bg-warning" role="progressbar" style="width: 60%" aria-valuenow="24" aria-valuemin="0" aria-valuemax="100"></div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div class="progress">
|
||||
<div class="progress-bar bg-danger" role="progressbar" style="width: 85%" aria-valuenow="24" aria-valuemin="0" aria-valuemax="100"></div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div class="progress">
|
||||
<div class="progress-bar bg-success" role="progressbar" style="width: 40%" aria-valuenow="24" aria-valuemin="0" aria-valuemax="100"></div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
3
|
||||
</td>
|
||||
<td>
|
||||
<i class="fas fa-thumbs-up"></i> <span class="text-success">Online</span>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
<i class="fas fa-server"></i> Bedwarz </td>
|
||||
<td>
|
||||
<div class="progress">
|
||||
<div class="progress-bar bg-success" role="progressbar" style="width: 10%" aria-valuenow="24" aria-valuemin="0" aria-valuemax="100"></div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div class="progress">
|
||||
<div class="progress-bar bg-success" role="progressbar" style="width: 12%" aria-valuenow="24" aria-valuemin="0" aria-valuemax="100"></div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div class="progress">
|
||||
<div class="progress-bar bg-success" role="progressbar" style="width: 40%" aria-valuenow="24" aria-valuemin="0" aria-valuemax="100"></div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
0
|
||||
</td>
|
||||
<td>
|
||||
<i class="fas fa-thumbs-up"></i> <span class="text-success">Online</span>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
<i class="fas fa-server"></i> Creative </td>
|
||||
<td>
|
||||
<div class="progress">
|
||||
<div class="progress-bar bg-warning" role="progressbar" style="width: 60%" aria-valuenow="24" aria-valuemin="0" aria-valuemax="100"></div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div class="progress">
|
||||
<div class="progress-bar bg-danger" role="progressbar" style="width: 85%" aria-valuenow="24" aria-valuemin="0" aria-valuemax="100"></div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div class="progress">
|
||||
<div class="progress-bar bg-success" role="progressbar" style="width: 40%" aria-valuenow="24" aria-valuemin="0" aria-valuemax="100"></div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
5
|
||||
</td>
|
||||
<td>
|
||||
<i class="fas fa-thumbs-up"></i> <span class="text-success">Online</span>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
<i class="fas fa-server"></i> Survival </td>
|
||||
<td>
|
||||
<div class="progress">
|
||||
<div class="progress-bar bg-warning" role="progressbar" style="width: 15%" aria-valuenow="15" aria-valuemin="0" aria-valuemax="100"></div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div class="progress">
|
||||
<div class="progress-bar bg-danger" role="progressbar" style="width: 85%" aria-valuenow="24" aria-valuemin="0" aria-valuemax="100"></div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div class="progress">
|
||||
<div class="progress-bar bg-success" role="progressbar" style="width: 40%" aria-valuenow="24" aria-valuemin="0" aria-valuemax="100"></div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
3
|
||||
</td>
|
||||
<td>
|
||||
<i class="fas fa-thumbs-up"></i> <span class="text-success">Online</span>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<!-- content-wrapper ends -->
|
||||
|
||||
|
||||
|
||||
{% end %}
|
@ -33,9 +33,9 @@
|
||||
<form action="/public/login" method="post">
|
||||
{% raw xsrf_form_html() %}
|
||||
<div class="form-group">
|
||||
<label class="label">Email</label>
|
||||
<label class="label">Username</label>
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control" placeholder="user@example.com" name="email" id="email" required="true">
|
||||
<input type="text" class="form-control" placeholder="username" name="username" id="username" required="true">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
|
Loading…
Reference in New Issue
Block a user