Login message middleware

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
from django.conf import settings
from django.core.urlresolvers import reverse

class LoginMessageMiddleware(object):
	def process_request(self, request):
		from django.conf import settings
		if request.user.is_authenticated():
			if not request.session.get(settings.LOGIN_SUCCESS_KEY):
				request.user.message_set.create(message="You have successfully logged in.")
				request.session[settings.LOGIN_SUCCESS_KEY] = True
		if request.path == reverse('auth_logout'):
			try:
				del request.session[settings.LOGIN_SUCCESS_KEY]
			except KeyError:
				pass

More like this

  1. Set test cookie unless logged in by nipuL 5 years, 2 months ago
  2. Execute a signal once by johnnoone 4 years, 1 month ago
  3. Clean Reversion History: Remove unimportant Changes by guettli 1 year, 4 months ago
  4. Automatic Manager Choice Filters by nipuL 4 years, 4 months ago
  5. Show logged users - keeping track of users login and logout by albertorcf 9 months, 2 weeks ago

Comments

(Forgotten your password?)