mail configuration

This commit is contained in:
Simon Pirkelmann 2021-03-14 23:04:52 +01:00
parent 253db849ff
commit e19f1b50c6
2 changed files with 33 additions and 10 deletions

33
app.py
View File

@ -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)

View File

@ -1,16 +1,16 @@
<!doctype html>
<title>Space Token Administration - {% block title %}{% endblock %}</title>
<!--<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">-->
<nav>
<ul>
<li><a href="{{ url_for('door_lock') }}">Home</a>
<li><a href="{{ url_for('register') }}">Token Registrierung</a>
<li><a href="{{ url_for('list_tokens') }}">Token Übersicht</a>
{% if g.user %}
<li><span>{{ g.user['username'] }}</span>
<li><a href="{{ url_for('security.logout') }}">Log Out</a>
{% if current_user.is_authenticated %}
<li><a href="{{ url_for('security.change_password') }}">Passwort ändern</a>
<li><a href="{{ url_for('security.logout') }}">Benutzer <span>{{ current_user.username }}</span> ausloggen</a>
{% else %}
<li><a href="{{ url_for('security.login') }}">Log In</a>
<li><a href="{{ url_for('security.login') }}">Einloggen</a>
{% endif %}
</ul>
</nav>