Compare commits
1 Commits
adb20dea14
...
208e3a7b49
Author | SHA1 | Date | |
---|---|---|---|
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 apt-get update && apt-get upgrade
|
||||||
RUN pip3 install flask Flask-SQLAlchemy flask_migrate flask_login flask_wtf python-dotenv
|
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 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
|
RUN pip3 install google google-oauth google-auth-oauthlib google-api-python-client mysqlclient
|
||||||
COPY docker-entrypoint.sh /usr/local/bin/
|
COPY docker-entrypoint.sh /usr/local/bin/
|
||||||
EXPOSE 8084
|
EXPOSE 8084
|
||||||
|
@ -2,6 +2,4 @@
|
|||||||
from server import app
|
from server import app
|
||||||
|
|
||||||
if __name__ == "__main__":
|
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)
|
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
|
from database.models import User, Device
|
||||||
import email_validator
|
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):
|
class LoginForm(FlaskForm):
|
||||||
username = StringField('Username', validators=[DataRequired()])
|
username = StringField('Username', validators=[DataRequired()])
|
||||||
password = PasswordField('Password', validators=[DataRequired()])
|
password = PasswordField('Password', validators=[DataRequired()])
|
||||||
remember_me = BooleanField('Remember Me')
|
remember_me = BooleanField('Remember Me')
|
||||||
submit = SubmitField('Sign In')
|
submit = SubmitField('Sign In')
|
||||||
|
|
||||||
|
'''
|
||||||
|
RegiatrationForm validates username, email and pw
|
||||||
|
This Form is based on 'The Flask mega-Tutorial'
|
||||||
|
'''
|
||||||
|
|
||||||
class RegistrationForm(FlaskForm):
|
class RegistrationForm(FlaskForm):
|
||||||
username = StringField('Username', validators=[DataRequired()])
|
username = StringField('Username', validators=[DataRequired()])
|
||||||
email = StringField('Email', validators=[DataRequired(), Email()])
|
email = StringField('Email', validators=[DataRequired(), Email()])
|
||||||
@ -31,7 +41,7 @@ class RegistrationForm(FlaskForm):
|
|||||||
class DeviceForm(FlaskForm):
|
class DeviceForm(FlaskForm):
|
||||||
deviceName=StringField('New Device ID', validators=[DataRequired()])
|
deviceName=StringField('New Device ID', validators=[DataRequired()])
|
||||||
submit = SubmitField('Add New Device')
|
submit = SubmitField('Add New Device')
|
||||||
|
#
|
||||||
def validate_deviceName (self, deviceName):
|
def validate_deviceName (self, deviceName):
|
||||||
device = Device.query.filter_by(deviceName=deviceName.data).first()
|
device = Device.query.filter_by(deviceName=deviceName.data).first()
|
||||||
if device is None:
|
if device is None:
|
||||||
|
@ -25,7 +25,9 @@ import requests
|
|||||||
from database.models import Calendar as dbCalendar
|
from database.models import Calendar as dbCalendar
|
||||||
from backend import Calendar, Event
|
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():
|
class GoogleClient():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.CLIENT_SECRETS_FILE = "certificate/client_secret.json"
|
self.CLIENT_SECRETS_FILE = "certificate/client_secret.json"
|
||||||
|
@ -13,7 +13,7 @@ from flask_login import (
|
|||||||
login_user,
|
login_user,
|
||||||
logout_user,
|
logout_user,
|
||||||
)
|
)
|
||||||
from random_word import RandomWords
|
from random_words import RandomWords
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
import server.googleHandler as google
|
import server.googleHandler as google
|
||||||
@ -74,15 +74,16 @@ def devices():
|
|||||||
|
|
||||||
# if this is a post request from the 'unlink' submittion form
|
# if this is a post request from the 'unlink' submittion form
|
||||||
# delete this device from the list
|
# delete this device from the list
|
||||||
|
form = DeviceForm()
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
|
|
||||||
if request.form.get("submit") == "Unlink":
|
if request.form.get("submit") == "Unlink":
|
||||||
device = db.session.query(Device).filter(Device.deviceName==request.form.get("device")).first()
|
device = db.session.query(Device).filter(Device.deviceName==request.form.get("device")).first()
|
||||||
db.session.delete(device)
|
db.session.delete(device)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
# if this is part of the device form
|
# if this is part of the device form
|
||||||
form = DeviceForm()
|
elif form.validate_on_submit():
|
||||||
if form.validate_on_submit():
|
|
||||||
device = db.session.query(Device).filter(Device.deviceName==form.deviceName.data).first()
|
device = db.session.query(Device).filter(Device.deviceName==form.deviceName.data).first()
|
||||||
current_user.devices.append(device)
|
current_user.devices.append(device)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
@ -222,9 +223,7 @@ def generateDeviceFingerprint():
|
|||||||
while True:
|
while True:
|
||||||
fingerprint = ""
|
fingerprint = ""
|
||||||
length = 3
|
length = 3
|
||||||
randos = r.get_random_words(limit=length, hasDictionaryDef="true",
|
randos = r.random_words(count=length)
|
||||||
includePartOfSpeech="noun", minDictionaryCount=1,
|
|
||||||
maxDictionaryCount=10, minLength=5, maxLength=10)
|
|
||||||
for i in range(len(randos)):
|
for i in range(len(randos)):
|
||||||
fingerprint += randos[i]
|
fingerprint += randos[i]
|
||||||
if i < length-1:
|
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">
|
<form action="" method="post">
|
||||||
<div class="container grey" style="margin-top: 3rem;">
|
<div class="container grey" style="margin-top: 3rem;">
|
||||||
<div>{{ form.hidden_tag() }}</div>
|
<div>{{ form.hidden_tag() }}</div>
|
||||||
<div style="width: 7rem; margin: 1rem">{{ form.deviceName.label }}</div>
|
<div style="margin: 1rem">{{ form.deviceName.label }}</div>
|
||||||
<div style="width: 12rem; margin: 1rem">{{ form.deviceName(size=24) }}</div>
|
<div style="margin: 1rem">{{ form.deviceName(size=24) }}</div>
|
||||||
<div style="with: 7rem; margin: 1rem">{{ form.submit() }}</div>
|
<div style="with: 8rem; margin: 1rem">{{ form.submit() }}</div>
|
||||||
{% for error in form.deviceName.errors %}
|
{% for error in form.deviceName.errors %}
|
||||||
<span style="color: red;">[{{ error }}]</span>
|
<span style="color: red;">[{{ error }}]</span>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
Loading…
Reference in New Issue
Block a user