feat: added remember me checkbox in login form

This commit is contained in:
2024-11-28 17:34:43 +01:00
parent 3ea4bc6b3a
commit 500886aacd
5 changed files with 34 additions and 15 deletions
+5
View File
@@ -9,6 +9,11 @@ server {
alias /code/static;
}
# Media files
location /media {
alias /code/media;
}
# Reverse proxy
location / {
proxy_pass http://127.0.0.1:8000;
+1
View File
@@ -1,5 +1,6 @@
# installs nvm (Node Version Manager)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
source ~/.bashrc
# download and install Node.js (you may need to restart the terminal)
nvm install 22
+11 -1
View File
@@ -15,7 +15,7 @@ class LoginForm(AuthenticationForm):
)
)
password = forms.CharField(
label=_("Password"),
label=_("Contraseña"),
strip=False,
widget=forms.PasswordInput(
attrs={
@@ -26,3 +26,13 @@ class LoginForm(AuthenticationForm):
}
),
)
remember_me = forms.BooleanField(
label=_("Mantener sesión iniciada"),
required=False,
widget=forms.CheckboxInput(
attrs={
"class": "w-4 h-4 border border-gray-300 rounded bg-gray-50 focus:ring-3 focus:ring-primary-300 "
"dark:bg-gray-700 dark:border-gray-600 dark:focus:ring-primary-600 dark:ring-offset-gray-800"
}
)
)
+14 -14
View File
@@ -25,20 +25,20 @@
{{ field }}
{% endfor %}
<div class="flex items-center justify-between">
<div class="flex items-start">
<div class="flex items-center h-5">
<input id="remember" aria-describedby="remember" type="checkbox"
class="w-4 h-4 border border-gray-300 rounded bg-gray-50 focus:ring-3 focus:ring-primary-300 dark:bg-gray-700 dark:border-gray-600 dark:focus:ring-primary-600 dark:ring-offset-gray-800">
</div>
<div class="ml-3 text-sm">
<label for="remember" class="text-gray-500 dark:text-gray-300">Remember me</label>
</div>
</div>
<a href="#" class="text-sm font-medium text-primary-600 hover:underline dark:text-primary-500">
Forgot password?
</a>
</div>
{# <div class="flex items-center justify-between">#}
{# <div class="flex items-start">#}
{# <div class="flex items-center h-5">#}
{# <input id="remember" aria-describedby="remember" type="checkbox"#}
{# class="w-4 h-4 border border-gray-300 rounded bg-gray-50 focus:ring-3 focus:ring-primary-300 dark:bg-gray-700 dark:border-gray-600 dark:focus:ring-primary-600 dark:ring-offset-gray-800">#}
{# </div>#}
{# <div class="ml-3 text-sm">#}
{# <label for="remember" class="text-gray-500 dark:text-gray-300">Remember me</label>#}
{# </div>#}
{# </div>#}
{# <a href="#" class="text-sm font-medium text-primary-600 hover:underline dark:text-primary-500">#}
{# Forgot password?#}
{# </a>#}
{# </div>#}
<button
class="w-full text-white bg-primary-600 hover:bg-primary-700 focus:ring-4 focus:outline-none focus:ring-primary-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-primary-600 dark:hover:bg-primary-700 dark:focus:ring-primary-800">
Login
+3
View File
@@ -34,6 +34,9 @@ class LoginView(View, RedirectionMixin):
if login_form.is_valid():
login_user(request, login_form.get_user())
if not login_form.cleaned_data.get('remember_me'):
request.session.set_expiry(0)
return redirect(self.get_redirection())
return render(request, self.template_name, {"form": login_form}, status=400)