multiple fixes and start on account page

This commit is contained in:
Izalia Mae 2020-02-21 02:59:09 -05:00
parent 0e158e7f03
commit a896c11642
20 changed files with 126 additions and 52 deletions

View file

@ -12,7 +12,7 @@ Note: Still need to figure out all the dependencies
### Python
pip install -r requirements.txt
python3 -m pip install -r requirements.txt
Note: Run this after installing pyenv
@ -38,7 +38,7 @@ Create a postgresql user if you haven't already
Run the relay to generate a default environment file and then edit it if necessary
./relay.py
python3 -m relay
$EDITOR data/production.env
Copy the link in the terminal output and paste it in your browser to setup the rest of the relay. A new link will be displayed once you restart the relay to setup an admin account
Copy the link in the terminal output and paste it in your browser to setup the rest of the relay. A new link will be displayed once you restart the relay to setup an admin account

View file

@ -1,17 +0,0 @@
#!/usr/bin/env python3
import sys
v = sys.version_info
try:
assert v >= (3,6)
except:
print('Your version of python ({}.{}) is too old'.format(v[0], v[1]))
print('Please upgrade to at least 3.6')
sys.exit()
from uncia.server import main
main()

View file

@ -1,5 +1,5 @@
exec = python relay.py
exec = python3 -m uncia
watch_ext = py, env
ignore_dirs = build
ignore_files = reload.py, test.py
ignore_files = reload.py, test.py, setup.py
log_level = INFO

View file

@ -1 +1,9 @@
print('Running via \'python -m uncia\' is disabled. Run \'python relay.py\' instead.')
#!/usr/bin/env python3
import sys
from .server import main
try:
main()
except KeyboardInterrupt:
sys.exit()

View file

@ -1,4 +1,4 @@
import os, sys
import os, sys, random, string
from os import environ as env
from os.path import abspath, dirname, basename, isdir, isfile
@ -7,7 +7,7 @@ from envbash import load_envbash
pyv = sys.version_info
version = '0.9.0'
version = '0.9.1'
if getattr(sys, 'frozen', False):
@ -49,7 +49,7 @@ else:
#DBPORT=5432
#DBUSER=$USER
#DBPASS=
#DBTABLE=uncia
#DBNAME=uncia
#DBCONNUM=25
# Web forward config

View file

@ -172,8 +172,22 @@ def user(data, db=None):
@connection
def token(token, db=None):
return query('tokens', {'token': token})
def token(data, db=None):
if type(data) == str:
query_string = {'token': data}
elif type(data) == dict:
if 'token' in data.keys():
query_string = {'token': data['token']}
elif 'userid' in data.keys():
query_string = {'userid': data['userid']}
return query('tokens', query_string, one=False)
else:
return
return query('tokens', query_string)
@connection

View file

