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
153b80c1
Commit
153b80c1
authored
Jun 15, 2015
by
Nikolaos S. Papaspyrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add user authentication
parent
b1adf840
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
53 additions
and
0 deletions
+53
-0
settings.py
myprj/settings.py
+5
-0
urls.py
myprj/urls.py
+2
-0
base.html
urlforward/templates/base.html
+5
-0
login.html
urlforward/templates/registration/login.html
+38
-0
views.py
urlforward/views.py
+3
-0
No files found.
myprj/settings.py
View file @
153b80c1
...
...
@@ -101,3 +101,8 @@ USE_TZ = True
# https://docs.djangoproject.com/en/1.8/howto/static-files/
STATIC_URL
=
'/static/'
# Authentication
LOGIN_URL
=
'/login/'
myprj/urls.py
View file @
153b80c1
...
...
@@ -15,8 +15,10 @@ Including another URLconf
"""
from
django.conf.urls
import
include
,
url
from
django.contrib
import
admin
from
django.contrib.auth
import
views
as
auth_views
urlpatterns
=
[
url
(
r'^'
,
include
(
'urlforward.urls'
)),
url
(
r'^'
,
include
(
'django.contrib.auth.urls'
)),
url
(
r'^admin/'
,
include
(
admin
.
site
.
urls
)),
]
urlforward/templates/base.html
View file @
153b80c1
...
...
@@ -16,6 +16,11 @@
URL follower
</a>
</div>
<ul
class=
"nav navbar-nav navbar-right"
>
{% if user.is_authenticated %}
<li><a
href=
"{% url 'logout' %}"
>
Logout
</a></li>
{% endif %}
</ul>
</div>
</nav>
<div
class=
"container"
>
...
...
urlforward/templates/registration/login.html
0 → 100644
View file @
153b80c1
{% 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 %}
urlforward/views.py
View file @
153b80c1
from
django.shortcuts
import
render
,
redirect
,
get_object_or_404
from
django.contrib.auth.decorators
import
login_required
from
.models
import
Url
# Create your views here.
@
login_required
def
index
(
request
):
context
=
{
'url_list'
:
Url
.
objects
.
all
()
...
...
@@ -16,6 +18,7 @@ def redir(request, url_id):
u
.
save
()
return
redirect
(
u
.
target
)
@
login_required
def
details
(
request
,
url_id
):
context
=
{
'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