diff --git a/nsupdate/accounts/templates/registration/login.html b/nsupdate/accounts/templates/registration/login.html index d537664..554c95d 100644 --- a/nsupdate/accounts/templates/registration/login.html +++ b/nsupdate/accounts/templates/registration/login.html @@ -11,6 +11,10 @@
{% csrf_token %} {{ form|bootstrap }} +
+ + +

Forgot your password? Need an account?

diff --git a/nsupdate/settings.py b/nsupdate/settings.py index 1f6e5be..ba2f26e 100644 --- a/nsupdate/settings.py +++ b/nsupdate/settings.py @@ -253,8 +253,8 @@ SESSION_COOKIE_NAME = 'sessionid' SESSION_COOKIE_PATH = '/' SESSION_COOKIE_SECURE = False # use True here if you have set WE_HAVE_SSL = True SESSION_COOKIE_HTTPONLY = True -SESSION_COOKIE_AGE = 14 * 24 * 3600 # 2 weeks, in seconds -SESSION_EXPIRE_AT_BROWSER_CLOSE = True # more safe than False +SESSION_COOKIE_AGE = 14 * 24 * 3600 # 2 weeks, in seconds (remember_me is True) +SESSION_EXPIRE_AT_BROWSER_CLOSE = False # more safe (remember_me is False) SESSION_SERIALIZER = 'django.contrib.sessions.serializers.JSONSerializer' diff --git a/nsupdate/urls.py b/nsupdate/urls.py index 36fab16..ddfab3f 100644 --- a/nsupdate/urls.py +++ b/nsupdate/urls.py @@ -9,6 +9,18 @@ from registration.backends.default.views import RegistrationView from registration.forms import RegistrationForm +def remember_me_login(request, *args, **kw): + """ + Wraps the default login view function. If user does not want to be + remembered, we change the cookie to a session cookie that gets cleared + when the browser is closed. + """ + if request.method == 'POST': + if not request.POST.get('remember_me'): + request.session.set_expiry(0) + return auth_views.login(request, *args, **kw) + + class Html5RegistrationForm(RegistrationForm): def __init__(self, *args, **kwargs): super(Html5RegistrationForm, self).__init__(*args, **kwargs) @@ -37,7 +49,7 @@ urlpatterns = patterns( name='registration_register'), # from registration.auth_urls: url(r'^accounts/login/$', - auth_views.login, + remember_me_login, {'authentication_form': Html5AuthenticationForm, 'template_name': 'registration/login.html'}, name='auth_login'),