code cleanup and comments
This commit is contained in:
parent
016e52f1e7
commit
208e3a7b49
2
backend
2
backend
@ -1 +1 @@
|
||||
Subproject commit 1a5700e9a0bdc404d0d2a49898dba78d872b53e8
|
||||
Subproject commit 45cd71cc4bcddf23f46b1eddcffd8c7fda2b9d41
|
@ -1,38 +0,0 @@
|
||||
# http://flask.pocoo.org/docs/1.0/tutorial/database/
|
||||
import sqlite3
|
||||
|
||||
import click
|
||||
from flask import current_app, g
|
||||
from flask.cli import with_appcontext
|
||||
|
||||
def get_db():
|
||||
if "db" not in g:
|
||||
g.db = sqlite3.connect(
|
||||
"database/sqlite_db", detect_types=sqlite3.PARSE_DECLTYPES
|
||||
)
|
||||
g.db.row_factory = sqlite3.Row
|
||||
|
||||
return g.db
|
||||
|
||||
def close_db(e=None):
|
||||
db = g.pop("db/db", None)
|
||||
|
||||
if db is not None:
|
||||
db.close()
|
||||
|
||||
def init_db():
|
||||
db = get_db()
|
||||
|
||||
with current_app.open_resource("database/schema.sql") as f:
|
||||
db.executescript(f.read().decode("utf8"))
|
||||
|
||||
@click.command("init-db")
|
||||
@with_appcontext
|
||||
def init_db_command():
|
||||
"""Clear the existing data and create new tables."""
|
||||
init_db()
|
||||
click.echo("Initialized the database.")
|
||||
|
||||
def init_app(app):
|
||||
app.teardown_appcontext(close_db)
|
||||
app.cli.add_command(init_db_command)
|
@ -1,14 +0,0 @@
|
||||
CREATE TABLE user (
|
||||
id TEXT PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
email TEXT UNIQUE NOT NULL,
|
||||
profile_pic TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE calendar (
|
||||
usr_id TEXT NOT NULL,
|
||||
calendar_id TEXT PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
toggle TEXT,
|
||||
color TEXT
|
||||
);
|
@ -1,92 +0,0 @@
|
||||
from flask_login import UserMixin
|
||||
from pathlib import Path
|
||||
|
||||
from server.database.db import get_db
|
||||
|
||||
class User(UserMixin):
|
||||
def __init__(self, id_, name, email, profile_pic):
|
||||
self.id = id_
|
||||
self.name = name
|
||||
self.email = email
|
||||
self.profile_pic = profile_pic
|
||||
|
||||
@staticmethod
|
||||
def get(user_id):
|
||||
db = get_db()
|
||||
user = db.execute(
|
||||
"SELECT * FROM user WHERE id = ?", (user_id,)
|
||||
).fetchone()
|
||||
if not user:
|
||||
return None
|
||||
|
||||
user = User(
|
||||
id_=user[0], name=user[1], email=user[2], profile_pic=user[3]
|
||||
)
|
||||
return user
|
||||
|
||||
@staticmethod
|
||||
def create(id_, name, email, profile_pic):
|
||||
db = get_db()
|
||||
db.execute(
|
||||
"INSERT INTO user (id, name, email, profile_pic) "
|
||||
"VALUES (?, ?, ?, ?)",
|
||||
(id_, name, email, profile_pic),
|
||||
)
|
||||
db.commit()
|
||||
|
||||
Path(f"userinfo/{id_}").mkdir(parents=True, exist_ok=True)
|
||||
|
||||
class dbCalendar():
|
||||
def __init__(self, id_, name, toggle, color):
|
||||
self.usr_id = id_
|
||||
self.name = name
|
||||
self.toggle = toggle
|
||||
self.color = color
|
||||
|
||||
@staticmethod
|
||||
def getCalendars(user_id):
|
||||
db = get_db()
|
||||
calendars = db.execute(
|
||||
"SELECT * FROM calendar WHERE usr_id = ?", (user_id,)
|
||||
).fetchall()
|
||||
|
||||
return calendars
|
||||
|
||||
@staticmethod
|
||||
def getCalendar(user_id, calendar_id):
|
||||
db = get_db()
|
||||
calendar = db.execute(
|
||||
"SELECT * FROM calendar WHERE usr_id = ? AND calendar_id = ?", (user_id, calendar_id)
|
||||
).fetchone()
|
||||
|
||||
if not calendar:
|
||||
return None
|
||||
|
||||
return calendar
|
||||
|
||||
@staticmethod
|
||||
def updateCalendar(user_id, calendar_name, toggle=None, color=None):
|
||||
db = get_db()
|
||||
print("updating")
|
||||
if(toggle != None):
|
||||
print(toggle)
|
||||
db.execute(
|
||||
"UPDATE calendar SET toggle = ? WHERE usr_id = ? AND name = ?", (toggle, user_id, calendar_name)
|
||||
)
|
||||
db.commit()
|
||||
|
||||
if(color != None):
|
||||
db.execute(
|
||||
"UPDATE calendar SET color = ? WHERE usr_id = ? AND name = ?", (color, user_id, calendar_name)
|
||||
)
|
||||
db.commit()
|
||||
|
||||
@staticmethod
|
||||
def create(user_id, calendar_id, name, color, toggle = 'True'):
|
||||
db = get_db()
|
||||
db.execute(
|
||||
"INSERT INTO calendar (usr_id, calendar_id, name, toggle, color) "
|
||||
"VALUES (?, ?, ?, ?, ?)",
|
||||
(user_id, calendar_id, name, toggle, color),
|
||||
)
|
||||
db.commit()
|
@ -2,7 +2,7 @@ FROM python:3.8-slim-buster
|
||||
RUN apt-get update && apt-get upgrade
|
||||
RUN pip3 install flask Flask-SQLAlchemy flask_migrate flask_login flask_wtf python-dotenv
|
||||
RUN apt-get install gcc libpcre3 libpcre3-dev libmariadbclient-dev -y
|
||||
RUN pip3 install uwsgi email-validator random-word
|
||||
RUN pip3 install uwsgi email-validator RandomWords
|
||||
RUN pip3 install google google-oauth google-auth-oauthlib google-api-python-client mysqlclient
|
||||
COPY docker-entrypoint.sh /usr/local/bin/
|
||||
EXPOSE 8084
|
||||
|
@ -2,6 +2,4 @@
|
||||
from server import app
|
||||
|
||||
if __name__ == "__main__":
|
||||
context = ('certificate/xip.io.crt', 'certificate/xip.io.key')#certificate and key files
|
||||
# app.run('0.0.0.0', 8084, ssl_context='adhoc', debug=True)
|
||||
app.run(host='0.0.0.0', port=8084, debug=True)
|
||||
|
@ -4,12 +4,22 @@ from wtforms.validators import DataRequired, ValidationError, Email, EqualTo
|
||||
from database.models import User, Device
|
||||
import email_validator
|
||||
|
||||
'''
|
||||
LoginForm defines the flask form used for the
|
||||
email-based login procedure
|
||||
This Form is based on 'The Flask Mega-Tutorial'
|
||||
'''
|
||||
class LoginForm(FlaskForm):
|
||||
username = StringField('Username', validators=[DataRequired()])
|
||||
password = PasswordField('Password', validators=[DataRequired()])
|
||||
remember_me = BooleanField('Remember Me')
|
||||
submit = SubmitField('Sign In')
|
||||
|
||||
'''
|
||||
RegiatrationForm validates username, email and pw
|
||||
This Form is based on 'The Flask mega-Tutorial'
|
||||
'''
|
||||
|
||||
class RegistrationForm(FlaskForm):
|
||||
username = StringField('Username', validators=[DataRequired()])
|
||||
email = StringField('Email', validators=[DataRequired(), Email()])
|
||||
@ -31,7 +41,7 @@ class RegistrationForm(FlaskForm):
|
||||
class DeviceForm(FlaskForm):
|
||||
deviceName=StringField('New Device ID', validators=[DataRequired()])
|
||||
submit = SubmitField('Add New Device')
|
||||
|
||||
#
|
||||
def validate_deviceName (self, deviceName):
|
||||
device = Device.query.filter_by(deviceName=deviceName.data).first()
|
||||
if device is None:
|
||||
|
@ -25,7 +25,9 @@ import requests
|
||||
from database.models import Calendar as dbCalendar
|
||||
from backend import Calendar, Event
|
||||
|
||||
# Configuration
|
||||
# Configuration class for the google client
|
||||
# all necessary variables and secrets are defined in this
|
||||
# aswell as some helper functions
|
||||
class GoogleClient():
|
||||
def __init__(self):
|
||||
self.CLIENT_SECRETS_FILE = "certificate/client_secret.json"
|
||||
|
@ -13,7 +13,7 @@ from flask_login import (
|
||||
login_user,
|
||||
logout_user,
|
||||
)
|
||||
from random_word import RandomWords
|
||||
from random_words import RandomWords
|
||||
import requests
|
||||
|
||||
import server.googleHandler as google
|
||||
@ -74,18 +74,19 @@ def devices():
|
||||
|
||||
# if this is a post request from the 'unlink' submittion form
|
||||
# delete this device from the list
|
||||
form = DeviceForm()
|
||||
if request.method == 'POST':
|
||||
|
||||
if request.form.get("submit") == "Unlink":
|
||||
device = db.session.query(Device).filter(Device.deviceName==request.form.get("device")).first()
|
||||
db.session.delete(device)
|
||||
db.session.commit()
|
||||
|
||||
# if this is part of the device form
|
||||
form = DeviceForm()
|
||||
if form.validate_on_submit():
|
||||
device = db.session.query(Device).filter(Device.deviceName==form.deviceName.data).first()
|
||||
current_user.devices.append(device)
|
||||
db.session.commit()
|
||||
elif form.validate_on_submit():
|
||||
device = db.session.query(Device).filter(Device.deviceName==form.deviceName.data).first()
|
||||
current_user.devices.append(device)
|
||||
db.session.commit()
|
||||
|
||||
return flask.render_template('devices.html',
|
||||
devices=current_user.devices,
|
||||
@ -222,9 +223,7 @@ def generateDeviceFingerprint():
|
||||
while True:
|
||||
fingerprint = ""
|
||||
length = 3
|
||||
randos = r.get_random_words(limit=length, hasDictionaryDef="true",
|
||||
includePartOfSpeech="noun", minDictionaryCount=1,
|
||||
maxDictionaryCount=10, minLength=5, maxLength=10)
|
||||
randos = r.random_words(count=length)
|
||||
for i in range(len(randos)):
|
||||
fingerprint += randos[i]
|
||||
if i < length-1:
|
||||
|
10
server/static/res/daria-changelog.json
Normal file
10
server/static/res/daria-changelog.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"latestVersion": "1.0",
|
||||
"latestVersionCode": 1,
|
||||
"url": "https://longitudecalendar.com/static/res/daria-scan-1.0.apk",
|
||||
"releaseNotes": [
|
||||
"- First evolution",
|
||||
"- Second evolution",
|
||||
"- Bug fixes"
|
||||
]
|
||||
}
|
BIN
server/static/res/daria-scan-1.0.apk
Normal file
BIN
server/static/res/daria-scan-1.0.apk
Normal file
Binary file not shown.
@ -34,9 +34,9 @@
|
||||
<form action="" method="post">
|
||||
<div class="container grey" style="margin-top: 3rem;">
|
||||
<div>{{ form.hidden_tag() }}</div>
|
||||
<div style="width: 7rem; margin: 1rem">{{ form.deviceName.label }}</div>
|
||||
<div style="width: 12rem; margin: 1rem">{{ form.deviceName(size=24) }}</div>
|
||||
<div style="with: 7rem; margin: 1rem">{{ form.submit() }}</div>
|
||||
<div style="margin: 1rem">{{ form.deviceName.label }}</div>
|
||||
<div style="margin: 1rem">{{ form.deviceName(size=24) }}</div>
|
||||
<div style="with: 8rem; margin: 1rem">{{ form.submit() }}</div>
|
||||
{% for error in form.deviceName.errors %}
|
||||
<span style="color: red;">[{{ error }}]</span>
|
||||
{% endfor %}
|
||||
|
Loading…
Reference in New Issue
Block a user