Skip to content
Snippets Groups Projects
Commit 0434a1fd authored by void's avatar void
Browse files
parents 1c6a751c ddb128bf
No related branches found
No related tags found
No related merge requests found
...@@ -30,6 +30,7 @@ RUN pip3 install \ ...@@ -30,6 +30,7 @@ RUN pip3 install \
ldap3 \ ldap3 \
uwsgi \ uwsgi \
django-two-factor-auth \ django-two-factor-auth \
matterhook \
--upgrade --upgrade
RUN pip3 install git+https://github.com/nkunihiko/django-bootstrap3-datetimepicker.git RUN pip3 install git+https://github.com/nkunihiko/django-bootstrap3-datetimepicker.git
......
...@@ -5,6 +5,9 @@ DEBUG = true ...@@ -5,6 +5,9 @@ DEBUG = true
SECRET_KEY = '4m4c(_$ubwued9p-insp!950g&r0yu851bp287$2a3ydj^y=0=' SECRET_KEY = '4m4c(_$ubwued9p-insp!950g&r0yu851bp287$2a3ydj^y=0='
PW_RESET_TOKEN_LIFETIME = 5 PW_RESET_TOKEN_LIFETIME = 5
[mattermost]
API_KEY = bohtwe6zy7y43p5n36skph7ejy
[ldap] [ldap]
LDAP_HOST = ldap LDAP_HOST = ldap
LDAP_BIND_DN = cn=admin,dc=warpzone,dc=ms LDAP_BIND_DN = cn=admin,dc=warpzone,dc=ms
......
...@@ -3,6 +3,8 @@ from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseNotAll ...@@ -3,6 +3,8 @@ from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseNotAll
from django.shortcuts import redirect from django.shortcuts import redirect
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from warpfood.util import * from warpfood.util import *
from warpzone.util import send_to_mattermost
from django.utils.translation import ugettext as _
from warpfood.models import * from warpfood.models import *
from reportlab.pdfgen import canvas from reportlab.pdfgen import canvas
from django.http import HttpResponse from django.http import HttpResponse
...@@ -21,7 +23,8 @@ def index(request): ...@@ -21,7 +23,8 @@ def index(request):
if request.method == 'POST': if request.method == 'POST':
form = FoodSheetForm(request.POST) form = FoodSheetForm(request.POST)
if form.is_valid(): if form.is_valid():
form.save() sheet = form.save()
send_to_mattermost("PizzaSheet", "town-square", _("pizza_sheet_opened_for_%(est_order_time)s_at_%(pizza_service)s") % ({'est_order_time': sheet.estimated_order_time, 'pizza_service':sheet.food_service}))
time_threshold = datetime.now() - timedelta(days=1) time_threshold = datetime.now() - timedelta(days=1)
FoodSheet.objects.filter(order_time__lte=time_threshold).delete() FoodSheet.objects.filter(order_time__lte=time_threshold).delete()
......
...@@ -39,9 +39,15 @@ EMAIL_SUBJECT_PREFIX = config.get('email','SUBJECT_PREFIX') ...@@ -39,9 +39,15 @@ EMAIL_SUBJECT_PREFIX = config.get('email','SUBJECT_PREFIX')
PW_RESET_TOKEN_LIFETIME = config.get('security','PW_RESET_TOKEN_LIFETIME') PW_RESET_TOKEN_LIFETIME = config.get('security','PW_RESET_TOKEN_LIFETIME')
SECRET_KEY = config.get('security','SECRET_KEY') SECRET_KEY = config.get('security','SECRET_KEY')
# MATTERMOST
API_KEY = config.get('mattermost','API_KEY')
# DEBUG # DEBUG
DEBUG = config.getboolean('debug','DEBUG') DEBUG = config.getboolean('debug','DEBUG')
# MISC
LOG_PATH = config.get('misc','LOG_PATH')
ALLOWED_HOSTS = [config.get('security','ALLOWED_HOSTS')] ALLOWED_HOSTS = [config.get('security','ALLOWED_HOSTS')]
LOGIN_URL = 'two_factor:login' LOGIN_URL = 'two_factor:login'
...@@ -185,13 +191,29 @@ AUTH_LDAP_FIND_GROUP_PERMS = True ...@@ -185,13 +191,29 @@ AUTH_LDAP_FIND_GROUP_PERMS = True
AUTH_LDAP_CACHE_GROUPS = True AUTH_LDAP_CACHE_GROUPS = True
AUTH_LDAP_GROUP_CACHE_TIMEOUT = 10 AUTH_LDAP_GROUP_CACHE_TIMEOUT = 10
logger = logging.getLogger('django_auth_ldap') LOGGING = {
logger.addHandler(logging.StreamHandler()) 'version': 1,
hdlr = logging.FileHandler('/tmp/ldap.log') 'disable_existing_loggers': False,
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') 'handlers': {
hdlr.setFormatter(formatter) 'file': {
logger.addHandler(hdlr) 'level': 'ERROR',
logger.setLevel(logging.DEBUG) 'class': 'logging.FileHandler',
'filename': LOG_PATH+'/error.log',
},
},
'loggers': {
'django': {
'handlers': ['file'],
'level': 'ERROR',
'propagate': True,
},
'django_auth_ldap': {
'handlers': ['file'],
'level': 'ERROR',
'propagate': True,
},
},
}
STATIC_URL = '/static/' STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static") STATIC_ROOT = os.path.join(BASE_DIR, "static")
......
from django.core.mail import send_mail from django.core.mail import send_mail
from django.conf import settings from django.conf import settings
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from matterhook import Webhook
import logging
page_context = {'pages': [ page_context = {'pages': [
{"link": "pizza", "name": _("pizza_sheet")}, {"link": "pizza", "name": _("pizza_sheet")},
{"link": "about", "name": _("about")}, {"link": "about", "name": _("about")},
], 'debug': settings.DEBUG} ], 'debug': settings.DEBUG}
def send_to_mattermost(username, channel, message):
try:
if settings.API_KEY:
hook = Webhook("https://mattermost.warpzone.ms", settings.API_KEY)
if settings.DEBUG:
username = "["+channel+"] "+username
channel = "warpinfradebug"
hook.send(message, channel=channel, username=username)
except Exception as e:
logging.getLogger("django").error(e)
def send_email(to_address, subject, content): def send_email(to_address, subject, content):
try: try:
send_mail( send_mail(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment