diff --git a/app.py b/app.py index cdb7259..89c4b9c 100644 --- a/app.py +++ b/app.py @@ -8,6 +8,7 @@ from flask_sqlalchemy import SQLAlchemy from flask_security import Security, SQLAlchemyUserDatastore, auth_required, hash_password, uia_email_mapper from flask_security.models import fsqla_v2 as fsqla from flask_security.forms import LoginForm, Required, PasswordField +from flask_mail import Mail import bleach from datetime import date @@ -16,10 +17,18 @@ from door_handle import DoorHandle import argparse parser = argparse.ArgumentParser() -parser.add_argument("--token_file", default="/etc/door_tokens") -parser.add_argument("--template_folder", default="/usr/share/door_admin/templates") -parser.add_argument("--static_folder", default="/usr/share/door_admin/static") -parser.add_argument("--mqtt_host", default="10.10.21.2") +parser.add_argument("--token_file", default="/etc/door_tokens", help="path to the file with door tokens and users") +parser.add_argument("--template_folder", default="/usr/share/door_admin/templates", help="path to Flask templates folder") +parser.add_argument("--static_folder", default="/usr/share/door_admin/static", help="path to Flask static folder") +parser.add_argument("--mqtt_host", default="10.10.21.2", help="IP address of MQTT broker") +parser.add_argument("--port", default=5000, help="Port for running the Flask server") +parser.add_argument("--mail_server", default="smtp.googlemail.com", help="email server for sending security messages") + +parser.add_argument("--mail_port", default=465, help="port for security email server") +parser.add_argument("--mail_use_tls", default=False, help="use TLS for security emails") +parser.add_argument("--mail_use_ssl", default=True, help="use SSL for security emails") +parser.add_argument("--mail_username", default="admin@example.com", help="email account for sending security messages") +parser.add_argument("--mail_password", default="password", help="Password for email account") config = parser.parse_args() # create door objects which provides access to the token file and current door state via MQTT @@ -44,6 +53,20 @@ app.config['SECURITY_USER_IDENTITY_ATTRIBUTES'] = [ {"email": {"mapper": uia_email_mapper, "case_insensitive": True}}, {"username": {"mapper": uia_username_mapper}} ] +app.config['SECURITY_CHANGEABLE'] = True +app.config['SECURITY_RECOVERABLE'] = True +app.config['SECURITY_SEND_PASSWORD_CHANGE_EMAIL'] = False + +# Mail Config +app.config['MAIL_SERVER'] = config.mail_server +app.config['MAIL_PORT'] = config.mail_port +app.config['MAIL_USE_TLS'] = config.mail_use_tls +app.config['MAIL_USE_SSL'] = config.mail_use_ssl +app.config['MAIL_USERNAME'] = config.mail_username +app.config['MAIL_PASSWORD'] = config.mail_password +app.config['MAIL_DEFAULT_SENDER'] = app.config['MAIL_USERNAME'] +mail = Mail(app) + app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///admin.db' # As of Flask-SQLAlchemy 2.4.0 it is easy to pass in options directly to the @@ -267,4 +290,4 @@ def deactivate_token(token): if __name__ == '__main__': - app.run(host='0.0.0.0') + app.run(host='0.0.0.0', port=config.port) diff --git a/templates/base.html b/templates/base.html index 3fad1b3..19c01e7 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,16 +1,16 @@