This commit is contained in:
Valentin Samir 2015-06-11 23:34:25 +02:00
parent 77fc5b5988
commit 365cfd4279
3 changed files with 7 additions and 10 deletions

View file

@ -37,13 +37,13 @@ class UserCredential(forms.Form):
try:
user = models.User.objects.get(
username=auth.username,
session_key=self.request.session_key
session_key=self.request.session.session_key
)
user.save()
except models.User.DoesNotExist:
user = models.User.objects.create(
username=auth.username,
session_key=self.request.session_key
session_key=self.request.session.session_key
)
user.save()
else:

View file

@ -61,10 +61,7 @@ class User(models.Model):
return utils.import_attr(settings.CAS_AUTH_CLASS)(self.username).attributs()
def __unicode__(self):
if self.session:
return u"%s - %s" % (self.username, self.session.session_key)
else:
return self.username
return u"%s - %s" % (self.username, self.session_key)
def logout(self, request=None):
"""Sending SLO request to all services the user logged in"""

View file

@ -71,7 +71,7 @@ class LogoutMixin(object):
try:
user = models.User.objects.get(
username=self.request.session.get("username"),
session_key=self.request.session_key
session_key=self.request.session.session_key
)
user.logout(self.request)
user.delete()
@ -156,7 +156,7 @@ class LoginView(View, LogoutMixin):
if self.form.is_valid():
self.user = models.User.objects.get(
username=self.form.cleaned_data['username'],
session_key=self.request.session_key
session_key=self.request.session.session_key
)
request.session.set_expiry(0)
request.session["username"] = self.form.cleaned_data['username']
@ -263,7 +263,7 @@ class LoginView(View, LogoutMixin):
try:
self.user = models.User.objects.get(
username=self.request.session.get("username"),
session_key=self.request.session_key
session_key=self.request.session.session_key
)
except models.User.DoesNotExist:
self.logout()
@ -351,7 +351,7 @@ class Auth(View):
try:
user = models.User.objects.get(
username=form.cleaned_data['username'],
session_key=self.request.session_key
session_key=self.request.session.session_key
)
# is the service allowed
service_pattern = ServicePattern.validate(service)