Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions core/templates/account/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{% extends "base.html" %}

{% load i18n %}
{% load account socialaccount %}

{% block head_title %}{% trans "Sign In" %}{% endblock %}

{% block content %}

<h1>{% trans "Sign In" %}</h1>

{% get_providers as socialaccount_providers %}

<p>{% blocktrans with site.name as site_name %}Please sign in with one
of your existing third party accounts:{% endblocktrans %}</p>

<div class="socialaccount_ballot">

<ul class="socialaccount_providers">
{% include "socialaccount/snippets/provider_list.html" with process="login" %}
</ul>

</div>

{% endblock %}
21 changes: 21 additions & 0 deletions core/templates/account/logout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% extends "base.html" %}

{% load i18n %}

{% block title %}{% trans "Sign Out" %}{% endblock %}

{% block content %}
<h1>{% trans "Sign Out" %}</h1>

<p>{% trans 'Are you sure you want to sign out?' %}</p>

<form method="post" action="{% url 'account_logout' %}">
{% csrf_token %}
{% if redirect_field_value %}
<input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}"/>
{% endif %}
<button type="submit">{% trans 'Sign Out' %}</button>
</form>


{% endblock %}
11 changes: 11 additions & 0 deletions core/templates/account/signup_closed.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends "base.html" %}

{% load i18n %}

{% block title %}{% trans "Sign Up Closed" %}{% endblock %}

{% block content %}
<h1>{% trans "Sign Up Closed" %}</h1>

<p>{% trans "We are sorry, but the sign up is currently closed." %}</p>
{% endblock %}
21 changes: 15 additions & 6 deletions core/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="{% static 'core/doodle.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'doodle.css' %}">
<title>Echoes: {% block title %}of the Labyrinth{% endblock %}</title>
</head>
<body class="doodle">
Expand All @@ -18,13 +18,22 @@
{# <a href="/example">django-allauth example page</a> #}
<a href="/">[Index]</a>
<a href="/about">[About]</a>
{# if user is authenticated #}
{# <a href="/accounts/login">Login</a> #}
{# else #}
{# <a href="/accounts/logout">Logout</a> #}
{# endif #}
{% if user.is_authenticated %}
<span>// Logged in as {{ user.username }} //</span>
<a href="/accounts/logout">[Logout]</a>
{% endif %}
{% endblock %}
</div>
{% if messages %}
<div>
<strong>Messages:</strong>
<ul>
{% for message in messages %}
<li>{{message}}</li>
{% endfor %}
</ul>
</div>
{% endif %}
<div id="content">
{% block content %}
{% endblock %}
Expand Down
17 changes: 11 additions & 6 deletions core/templates/index.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
{% extends 'base.html' %}
{% load socialaccount %}

{% block title %}Main page{% endblock %}

{% block content %}
<div>
<p>Some sample links, before we add proper ones:</p>
<ul>
<li><a href="vision/1/text">Look at a single vision</a></li>
<li><a href="volume/1a/text">Look at volume 1a</a></li>
<li><a href="volume/1/text">Look at volume 1</a></li>
</ul>
{% if user.is_authenticated %}
<p>Some sample links, before we add proper ones:</p>
<ul>
<li><a href="vision/1/text">Look at a single vision</a></li>
<li><a href="volume/1a/text">Look at volume 1a</a></li>
<li><a href="volume/1/text">Look at volume 1</a></li>
</ul>
{% else %}
<a href="{% provider_login_url 'github' %}">Log in with Github</a>
{% endif %}
</div>
{% endblock %}
21 changes: 21 additions & 0 deletions core/templates/socialaccount/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% extends "base.html" %}
{% load i18n %}

{% block head_title %}{% trans "Sign In" %}{% endblock %}

{% block content %}
{% if process == "connect" %}
<h1>{% blocktrans with provider.name as provider %}Connect {{ provider }}{% endblocktrans %}</h1>

<p>{% blocktrans with provider.name as provider %}You are about to connect a new third party account from {{ provider }}.{% endblocktrans %}</p>
{% else %}
<h1>{% blocktrans with provider.name as provider %}Sign In Via {{ provider }}{% endblocktrans %}</h1>

<p>{% blocktrans with provider.name as provider %}You are about to sign in using a third party account from {{ provider }}.{% endblocktrans %}</p>
{% endif %}

<form method="post">
{% csrf_token %}
<button type="submit">{% trans "Continue" %}</button>
</form>
{% endblock %}
10 changes: 7 additions & 3 deletions core/views/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
from django.template.response import SimpleTemplateResponse
from django.template.response import TemplateResponse

from login_required import login_not_required

# URL /, name "index"
@login_not_required
def index(request):
"""
Index page.
If the user is logged out, shows a login link.
If the user is logged in, shows a page that links to other pages.
"""
return SimpleTemplateResponse(template="index.html")
return TemplateResponse(request=request, template="index.html")

# URL /about, name "about"
@login_not_required
def about(request):
"""
About page.
Has a brief summary of what the website is for.
"""
return SimpleTemplateResponse(template="about.html")
return TemplateResponse(request=request, template="about.html")
1 change: 1 addition & 0 deletions core/views/plain_text.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.contrib.auth.decorators import login_required
from django.template.response import SimpleTemplateResponse

from core.models import Vision, Volume
Expand Down
12 changes: 12 additions & 0 deletions echoes_cms/auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""This houses the adapter class that we use with allauth."""
import os

from allauth.socialaccount.adapter import DefaultSocialAccountAdapter


class SocialAccountAdapter(DefaultSocialAccountAdapter):
"""Use the default social account adapter, except make is_open_for_signup
depend on an environment variable."""
def is_open_for_signup(self, request, sociallogin):
"""Along with this, we'll need to add an account/signup_closed.html template."""
return bool(os.environ.get("OPEN_FOR_SIGNUP", False))
27 changes: 27 additions & 0 deletions echoes_cms/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,15 @@
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
'django.contrib.sites',

'sortedm2m',
'debug_toolbar',

'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.github',
]

MIDDLEWARE = [
Expand All @@ -52,6 +59,7 @@
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'login_required.middleware.LoginRequiredMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
Expand Down Expand Up @@ -131,3 +139,22 @@
INTERNAL_IPS = [
'127.0.0.1',
]

# Based on https://wsvincent.com/django-allauth-tutorial/ .
AUTHENTICATION_BACKENDS = (
"django.contrib.auth.backends.ModelBackend",
"allauth.account.auth_backends.AuthenticationBackend",
)

ADAPTER = 'echoes_cms.auth.SocialAccountAdapter'

SITE_ID = 1

LOGIN_REDIRECT_URL = 'index'

LOGIN_REQUIRED_IGNORE_PATHS = [
r'/accounts/login/$',
r'/accounts/github/login/$',
r'/accounts/github/login/callback/$',
r'/admin/$',
]
1 change: 1 addition & 0 deletions echoes_cms/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
path('admin/', admin.site.urls),
path('__debug__/', include('debug_toolbar.urls')),
path('', include('core.urls')),
path('accounts/', include('allauth.urls')),
]
Loading