From 9c07479eba71589011aec0ed120b6a1bdd78459c Mon Sep 17 00:00:00 2001 From: jordan Date: Tue, 2 Aug 2011 12:11:29 +0000 Subject: [PATCH] OSQA-605, store user logins in a separate action, this helps to easily retrieve the user IP address after every login git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@1148 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- forum/actions/user.py | 9 +++++++++ forum/views/auth.py | 5 ++++- forum_modules/facebookauth/authentication.py | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/forum/actions/user.py b/forum/actions/user.py index 15ad5ee..3366a6c 100644 --- a/forum/actions/user.py +++ b/forum/actions/user.py @@ -23,6 +23,15 @@ class UserJoinsAction(ActionProxy): 'app_name': APP_SHORT_NAME, } +class UserLoginAction(ActionProxy): + verb = _("logged in") + + def describe(self, viewer=None): + return _("%(user)s %(have_has)s logged in") % { + 'user' : self.hyperlink(self.user.get_profile_url(), self.friendly_username(viewer, self.user)), + 'have_has': self.viewer_or_user_verb(viewer, self.user, _('have'), _('has')), + } + class EmailValidationAction(ActionProxy): verb = _("validated e-mail") diff --git a/forum/views/auth.py b/forum/views/auth.py index c64aa1d..1b18d6c 100644 --- a/forum/views/auth.py +++ b/forum/views/auth.py @@ -23,7 +23,7 @@ from forum.utils.mail import send_template_email from forum.authentication.base import InvalidAuthentication from forum.authentication import AUTH_PROVIDERS from forum.models import User, AuthKeyUserAssociation, ValidationHash -from forum.actions import UserJoinsAction +from forum.actions import UserJoinsAction, UserLoginAction from forum import settings from vars import ON_SIGNIN_SESSION_ATTR, PENDING_SUBMISSION_SESSION_ATTR @@ -374,6 +374,9 @@ def login_and_forward(request, user, forward=None, message=None): user.backend = "django.contrib.auth.backends.ModelBackend" login(request, user) + # Store the login action + UserLoginAction(user=user, ip=request.META['REMOTE_ADDR']).save() + if message is None: message = _("Welcome back %s, you are now logged in") % smart_unicode(user.username) diff --git a/forum_modules/facebookauth/authentication.py b/forum_modules/facebookauth/authentication.py index aa54c42..4e9a44a 100644 --- a/forum_modules/facebookauth/authentication.py +++ b/forum_modules/facebookauth/authentication.py @@ -82,6 +82,6 @@ class FacebookAuthContext(ConsumerTemplateContext): weight = 100 human_name = 'Facebook' code_template = 'modules/facebookauth/button.html' - extra_css = ["http://www.facebook.com/css/connect/connect_button.css"] + extra_css = [] API_KEY = settings.FB_API_KEY \ No newline at end of file -- 2.39.5