aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/__init__.py41
-rw-r--r--app/auth/__init__.py3
-rw-r--r--app/auth/forms.py7
-rw-r--r--app/config.py16
-rw-r--r--app/database.py25
-rw-r--r--app/static/gen/style.css46
-rw-r--r--app/static/scss/style.scss56
7 files changed, 194 insertions, 0 deletions
diff --git a/app/__init__.py b/app/__init__.py
new file mode 100644
index 0000000..e929535
--- /dev/null
+++ b/app/__init__.py
@@ -0,0 +1,41 @@
+
+from flask import Flask
+from flask_security.datastore import SQLAlchemyUserDatastore
+from flask_sqlalchemy import SQLAlchemy
+from flask_migrate import Migrate
+from flask_security.core import Security
+
+from flask_assets import Bundle, Environment
+
+from . import config
+
+db = SQLAlchemy()
+migrate = Migrate()
+security = Security()
+environment = Environment()
+
+
+def create_app():
+ app = Flask(__name__)
+
+ app.config.from_file("/etc/nccd/config.toml", load=config.load_config)
+
+ db.init_app(app)
+ migrate.init_app(app, db)
+ environment.init_app(app)
+
+ # Static file init
+ scss = Bundle('scss/style.scss', filters='scss', output='gen/style.css')
+ environment.register('scss', scss)
+
+ from .database import User, Role
+ from .auth import forms as auth_forms
+ user_datastore = SQLAlchemyUserDatastore(db, User, Role)
+ security.init_app(app, user_datastore, register_form=auth_forms.ExtendedRegister)
+
+ # Blueprints
+ app.register_blueprint(auth.bp)
+
+ print(app.url_map)
+
+ return app
diff --git a/app/auth/__init__.py b/app/auth/__init__.py
new file mode 100644
index 0000000..52f0cd7
--- /dev/null
+++ b/app/auth/__init__.py
@@ -0,0 +1,3 @@
+from flask import Blueprint
+
+bp = Blueprint('auth', __name__, url_prefix='/auth')
diff --git a/app/auth/forms.py b/app/auth/forms.py
new file mode 100644
index 0000000..4814f48
--- /dev/null
+++ b/app/auth/forms.py
@@ -0,0 +1,7 @@
+from flask_security.forms import RegisterForm
+from wtforms import StringField
+from wtforms.validators import DataRequired
+
+class ExtendedRegister(RegisterForm):
+ pref_name = StringField('Preferred Name', [DataRequired()])
+
diff --git a/app/config.py b/app/config.py
new file mode 100644
index 0000000..29eb2ef
--- /dev/null
+++ b/app/config.py
@@ -0,0 +1,16 @@
+import toml
+
+def load_config(path):
+ contents = toml.load(path)
+
+ result = {
+ 'SQLALCHEMY_DATABASE_URI': contents['database']['postgres_url'],
+ 'SECRET_KEY': contents['server']['secret_key'],
+ 'MAIL_SERVER': contents['email']['smtp_server'],
+ 'MAIL_PORT': contents['email']['smtp_port'],
+ 'MAIL_USE_TLS': contents['email']['smtp_tls'],
+ 'SECURITY_REGISTERABLE': True,
+ 'SECURITY_PASSWORD_SALT': contents['server']['secret_key']
+ }
+
+ return result
diff --git a/app/database.py b/app/database.py
new file mode 100644
index 0000000..24e1930
--- /dev/null
+++ b/app/database.py
@@ -0,0 +1,25 @@
+from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer, String
+from sqlalchemy.orm import relationship, backref
+from . import db
+from flask_security.core import RoleMixin, UserMixin
+
+class User(db.Model, UserMixin):
+ id = Column(String, primary_key=True)
+ email = Column(String, unique=True, nullable=False)
+ password = Column(String, nullable=False)
+ pref_name = Column(String, nullable=False)
+ last_login = Column(DateTime, nullable=False)
+ fs_uniquifier = Column(String, unique=True, nullable=False)
+ active = Column(Boolean, nullable=False)
+ roles = relationship('Role', secondary='roles_users',backref=backref('users', lazy='dynamic'))
+
+class Role(db.Model, RoleMixin):
+ id = Column(String, primary_key=True)
+ name = Column(String, unique=True)
+ description = Column(String)
+
+class RolesUsers(db.Model):
+ __tablename__ = "roles_users"
+ id = Column(Integer(), primary_key=True)
+ user_id = Column('user_id', String(), ForeignKey('user.id'))
+ role_id = Column('role_id', String(), ForeignKey('role.id'))
diff --git a/app/static/gen/style.css b/app/static/gen/style.css
new file mode 100644
index 0000000..6dd2994
--- /dev/null
+++ b/app/static/gen/style.css
@@ -0,0 +1,46 @@
+body {
+ background: #282828;
+ color: #ebdbb2;
+ font-family: monospace;
+}
+
+a a:active, a:visited {
+ color: #458588;
+}
+
+.container {
+ margin: auto;
+ width: 60%;
+}
+
+button {
+ border-radius: 8px;
+ background-color: #458588;
+ border-color: #458588;
+ border: none;
+ margin: 0.5rem;
+}
+
+button.accent {
+ background-color: #d79921;
+ border-color: #d79921;
+}
+
+form {
+ width: 40%;
+}
+
+label,
+input {
+ display: inline-block;
+}
+
+label {
+ width: 40%;
+ text-align: right;
+}
+
+label + input {
+ width: 40%;
+ margin: 0 30% 0 4%;
+}
diff --git a/app/static/scss/style.scss b/app/static/scss/style.scss
new file mode 100644
index 0000000..d7f50f7
--- /dev/null
+++ b/app/static/scss/style.scss
@@ -0,0 +1,56 @@
+$color-bg: #282828;
+$color-fg: #ebdbb2;
+$color-accent: #d79921;
+$color-link: #458588;
+$color-danger: #cc241d;
+$font-family: monospace;
+
+body {
+ background: $color-bg;
+ color: $color-fg;
+ font-family: $font-family;
+}
+
+a a:active, a:visited {
+ color: $color-link;
+}
+
+.container {
+ margin: auto;
+ width: 60%;
+}
+
+button {
+ border-radius: 8px;
+ background-color: $color-link;
+ border-color: $color-link;
+ border: none;
+ margin: 0.5rem;
+}
+
+button.accent {
+ background-color: $color-accent;
+ border-color: $color-accent;
+}
+
+// Forms
+form {
+ width: 40%;
+}
+
+label,
+input {
+ display: inline-block;
+}
+
+label {
+ width: 40%;
+ text-align: right;
+}
+
+label+input {
+ width: 40%;
+
+ margin: 0 30% 0 4%;
+}
+