add login and register forms

This commit is contained in:
Izalia Mae 2021-08-17 17:15:00 -04:00
parent 6d42b95df5
commit 43b2a5a6a3
11 changed files with 123 additions and 19 deletions

16
dist/production.env vendored Normal file
View file

@ -0,0 +1,16 @@
# Server settings
SYNC_LISTEN=localhost
SYNC_PORT=8080
SYNC_HOST=localhost:8080
#SYNC_ALT_HOSTS=sync.example.com,example.com
SYNC_PROTO=http
SYNC_LOG_LEVEL=info
# Database settings
SYNC_DB_TYPE=sqlite
SYNC_DB_HOST=/var/run/postgresql
SYNC_DB_PORT=5432
SYNC_DB_NAME=pywebsync
SYNC_DB_USER=pywebsync
SYNC_DB_PASS=changeme
SYNC_DB_SSL=False

View file

@ -0,0 +1,3 @@
__software__ = 'PyWeb Sync Server'
__author__ = 'Zoey Mae'
__version__ = '0.0.1'

View file

@ -1,3 +1,6 @@
import getpass, sys
from envbash import load_envbash
from os import getcwd, environ as env
from izzylib import DotDict, Path, logging
@ -12,4 +15,41 @@ path = DotDict(
)
path.data.mkdir()
logging.set_config('level', env.get('LOG_LEVEL', 'info'))
try:
load_envbash(path.data.join('production.env'))
except FileNotFoundError:
logging.warning('No environment file found. Creating a new one and exiting')
with path.data.join('production.env').open('w') as fd:
fd.write(f"""# Server settings
SYNC_LISTEN=localhost
SYNC_PORT=8080
SYNC_HOST=localhost:8080
#SYNC_ALT_HOSTS=example.com,sync.example.com
SYNC_PROTO=http
SYNC_LOG_LEVEL=info
# Database settings
SYNC_DB_TYPE=sqlite
SYNC_DB_HOST=/var/run/postgresql
SYNC_DB_PORT=5432
SYNC_DB_NAME=pywebsync
SYNC_DB_USER={getpass.getuser()}
SYNC_DB_PASS=changeme
SYNC_DB_SSL=False
""")
sys.exit()
config = DotDict(
listen = env.get('SYNC_LISTEN', 'localhost'),
port = int(env.get('SYNC_PORT', 8080)),
proto = env.get('SYNC_PROTO', 'http'),
workers = int(env.get('SYNC_WORKERS', 1)),
alt_hosts = env.get('SYNC_ALT_HOSTS', '').split(',')
)
config.host = env.get('SYNC_HOST', f'{config.listen}:{config.port}')
logging.set_config('level', env.get('SYNC_LOG_LEVEL', 'info'))

View file

@ -1,4 +1,15 @@
-extends 'base.haml'
-set page = 'Login'
-block head
%link rel='stylesheet' type='text/css' href='{{cfg.proto}}://{{cfg.web_host}}/style/logreg_form.css'
-block content
#title -> =page
%form(action='{{cfg.proto}}://{{cfg.web_host}}/login', method='post')
%center
%input(type='text', name='username', placeholder='username')
%br
%input(type='password', name='password', placeholder='password'})
%br
%input(type='submit', value='submit', class='button')

View file

@ -1,4 +1,18 @@
-extends 'base.haml'
-set page = 'Register'
-extends "base.haml"
-set page = "Register"
-block head
%link rel='stylesheet' type='text/css' href='{{cfg.proto}}://{{cfg.web_host}}/style/logreg_form.css'
-block content
#title -> =page
%form(action="https://{{cfg.web_host}}/register", method="post", autocomplete="new-password")
%center
%input(type="text", name="username", placeholder="username")
%br
%input(type="text", name="password", placeholder="password")
%br
%input(type="text", name="password2", placeholder="password again")
%br
%input(type="submit", value="submit", class="button")

View file

@ -0,0 +1,15 @@
input {
padding: 3px;
text-align: center;
border-radius: 5px;
}
input[type='submit'] {
margin-top: 5px;
}
input:not([type='submit']) {
width: 75%;
margin-top: 5px;
margin-bottom: 5px;
}

View file

@ -1,29 +1,32 @@
from izzylib.http_server import Application
from izzylib.http_server import Application, View
from os import environ as env
from .config import path
from .views import Home, Register, Login, Logout, Account, Admin
from . import views, __software__, __version__
from .config import config, path
app = Application(
listen = '192.168.2.5',
port = 3621,
name = 'PyWeb Sync Server',
name = __software__,
version = __version__,
git_repo = 'https://git.barkshark.xyz/izaliamae/pyweb-sync',
host = 'relaydev.barkshark.xyz',
proto = 'https',
tpl_search = [path.frontend]
tpl_search = [path.frontend],
**config
)
## Frontend
app.add_class_route(Home)
app.add_class_route(Register)
app.add_class_route(Login)
app.add_class_route(Logout)
app.add_class_route(Account)
app.add_class_route(Admin)
for cls in dir(views):
view = getattr(views, cls)
try:
view.paths
app.add_class_route(view)
except AttributeError:
pass
app.static('/static', path.frontend.join('static'))
app.static('/style', path.frontend.join('style'))
## Api

View file

@ -0,0 +1 @@
from .frontend import Home, Register, Login, Logout, Account, Admin

1
pyweb_sync/views/api.py Normal file
View file

@ -0,0 +1 @@

View file

@ -10,7 +10,7 @@
"ignore_dirs": [
"build",
"config",
"data"
"dist"
],
"ignore_files": [
"reload.py",