This commit is contained in:
c0de 2018-09-26 20:59:55 -05:00
parent b1b9bc4ce2
commit d82bcffab5
2 changed files with 14 additions and 1 deletions

View File

@ -27,6 +27,15 @@ class Account(models.Model):
def __str__(self):
return "<%s:%s>" % (self.id, self.user.username)
def get_meta(self):
meta = {
'user': self.user.username,
'first_login': self.first_login,
'accepted_terms': self.accepted_terms
}
return meta
def create_user(self, username, first_name, last_name, email, password):
# Create a user
usr_obj = User.objects.get_or_create(username=username,

View File

@ -1,6 +1,7 @@
from django.http import HttpResponse
from django.template import loader
from django.contrib import auth
import logging
# Usage:
# template - relative path to the template you wish to render
@ -15,15 +16,18 @@ def _ResponseTemplate(template, request, message='', context=None):
(context.get('message', False)):
context['message'] += ' -- ' + str(message)
else:
logging.warning('[_ResponseTemplate]: context was %s, not a dictionary like expected. Ignoring provided context' % type(context))
context = {
'message': str(message)
}
template = loader.get_template(str(template))
return HttpResponse(template.render(context, request))
# Logs out a user, sending them to the login screen with an optional message and context
# Same arguments as _ResponseTemplate, except for the template
def _ForceLogout(request, message='', context=None):
if request.user:
logging.debug('Logged out %s' % request.user)
auth.logout(request)
return _ResponseTemplate('account/login.html', request, message, context)