Implement email sending
This commit is contained in:
parent
f6fb0cb00a
commit
f5f74540fd
4 changed files with 22 additions and 9 deletions
|
@ -98,7 +98,7 @@ def user_info():
|
|||
me = False if not("username" in session) else username.lower() == session["username"].lower()
|
||||
user = get_user(username_lower=username.lower()).first()
|
||||
if user is None:
|
||||
raise WebException("User not found.")
|
||||
raise WebException("User not found.")
|
||||
|
||||
show_email = me if logged_in else False
|
||||
user_in_team = in_team(user)
|
||||
|
@ -182,7 +182,7 @@ def login_user(username, password):
|
|||
token = LoginTokens(user.uid, user.username, ua=useragent, ip=ip)
|
||||
db.session.add(token)
|
||||
db.session.commit()
|
||||
|
||||
|
||||
session["sid"] = token.sid
|
||||
session["username"] = token.username
|
||||
session["admin"] = user.admin == True
|
||||
|
@ -215,4 +215,4 @@ def validate_captcha(form):
|
|||
captcha_response = form["captcha_response"]
|
||||
data = {"secret": "6Lc4xhMTAAAAACFaG2NyuKoMdZQtSa_1LI76BCEu", "response": captcha_response}
|
||||
response = requests.post("https://www.google.com/recaptcha/api/siteverify", data=data)
|
||||
return response.json()["success"]
|
||||
return response.json()["success"]
|
||||
|
|
|
@ -2,10 +2,12 @@ import datetime
|
|||
import json
|
||||
import random
|
||||
import re
|
||||
import requests
|
||||
import string
|
||||
import traceback
|
||||
import unicodedata
|
||||
|
||||
from flask import current_app as app
|
||||
from functools import wraps
|
||||
from werkzeug.security import generate_password_hash, check_password_hash
|
||||
|
||||
|
@ -33,4 +35,14 @@ def flat_multi(multidict):
|
|||
for key, values in multidict.items():
|
||||
value = values[0] if type(values) == list and len(values) == 1 else values
|
||||
flat[key] = value.encode("utf-8")
|
||||
return flat
|
||||
return flat
|
||||
|
||||
def send_email(recipient, subject, body):
|
||||
api_key = app.config["MG_API_KEY"]
|
||||
data = {"from": "EasyCTF Administrator <%s>" % (app.config["ADMIN_EMAIL"]),
|
||||
"to": recipient,
|
||||
"subject": subject,
|
||||
"text": body
|
||||
}
|
||||
auth = ("api", api_key)
|
||||
return requests.post("https://api.mailgun.net/v3/%s/messages" % (app.config["MG_HOST"]), auth=auth, data=data)
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
from argparse import ArgumentParser
|
||||
from flask import Flask
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
import api
|
||||
import config
|
||||
import json
|
||||
|
@ -8,11 +10,7 @@ import os
|
|||
|
||||
from api.decorators import api_wrapper
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
app.config["SQLALCHEMY_DATABASE_URI"] = config.SQLALCHEMY_DATABASE_URI
|
||||
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = config.SQLALCHEMY_TRACK_MODIFICATIONS
|
||||
app.config["UPLOAD_FOLDER"] = config.UPLOAD_FOLDER
|
||||
app.config.from_object(config)
|
||||
|
||||
if not os.path.exists(app.config["UPLOAD_FOLDER"]):
|
||||
os.makedirs(app.config["UPLOAD_FOLDER"])
|
||||
|
|
|
@ -19,3 +19,6 @@ UPLOAD_FOLDER = os.path.normpath("../web/files")
|
|||
|
||||
CTF_BEGIN = 0 # To be used later
|
||||
CTF_END = 0 # To be used later
|
||||
MG_HOST = ""
|
||||
MG_API_KEY = ""
|
||||
ADMIN_EMAIL = ""
|
||||
|
|
Loading…
Reference in a new issue