Commit 05bcb63f authored by Sofia Papagiannaki's avatar Sofia Papagiannaki Committed by Christos Stavrakakis
Browse files

astakos: Fix logging issues

parent 40e372b3
......@@ -53,8 +53,8 @@ class TokenBackend(ModelBackend):
except AstakosUser.DoesNotExist:
return None
else:
msg = 'Invalid token during authentication for %s' % email
logger._log(settings.LOGGING_LEVEL, msg, [])
msg = 'Invalid token during authentication for %s'
logger.log(settings.LOGGING_LEVEL, msg, email)
def get_user(self, user_id):
try:
......@@ -80,8 +80,8 @@ class EmailBackend(ModelBackend):
if user.check_password(password):
return user
else:
msg = 'Invalid password during authentication for %s' % username
logger._log(settings.LOGGING_LEVEL, msg, [])
msg = 'Invalid password during authentication for %s'
logger.log(settings.LOGGING_LEVEL, msg, username)
def get_user(self, user_id):
......
......@@ -86,20 +86,20 @@ class CookieHandler():
else:
cookie_value = quote(user.uuid + '|' + user.auth_token)
self.response.set_cookie(
settings.COOKIE_NAME, value=cookie_value, expires=expire_fmt, path='/',
domain=settings.COOKIE_DOMAIN, secure=settings.COOKIE_SECURE
)
msg = str(('Cookie [expiring %s]', 'set for %s')) \
% (user.auth_token_expires, user.uuid)
logger._log(settings.LOGGING_LEVEL, msg, [])
settings.COOKIE_NAME, value=cookie_value, expires=expire_fmt,
path='/', domain=settings.COOKIE_DOMAIN,
secure=settings.COOKIE_SECURE)
msg = 'Cookie [expiring %s] set for %s'
logger.log(settings.LOGGING_LEVEL, msg, user.auth_token_expires,
user.uuid)
def __delete(self):
if not self.response:
raise ValueError(_(astakos_messages.NO_RESPONSE))
self.response.delete_cookie(
settings.COOKIE_NAME, path='/', domain=settings.COOKIE_DOMAIN)
msg = 'Cookie deleted for %(uuid)s' % self.__dict__
logger._log(settings.LOGGING_LEVEL, msg, [])
msg = 'Cookie deleted for %s'
logger.log(settings.LOGGING_LEVEL, msg, self.uuid)
def fix(self, response=None):
self.response = response or self.response
......
......@@ -155,8 +155,8 @@ def send_account_activated_notification(
send_mail(_(astakos_messages.HELPDESK_NOTIFICATION_EMAIL_SUBJECT) %
{'user': user.email},
message, sender, recipient_list, connection=get_connection())
msg = 'Sent helpdesk admin notification for %s' % user.email
logger.log(settings.LOGGING_LEVEL, msg)
msg = 'Sent helpdesk admin notification for %s'
logger.log(settings.LOGGING_LEVEL, msg, user.email)
def send_invitation(invitation, template_name='im/invitation.txt'):
......@@ -175,8 +175,8 @@ def send_invitation(invitation, template_name='im/invitation.txt'):
sender = settings.SERVER_EMAIL
send_mail(subject, message, sender, [invitation.username],
connection=get_connection())
msg = 'Sent invitation %s' % invitation
logger.log(settings.LOGGING_LEVEL, msg)
msg = 'Sent invitation %s'
logger.log(settings.LOGGING_LEVEL, msg, invitation)
inviter_invitations = invitation.inviter.invitations
invitation.inviter.invitations = max(0, inviter_invitations - 1)
invitation.inviter.save()
......@@ -199,8 +199,8 @@ def send_greeting(user, email_template_name='im/welcome_email.txt'):
sender = settings.SERVER_EMAIL
send_mail(subject, message, sender, [user.email],
connection=get_connection())
msg = 'Sent greeting %s' % user.log_display
logger.log(settings.LOGGING_LEVEL, msg)
msg = 'Sent greeting %s'
logger.log(settings.LOGGING_LEVEL, msg, user.log_display)
def send_feedback(msg, data, user, email_template_name='im/feedback_mail.txt'):
......@@ -213,23 +213,24 @@ def send_feedback(msg, data, user, email_template_name='im/feedback_mail.txt'):
'user': user})
send_mail(subject, content, from_email, recipient_list,
connection=get_connection())
msg = 'Sent feedback from %s' % user.log_display
logger.log(settings.LOGGING_LEVEL, msg)
msg = 'Sent feedback from %s'
logger.log(settings.LOGGING_LEVEL, msg, user.log_display)
def send_change_email(
ec, request, email_template_name='registration/email_change_email.txt'):
def send_change_email(ec, request,
email_template_name=
'registration/email_change_email.txt'):
url = ec.get_url()
url = request.build_absolute_uri(url)
c = {'url': url, 'site_name': settings.SITENAME, 'support': settings.CONTACT_EMAIL,
'ec': ec}
c = {'url': url, 'site_name': settings.SITENAME,
'support': settings.CONTACT_EMAIL, 'ec': ec}
message = render_to_string(email_template_name, c)
from_email = settings.SERVER_EMAIL
send_mail(_(astakos_messages.EMAIL_CHANGE_EMAIL_SUBJECT), message,
from_email,
[ec.new_email_address], connection=get_connection())
msg = 'Sent change email for %s' % ec.user.log_display
logger.log(settings.LOGGING_LEVEL, msg)
msg = 'Sent change email for %s'
logger.log(settings.LOGGING_LEVEL, msg, ec.user.log_display)
def invite(inviter, email, realname):
......
......@@ -126,8 +126,8 @@ class Component(models.Model):
self.auth_token_expires = expiration_date
else:
self.auth_token_expires = None
msg = 'Token renewed for component %s' % self.name
logger.log(astakos_settings.LOGGING_LEVEL, msg)
msg = 'Token renewed for component %s'
logger.log(astakos_settings.LOGGING_LEVEL, msg, self.name)
def __str__(self):
return self.name
......@@ -554,8 +554,8 @@ class AstakosUser(User):
timedelta(hours=astakos_settings.AUTH_TOKEN_DURATION)
if flush_sessions:
self.flush_sessions(current_key)
msg = 'Token renewed for %s' % self.log_display
logger.log(astakos_settings.LOGGING_LEVEL, msg)
msg = 'Token renewed for %s'
logger.log(astakos_settings.LOGGING_LEVEL, msg, self.log_display)
def token_expired(self):
return self.auth_token_expires < datetime.now()
......@@ -567,8 +567,8 @@ class AstakosUser(User):
keys = q.values_list('session_key', flat=True)
if keys:
msg = 'Flushing sessions: %s' % ','.join(keys)
logger.log(astakos_settings.LOGGING_LEVEL, msg, [])
msg = 'Flushing sessions: %s'
logger.log(astakos_settings.LOGGING_LEVEL, msg, ','.join(keys))
engine = import_module(settings.SESSION_ENGINE)
for k in keys:
s = engine.SessionStore(k)
......@@ -1116,10 +1116,8 @@ class EmailChangeManager(models.Manager):
user.email = email_change.new_email_address
user.save()
email_change.delete()
msg = "User %s changed email from %s to %s" % (user.log_display,
old_email,
user.email)
logger.log(astakos_settings.LOGGING_LEVEL, msg)
msg = "User %s changed email from %s to %s"
logger.log(astakos_settings.LOGGING_LEVEL, msg, user.log_display, old_email, user.email)
return user
except EmailChange.DoesNotExist:
raise ValueError(_('Invalid activation key.'))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment