mirror of
https://github.com/tubearchivist/tubearchivist-frontend.git
synced 2024-11-22 11:50:14 +00:00
add remember me checkbox to login view and set session expire, #77
This commit is contained in:
parent
e858bba944
commit
c9373eee15
@ -16,6 +16,7 @@ class CustomAuthForm(AuthenticationForm):
|
||||
password = forms.CharField(
|
||||
widget=PasswordInput(attrs={"placeholder": "Password"}), label=False
|
||||
)
|
||||
remember_me = forms.BooleanField(required=False)
|
||||
|
||||
|
||||
class UserSettingsForm(forms.Form):
|
||||
|
@ -29,9 +29,9 @@
|
||||
{% endif %}
|
||||
<form action="/login/" method="POST" name="login">
|
||||
{% csrf_token %}
|
||||
{% for field in form %}
|
||||
{{ field }}<br>
|
||||
{% endfor %}
|
||||
{{ form.username }}<br>
|
||||
{{ form.password }}<br>
|
||||
<p>Remember me: {{ form.remember_me }}</p>
|
||||
<input type="hidden" name="next" value="{{ request.GET.next }}" />
|
||||
<button type="submit">Login</button>
|
||||
</form>
|
||||
|
@ -173,6 +173,8 @@ class LoginView(View):
|
||||
Greeting and login page
|
||||
"""
|
||||
|
||||
SEC_IN_DAY = 60 * 60 * 24
|
||||
|
||||
@staticmethod
|
||||
def get(request):
|
||||
"""handle get requests"""
|
||||
@ -182,11 +184,17 @@ class LoginView(View):
|
||||
context = {"colors": colors, "form": form, "form_error": failed}
|
||||
return render(request, "home/login.html", context)
|
||||
|
||||
@staticmethod
|
||||
def post(request):
|
||||
def post(self, request):
|
||||
"""handle login post request"""
|
||||
form = AuthenticationForm(data=request.POST)
|
||||
if form.is_valid():
|
||||
remember_me = request.POST.get("remember_me") or False
|
||||
if remember_me == "on":
|
||||
request.session.set_expiry(self.SEC_IN_DAY * 365)
|
||||
else:
|
||||
request.session.set_expiry(self.SEC_IN_DAY * 2)
|
||||
print(f"expire session in {request.session.get_expiry_age()} secs")
|
||||
|
||||
next_url = request.POST.get("next") or "home"
|
||||
user = form.get_user()
|
||||
login(request, user)
|
||||
|
@ -543,6 +543,10 @@ button:hover {
|
||||
min-width: 200px;
|
||||
}
|
||||
|
||||
#id_remember_me {
|
||||
min-width: unset;
|
||||
}
|
||||
|
||||
.login-page button,
|
||||
.login-page .danger-zone {
|
||||
width: 210px;
|
||||
|
Loading…
Reference in New Issue
Block a user