신은섭(Shin Eun Seop)

add login

...@@ -23,6 +23,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) ...@@ -23,6 +23,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
23 SECRET_KEY = '534f6m=i@*)=q3kuwlge1m3c+@^cabr3ttcx*omv^+dorydjfr' 23 SECRET_KEY = '534f6m=i@*)=q3kuwlge1m3c+@^cabr3ttcx*omv^+dorydjfr'
24 24
25 # SECURITY WARNING: don't run with debug turned on in production! 25 # SECURITY WARNING: don't run with debug turned on in production!
26 +# TODO
26 DEBUG = True 27 DEBUG = True
27 28
28 ALLOWED_HOSTS = [] 29 ALLOWED_HOSTS = []
...@@ -121,3 +122,8 @@ USE_TZ = True ...@@ -121,3 +122,8 @@ USE_TZ = True
121 # https://docs.djangoproject.com/en/2.0/howto/static-files/ 122 # https://docs.djangoproject.com/en/2.0/howto/static-files/
122 123
123 STATIC_URL = '/static/' 124 STATIC_URL = '/static/'
125 +
126 +
127 +# Login redirect
128 +
129 +LOGIN_REDIRECT_URL = '/'
...\ No newline at end of file ...\ No newline at end of file
......
1 -"""dcloud URL Configuration
2 -
3 -The `urlpatterns` list routes URLs to views. For more information please see:
4 - https://docs.djangoproject.com/en/2.0/topics/http/urls/
5 -Examples:
6 -Function views
7 - 1. Add an import: from my_app import views
8 - 2. Add a URL to urlpatterns: path('', views.home, name='home')
9 -Class-based views
10 - 1. Add an import: from other_app.views import Home
11 - 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
12 -Including another URLconf
13 - 1. Import the include() function: from django.urls import include, path
14 - 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
15 -"""
16 from django.contrib import admin 1 from django.contrib import admin
17 from django.conf.urls import url, include 2 from django.conf.urls import url, include
3 +from django.contrib.auth import views
18 4
19 5
20 urlpatterns = [ 6 urlpatterns = [
21 url(r'^admin/', admin.site.urls), 7 url(r'^admin/', admin.site.urls),
8 + url(r'^accounts/login/$', views.login, name='login'),
9 + url(r'^accounts/logout/$', views.logout, name='logout', kwargs={'next_page': '/'}),
22 url(r'^restapi/', include('restful.urls')), 10 url(r'^restapi/', include('restful.urls')),
23 url(r'^', include('website.urls')), 11 url(r'^', include('website.urls')),
24 ] 12 ]
...\ No newline at end of file ...\ No newline at end of file
......
1 -from restful.models import File 1 +from django.http import Http404
2 -from restful.serializers import FileSerializer 2 +from django.contrib.auth.decorators import login_required
3 -from django.http import Http404
4 from rest_framework.views import APIView 3 from rest_framework.views import APIView
5 from rest_framework.response import Response 4 from rest_framework.response import Response
6 from rest_framework import status 5 from rest_framework import status
7 6
7 +from restful.models import File
8 +from restful.serializers import FileSerializer
8 9
9 -# Create your views here.
10 class FileList(APIView): 10 class FileList(APIView):
11 """ 11 """
12 List all file, or create a new snippet. 12 List all file, or create a new snippet.
......
1 -{% extends "base_generic.html" %} 1 +{% extends "website/base.html" %}
2 2
3 {% block content %} 3 {% block content %}
4 - 4 + {% if form.errors %}
5 -{% if form.errors %} 5 + <p>이름과 비밀번호가 일치하지 않습니다. 다시 시도해주세요.</p>
6 -<p>Your username and password didn't match. Please try again.</p>
7 -{% endif %}
8 -
9 -{% if next %}
10 - {% if user.is_authenticated %}
11 - <p>Your account doesn't have access to this page. To proceed,
12 - please login with an account that has access.</p>
13 - {% else %}
14 - <p>Please login to see this page.</p>
15 {% endif %} 6 {% endif %}
16 -{% endif %}
17 -
18 -<form method="post" action="{% url 'login' %}">
19 -{% csrf_token %}
20 -
21 -<div>
22 - <td>{{ form.username.label_tag }}</td>
23 - <td>{{ form.username }}</td>
24 -</div>
25 -<div>
26 - <td>{{ form.password.label_tag }}</td>
27 - <td>{{ form.password }}</td>
28 -</div>
29 -
30 -<div>
31 - <input type="submit" value="login" />
32 - <input type="hidden" name="next" value="{{ next }}" />
33 -</div>
34 -</form>
35 -
36 -{# Assumes you setup the password_reset view in your URLconf #}
37 -<p><a href="{% url 'password_reset' %}">Lost password?</a></p>
38 7
8 + <form method="post" action="{% url 'login' %}">
9 + {% csrf_token %}
10 + <table>
11 + <tr>
12 + <td>{{ form.username.label_tag }}</td>
13 + <td>{{ form.username }}</td>
14 + </tr>
15 + <tr>
16 + <td>{{ form.password.label_tag }}</td>
17 + <td>{{ form.password }}</td>
18 + </tr>
19 + </table>
20 +
21 + <input type="submit" value="login" />
22 + <input type="hidden" name="next" value="{{ next }}" />
23 + </form>
39 {% endblock %} 24 {% endblock %}
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -10,16 +10,19 @@ ...@@ -10,16 +10,19 @@
10 <body> 10 <body>
11 <div class="page-header"> 11 <div class="page-header">
12 {% if user.is_authenticated %} 12 {% if user.is_authenticated %}
13 - <a href="{% url 'post_new' %}" class="top-menu"><span class="glyphicon glyphicon-plus"></span></a> 13 + <a href="{% url 'post_new' %}" class="top-menu"><span class="glyphicon glyphicon-plus"></span></a>
14 <a href="{% url 'post_draft_list' %}" class="top-menu"><span class="glyphicon glyphicon-edit"></span></a> 14 <a href="{% url 'post_draft_list' %}" class="top-menu"><span class="glyphicon glyphicon-edit"></span></a>
15 + <p class="top-menu">Hello {{ user.username }} <small>(<a href="{% url 'logout' %}">Log out</a>)</small></p>
16 + {% else %}
17 + <a href="{% url 'login' %}" class="top-menu"><span class="glyphicon glyphicon-lock"></span></a>
15 {% endif %} 18 {% endif %}
16 <h1><a href="/">Django Girls Blog</a></h1> 19 <h1><a href="/">Django Girls Blog</a></h1>
17 </div> 20 </div>
18 <div class="content container"> 21 <div class="content container">
19 <div class="row"> 22 <div class="row">
20 <div class="col-md-8"> 23 <div class="col-md-8">
21 - {% block content %} 24 + {% block content %}
22 - {% endblock %} 25 + {% endblock %}
23 </div> 26 </div>
24 </div> 27 </div>
25 </div> 28 </div>
......
...@@ -2,6 +2,7 @@ from django.conf.urls import url ...@@ -2,6 +2,7 @@ from django.conf.urls import url
2 from website import views 2 from website import views
3 3
4 urlpatterns = [ 4 urlpatterns = [
5 + # blog
5 url(r'^$', views.post_list, name='post_list'), 6 url(r'^$', views.post_list, name='post_list'),
6 url(r'^post/(?P<pk>\d+)/$', views.post_detail, name='post_detail'), 7 url(r'^post/(?P<pk>\d+)/$', views.post_detail, name='post_detail'),
7 url(r'^post/new/$', views.post_new, name='post_new'), 8 url(r'^post/new/$', views.post_new, name='post_new'),
......
1 from django.shortcuts import render, get_object_or_404, redirect 1 from django.shortcuts import render, get_object_or_404, redirect
2 from django.utils import timezone 2 from django.utils import timezone
3 +from django.contrib.auth.decorators import login_required
3 from website.models import Post 4 from website.models import Post
4 from restful.models import File 5 from restful.models import File
5 from website.forms import PostForm 6 from website.forms import PostForm
6 7
7 8
8 9
9 -# Create your views here.
10 def post_list(request): 10 def post_list(request):
11 posts = Post.objects.filter(published_date__lte=timezone.now()).order_by('published_date') 11 posts = Post.objects.filter(published_date__lte=timezone.now()).order_by('published_date')
12 return render(request, 'website/post_list.html', {'posts':posts}) 12 return render(request, 'website/post_list.html', {'posts':posts})
...@@ -19,6 +19,7 @@ def post_detail(request, pk): ...@@ -19,6 +19,7 @@ def post_detail(request, pk):
19 post = get_object_or_404(Post, pk=pk) 19 post = get_object_or_404(Post, pk=pk)
20 return render(request, 'website/post_detail.html', {'post': post}) 20 return render(request, 'website/post_detail.html', {'post': post})
21 21
22 +@login_required
22 def post_new(request): 23 def post_new(request):
23 if request.method == "POST": 24 if request.method == "POST":
24 form = PostForm(request.POST) 25 form = PostForm(request.POST)
...@@ -32,6 +33,7 @@ def post_new(request): ...@@ -32,6 +33,7 @@ def post_new(request):
32 form = PostForm() 33 form = PostForm()
33 return render(request, 'website/post_edit.html', {'form': form}) 34 return render(request, 'website/post_edit.html', {'form': form})
34 35
36 +@login_required
35 def post_edit(request, pk): 37 def post_edit(request, pk):
36 post = get_object_or_404(Post, pk=pk) 38 post = get_object_or_404(Post, pk=pk)
37 if request.method == "POST": 39 if request.method == "POST":
...@@ -46,10 +48,12 @@ def post_edit(request, pk): ...@@ -46,10 +48,12 @@ def post_edit(request, pk):
46 form = PostForm(instance=post) 48 form = PostForm(instance=post)
47 return render(request, 'website/post_edit.html', {'form': form}) 49 return render(request, 'website/post_edit.html', {'form': form})
48 50
51 +@login_required
49 def post_draft_list(request): 52 def post_draft_list(request):
50 posts = Post.objects.filter(published_date__isnull=True).order_by('created_date') 53 posts = Post.objects.filter(published_date__isnull=True).order_by('created_date')
51 return render(request, 'website/post_draft_list.html', {'posts': posts}) 54 return render(request, 'website/post_draft_list.html', {'posts': posts})
52 55
56 +@login_required
53 def post_publish(request, pk): 57 def post_publish(request, pk):
54 post = get_object_or_404(Post, pk=pk) 58 post = get_object_or_404(Post, pk=pk)
55 post.publish() 59 post.publish()
......