@ -24,9 +24,6 @@ def config(data, db=None):
continue
if not configs or k not in configs:
logging.warning(f'heckie weckie\nkey: {k}')
continue
data = {
'key': k,
'value': value

View file

@ -1,6 +1,6 @@
{% set primary = '#C6C' %}
{% set secondary = '#68C' %}
{% set error = '#C64' %}
{% set error = '#D44' %}
{% set background = '#202020' %}
{% set text = '#DDD' %}
@ -12,7 +12,6 @@
--bg-color-lighter: {{lighten(background, 0.075)}};
--bg-dark: {{desaturate(darken(primary, 0.90), 0.5)}};
--primary: {{primary}};
--error: {{desaturate(darken('red', 0.2), 0.25)}};
--valid: {{desaturate(darken('green', 0.2), 0.25)}};
--shadow-color: {{rgba('black', 0.5)}};
@ -158,4 +157,11 @@ tr:not(.header):hover td a {
background-color: {{desaturate(darken(primary, 0.70), 0.2)}};
}
/* setup page */
.error {
color: {{error}};
background-color: {{desaturate(darken(error, 0.85), 0.50)}};
}
{% include 'layout.css' %}

View file

@ -326,6 +326,27 @@ tr:last-child .col2 {
}
/* setup page */
.error {
text-align: center;
font-weight: bold;
}
/* account page */
.account {
text-align: center;
}
.account input:not([type="submit"]) {
width: calc(100% - 20px);
}
.account input[type="submit"] {
min-width: 200px;
}
/* mobile/small screen */
@media (max-width : 1000px) {
#content {
@ -342,6 +363,10 @@ tr:last-child .col2 {
.stats .grid-container {
grid-template-columns: 33% 33% auto;
}
.account input[type="submit"] {
min-width: auto;
}
}
@media (max-width : 800px) {

View file

@ -0,0 +1,32 @@
- extends "base.html"
- set title = 'Login'
- block content
%div{'class': 'section account profile'}
%h2{'class': 'title'} Profile
%form{'action': 'https://{{config.host}}/admin/profile', 'method': 'post'}
%input{'type': 'text', 'name': 'displayname', 'placeholder': 'displayname'}
%br
%input{'type': 'text', 'name': 'username', 'placeholder': 'username'}
%br
%input{'type': 'submit', 'value': 'Submit'}
%div{'class': 'section account token'}
%h2{'class': 'title'} Tokens
%form{'action': 'https://{{config.host}}/admin/profile', 'method': 'post'}
%input{'type': 'text', 'name': 'displayname', 'placeholder': 'displayname'}
%br
%input{'type': 'text', 'name': 'username', 'placeholder': 'username'}
%br
%input{'type': 'submit', 'value': 'submit'}
%div{'class': 'section account password'}
%h2{'class': 'title'} Password
%form{'action': 'https://{{config.host}}/admin/profile/password', 'method': 'post'}
%input{'type': 'password', 'name': 'oldpassword', 'placeholder': 'old password'}
%br
%input{'type': 'password', 'name': 'password1', 'placeholder': 'new password'}
%br
%input{'type': 'password', 'name': 'password2', 'placeholder': 'new password again'}
%br
%input{'type': 'submit', 'value': 'Submit'}

View file

@ -45,10 +45,6 @@
-else
%a{'href': '/admin?page=settings', 'class': 'setmenu-item'}< Settings
-if msg
%div{'id': 'setmenu', 'class': 'section admin message'}
{{msg}}
-if page == 'instances'
%div{'class': 'section admin group instances'}
%p{'class': 'sec-header'} Instances

View file

@ -47,6 +47,10 @@
%h1{'id': 'name'}
{{config.name}}
-if msg
%div{'id': 'message', 'class': 'section'}
{{msg}}
-block content
%div{'class': 'section grid-container', 'id': 'footer'}

View file

@ -4,8 +4,6 @@
- block content
%div{'class': 'section', 'id': 'auth'}
%h2{'class': 'title'} Login
- if msg
{{msg}}
%form{'action': 'https://{{config.host}}/login', 'method': 'post'}
%input{'type': 'text', 'name': 'username', 'placeholder': 'username'}
%br

View file

@ -4,8 +4,6 @@
- block content
%div{'class': 'section', 'id': 'auth'}
%h2{'class': 'title'} Register
- if msg
{{msg}}
%form{'action': 'https://{{config.host}}/register', 'method': 'post', 'autocomplete': 'new-password'}
%input{'type': 'text', 'name': 'username', 'placeholder': 'username'}
%br

View file

@ -9,6 +9,10 @@
The relay has been successfully setup stopped. Please start the relay again and setup an admin account via the register url that shows up in the console log
- else
-if msg:
%div{'class': 'section setup error'}
{{msg}}
%div{'class': 'section setup'}
%p{'class': 'sec-header'} Setup
%p<

View file

@ -2,12 +2,14 @@ import sys
import logging as logger
import logging.config as logconf
from os import environ as env
def verb(self, message, *args, **kws):
if self.isEnabledFor(15):
self._log(15, message, args, **kws)
LOG_BASE = '%(asctime)s %(process)d %(levelname)s'
DATE_FMT = "%Y-%m-%d %H:%M:%S"
DATE_FMT = "%Y-%m-%d %H:%M:%S" if not env.get('INVOCATION_ID') else ''
LOG = dict(
version=1,

View file

@ -8,8 +8,8 @@ from datetime import datetime
from tinydb import TinyDB, Query
from configobj import ConfigObj
from uncia.config import stor_path
from uncia.database import db as pgdb, get, put
from .config import stor_path
from .database import db as pgdb, get, put
oldpath = abspath('config')

View file

@ -40,12 +40,14 @@ app.add_route(views.Nodeinfo.as_view(), '/nodeinfo/2.0.json')
# Register web frontend routes
app.add_route(views.Home.as_view(), '/')
app.add_route(views.Faq.as_view(), '/faq')
app.add_route(views.Account.as_view(), '/admin/account')
app.add_route(views.Account.as_view(), '/admin/account/<action>')
app.add_route(views.Admin.as_view(), '/admin')
#app.add_route(views.Cache.as_view(), '/admin/cache') # I probably don't need this anymore
app.add_route(views.Admin.as_view(), '/admin/<action>')
app.add_route(views.Login.as_view(), '/login')
app.add_route(views.Logout.as_view(), '/logout')
app.add_route(views.Register.as_view(), '/register')
#app.add_route(views.Cache.as_view(), '/admin/cache') # I probably don't need this anymore
# Register resources for web frontend
app.add_route(views.Style.as_view(), '/style-<timestamp>')

View file

@ -1,4 +1,4 @@
import codecs, traceback
import codecs, traceback, os
import ujson as json
from os import listdir

View file

@ -264,10 +264,11 @@ class Admin(HTTPMethodView):
class Account(HTTPMethodView):
async def get(self, request):
context = ['heck']
context = {}
return render('account.html', request, context)
async def post(self, requrest):
async def post(self, requrest, action=''):
action = re.sub(r'[^a-z]+', '', action.lower())
pass
@ -408,8 +409,8 @@ class Robots(HTTPMethodView):
class Setup(HTTPMethodView):
async def get(self, request, *args, **kwargs):
data = {'code': request['query'].get('code')}
async def get(self, request, *args, msg=None, **kwargs):
data = {'code': request['query'].get('code'), 'msg': msg}
return render('setup.html', request, data)
@ -417,9 +418,13 @@ class Setup(HTTPMethodView):
data = request['form']
if data.get('code') != get.auth_code:
return response.redirect('/setup')
return await self.get(request, msg='Invalid auth code')
msg = admin.run('settings', data)
if msg == str:
return await self.get(request, msg=msg)
admin.run('settings', data)
put.config({'setup': True})
return await self.get(request)