Add support for email backend in config.

This commit is contained in:
Ceda EI 2020-01-19 16:20:16 +05:30
parent 432f2854d5
commit 20d5c51016
1 changed files with 12 additions and 2 deletions

View File

@ -1,4 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
"Server for the-long-night"
import subprocess import subprocess
import json import json
@ -11,6 +12,7 @@ app = Flask(__name__)
@app.route('/login', methods=['POST']) @app.route('/login', methods=['POST'])
def en_login(): def en_login():
"/login"
try: try:
password = request.values['password'] password = request.values['password']
except KeyError: except KeyError:
@ -35,26 +37,34 @@ def en_login():
"and run `cancel-adding-key.sh` in The Long Night installation" "and run `cancel-adding-key.sh` in The Long Night installation"
"directory.") "directory.")
if config["matrix"]["enabled"]: if "matrix" in config and config["matrix"]["enabled"]:
from backends import matrix from backends import matrix
try: try:
matrix.send(config["matrix"], message) matrix.send(config["matrix"], message)
except: except:
pass pass
if config["telegram"]["enabled"]: if "telegram" in config and config["telegram"]["enabled"]:
from backends import telegram from backends import telegram
try: try:
telegram.send(config["telegram"], message) telegram.send(config["telegram"], message)
except: except:
pass pass
if "email" in config and config["email"]["enabled"]:
from backends import mail
try:
mail.send(config["email"], message)
except:
pass
return ("Logged In. The ssh key will be added " + str(config["days"]) + return ("Logged In. The ssh key will be added " + str(config["days"]) +
" day(s) later.") " day(s) later.")
@app.route('/') @app.route('/')
def en_root(): def en_root():
"/"
return """ return """
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>