Implement login and logout views
This commit is contained in:
parent
d2f896966a
commit
fdcd9cb42c
@ -22,3 +22,4 @@ $alternative-color-dark: darken($alternative-color, 5%);
|
||||
@import "util";
|
||||
@import "shared";
|
||||
@import "bookmarks";
|
||||
@import "login";
|
||||
|
6
bookmarks/styles/login.scss
Normal file
6
bookmarks/styles/login.scss
Normal file
@ -0,0 +1,6 @@
|
||||
.login-page {
|
||||
> .columns {
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
@ -18,12 +18,15 @@
|
||||
<h1>linkding</h1>
|
||||
</a>
|
||||
</section>
|
||||
{# Only nav items menu when logged in #}
|
||||
{% if request.user.is_authenticated %}
|
||||
<section class="navbar-section">
|
||||
<a href="{% url 'bookmarks:new' %}" class="btn btn-primary mr-2">Add bookmark</a>
|
||||
<a href="/bookmarks" class="btn btn-link">Bookmarks</a>
|
||||
<a href="/settings" class="btn btn-link">Settings</a>
|
||||
<a href="/logout" class="btn btn-link">Logout</a>
|
||||
</section>
|
||||
{% endif %}
|
||||
</header>
|
||||
<div class="content container grid-lg">
|
||||
{% block content %}
|
||||
|
38
bookmarks/templates/registration/login.html
Normal file
38
bookmarks/templates/registration/login.html
Normal file
@ -0,0 +1,38 @@
|
||||
{% extends 'bookmarks/layout.html' %}
|
||||
{% load widget_tweaks %}
|
||||
|
||||
{% block title %}Login{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="login-page">
|
||||
<div class="columns">
|
||||
<section class="content-area column col-5 col-sm-12">
|
||||
<div class="content-area-header">
|
||||
<h2>Login</h2>
|
||||
</div>
|
||||
<form method="post" action="{% url 'login' %}">
|
||||
{% csrf_token %}
|
||||
{% if form.errors %}
|
||||
<div class="form-group has-error">
|
||||
<p class="form-input-hint">Your username and password didn't match. Please try again.</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="form-group">
|
||||
<label class="form-label" for="{{ form.username.id_for_label }}">Username</label>
|
||||
{{ form.username|add_class:'form-input' }}
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label" for="{{ form.username.id_for_label }}">Password</label>
|
||||
{{ form.password|add_class:'form-input' }}
|
||||
</div>
|
||||
|
||||
<input type="submit" value="Login" class="btn btn-primary mt-2 col-sm-12">
|
||||
<input type="hidden" name="next" value="{{ next }}">
|
||||
</form>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
{% endblock %}
|
@ -1,8 +1,10 @@
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.http import JsonResponse
|
||||
|
||||
from services.website_loader import load_website_metadata
|
||||
|
||||
|
||||
@login_required
|
||||
def website_metadata(request):
|
||||
url = request.GET.get('url')
|
||||
metadata = load_website_metadata(url)
|
||||
|
@ -1,3 +1,4 @@
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.core.paginator import Paginator
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import render
|
||||
@ -10,6 +11,7 @@ from bookmarks.services.bookmarks import create_bookmark, update_bookmark
|
||||
_default_page_size = 30
|
||||
|
||||
|
||||
@login_required
|
||||
def index(request):
|
||||
page = request.GET.get('page')
|
||||
query_string = request.GET.get('q')
|
||||
@ -31,6 +33,7 @@ def index(request):
|
||||
return render(request, 'bookmarks/index.html', context)
|
||||
|
||||
|
||||
@login_required
|
||||
def new(request):
|
||||
if request.method == 'POST':
|
||||
form = BookmarkForm(request.POST)
|
||||
@ -44,6 +47,7 @@ def new(request):
|
||||
return render(request, 'bookmarks/new.html', {'form': form})
|
||||
|
||||
|
||||
@login_required
|
||||
def edit(request, bookmark_id: int):
|
||||
bookmark = Bookmark.objects.get(pk=bookmark_id)
|
||||
if request.method == 'POST':
|
||||
@ -58,6 +62,7 @@ def edit(request, bookmark_id: int):
|
||||
return render(request, 'bookmarks/edit.html', {'form': form, 'bookmark_id': bookmark_id})
|
||||
|
||||
|
||||
@login_required
|
||||
def remove(request, bookmark_id: int):
|
||||
bookmark = Bookmark.objects.get(pk=bookmark_id)
|
||||
bookmark.delete()
|
||||
|
@ -98,6 +98,10 @@ AUTH_PASSWORD_VALIDATORS = [
|
||||
},
|
||||
]
|
||||
|
||||
LOGIN_URL = '/login'
|
||||
LOGIN_REDIRECT_URL = '/bookmarks'
|
||||
LOGOUT_REDIRECT_URL = '/login'
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/2.2/topics/i18n/
|
||||
|
||||
|
@ -14,9 +14,12 @@ Including another URLconf
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.contrib import admin
|
||||
from django.contrib.auth import views as auth_views
|
||||
from django.urls import path, include
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
path('login/', auth_views.LoginView.as_view(redirect_authenticated_user=True), name='login'),
|
||||
path('logout/', auth_views.LogoutView.as_view(), name='logout'),
|
||||
path('', include('bookmarks.urls')),
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user