Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
D
django-url-follower
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nikolaos S. Papaspyrou
django-url-follower
Commits
fd473073
Commit
fd473073
authored
Jun 15, 2015
by
Nikolaos S. Papaspyrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add part 5, user authentication
parent
e9a5d5b2
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
61 additions
and
2 deletions
+61
-2
README.md
README.md
+7
-0
settings.py
redurl/settings.py
+5
-0
urls.py
redurl/urls.py
+2
-0
base.html
urlapp/templates/base.html
+6
-1
login.html
urlapp/templates/registration/login.html
+38
-0
views.py
urlapp/views.py
+3
-1
No files found.
README.md
View file @
fd473073
...
@@ -110,3 +110,10 @@ Edit `urlapp/templates/index.html`.
...
@@ -110,3 +110,10 @@ Edit `urlapp/templates/index.html`.
Make it redirect and count!
Make it redirect and count!
Edit
`urlapp/views.py`
.
Edit
`urlapp/views.py`
.
Add a base template, using bootstrap!
Part 5
------
Require user authentication.
redurl/settings.py
View file @
fd473073
...
@@ -101,3 +101,8 @@ USE_TZ = True
...
@@ -101,3 +101,8 @@ USE_TZ = True
# https://docs.djangoproject.com/en/1.8/howto/static-files/
# https://docs.djangoproject.com/en/1.8/howto/static-files/
STATIC_URL
=
'/static/'
STATIC_URL
=
'/static/'
# Authentication
LOGIN_URL
=
'/login/'
redurl/urls.py
View file @
fd473073
...
@@ -15,8 +15,10 @@ Including another URLconf
...
@@ -15,8 +15,10 @@ Including another URLconf
"""
"""
from
django.conf.urls
import
include
,
url
from
django.conf.urls
import
include
,
url
from
django.contrib
import
admin
from
django.contrib
import
admin
from
django.contrib.auth
import
views
as
auth_views
urlpatterns
=
[
urlpatterns
=
[
url
(
r'^'
,
include
(
'urlapp.urls'
)),
url
(
r'^'
,
include
(
'urlapp.urls'
)),
url
(
r'^'
,
include
(
'django.contrib.auth.urls'
)),
url
(
r'^admin/'
,
include
(
admin
.
site
.
urls
)),
url
(
r'^admin/'
,
include
(
admin
.
site
.
urls
)),
]
]
urlapp/templates/base.html
View file @
fd473073
...
@@ -16,6 +16,11 @@
...
@@ -16,6 +16,11 @@
URL follower
URL follower
</a>
</a>
</div>
</div>
<ul
class=
"nav navbar-nav navbar-right"
>
{% if user.is_authenticated %}
<li><a
href=
"{% url 'logout' %}"
>
Logout
</a></li>
{% endif %}
</ul>
</div>
</div>
</nav>
</nav>
<div
class=
"container"
>
<div
class=
"container"
>
...
...
urlapp/templates/registration/login.html
0 → 100644
View file @
fd473073
{% extends "base.html" %}
{% block content %}
{% if form.errors %}
<p>
Your username and password didn't match. Please try again.
</p>
{% endif %}
{% if next %}
{% if user.is_authenticated %}
<p>
Your account doesn't have access to this page. To proceed,
please login with an account that has access.
</p>
{% else %}
<p>
Please login to see this page.
</p>
{% endif %}
{% endif %}
<form
method=
"post"
action=
"{% url 'django.contrib.auth.views.login' %}"
>
{% csrf_token %}
<table>
<tr>
<td>
{{ form.username.label_tag }}
</td>
<td>
{{ form.username }}
</td>
</tr>
<tr>
<td>
{{ form.password.label_tag }}
</td>
<td>
{{ form.password }}
</td>
</tr>
</table>
<input
type=
"submit"
value=
"login"
/>
<input
type=
"hidden"
name=
"next"
value=
"{{ next }}"
/>
</form>
{# Assumes you setup the password_reset view in your URLconf #}
<p><a
href=
"{% url 'password_reset' %}"
>
Lost password?
</a></p>
{% endblock %}
urlapp/views.py
View file @
fd473073
from
django.shortcuts
import
render
,
get_object_or_404
,
redirect
from
django.shortcuts
import
render
,
get_object_or_404
,
redirect
from
django.
http
import
HttpResponse
from
django.
contrib.auth.decorators
import
login_required
from
.models
import
Url
from
.models
import
Url
# Create your views here.
# Create your views here.
@
login_required
def
index
(
request
):
def
index
(
request
):
context
=
{
context
=
{
'url_list'
:
Url
.
objects
.
all
()
'url_list'
:
Url
.
objects
.
all
()
...
@@ -17,6 +18,7 @@ def redir(request, url_id):
...
@@ -17,6 +18,7 @@ def redir(request, url_id):
u
.
save
()
u
.
save
()
return
redirect
(
u
.
target
)
return
redirect
(
u
.
target
)
@
login_required
def
url
(
request
,
url_id
):
def
url
(
request
,
url_id
):
context
=
{
context
=
{
'url'
:
get_object_or_404
(
Url
,
id
=
url_id
)
'url'
:
get_object_or_404
(
Url
,
id
=
url_id
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment