├── apps
├── __init__.py
├── apps
│ ├── __init__.py
│ ├── wsgi.py
│ ├── urls.py
│ └── settings.py
├── accounts
│ ├── __init__.py
│ ├── migrations
│ │ ├── __init__.py
│ │ ├── 0002_auto_20200412_2319.py
│ │ └── 0001_initial.py
│ ├── apps.py
│ ├── urls.py
│ ├── utils.py
│ ├── views.py
│ ├── templates
│ │ └── registration
│ │ │ └── login.html
│ ├── decorators.py
│ ├── admin.py
│ └── models.py
├── toppage
│ ├── __init__.py
│ ├── migrations
│ │ └── __init__.py
│ ├── apps.py
│ ├── templates
│ │ ├── customer.html
│ │ └── supporter.html
│ ├── urls.py
│ └── views.py
├── templates
│ └── base.html
└── manage.py
├── requirements.txt
├── Procfile
├── .gitignore
├── dispatcher.py
├── README-ja.md
├── README.md
└── LICENSE
/apps/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/apps/apps/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/apps/accounts/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/apps/toppage/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/apps/accounts/migrations/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/apps/toppage/migrations/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/apps/accounts/apps.py:
--------------------------------------------------------------------------------
1 | from django.apps import AppConfig
2 |
3 |
4 | class AccountsConfig(AppConfig):
5 | name = 'accounts'
6 |
--------------------------------------------------------------------------------
/apps/toppage/apps.py:
--------------------------------------------------------------------------------
1 | from django.apps import AppConfig
2 |
3 |
4 | class ToppageConfig(AppConfig):
5 | name = 'toppage'
6 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | asgiref==3.2.7
2 | bottle==0.12.20
3 | Django==3.1.14
4 | django-environ==0.4.5
5 | honcho==1.0.1
6 | pytz==2019.3
7 | sqlparse==0.3.1
8 |
--------------------------------------------------------------------------------
/apps/toppage/templates/customer.html:
--------------------------------------------------------------------------------
1 | {% extends "base.html" %}
2 |
3 | {% block content %}
4 | Customer: {{ customer.email }}, {{ customer.tel }}
5 | {% endblock %}
6 |
--------------------------------------------------------------------------------
/apps/toppage/templates/supporter.html:
--------------------------------------------------------------------------------
1 | {% extends "base.html" %}
2 |
3 | {% block content %}
4 | Supporter: {{ supporter.email }}, {{ supporter.organization }}
5 | {% endblock %}
6 |
--------------------------------------------------------------------------------
/Procfile:
--------------------------------------------------------------------------------
1 | front: PYTHONUNBUFFERED=false python apps/manage.py runserver 8000
2 | admin: PYTHONUNBUFFERED=false USER_MODEL=admin python apps/manage.py runserver 8001
3 | dispatch: PYTHONUNBUFFERED=false python dispatcher.py
4 |
--------------------------------------------------------------------------------
/apps/accounts/urls.py:
--------------------------------------------------------------------------------
1 | from django.urls import path, include
2 | from . import views
3 |
4 |
5 | urlpatterns = [
6 | path('login/', views.LoginView.as_view(), name='login'),
7 | path('logout/', views.logout_view, name='logout'),
8 | path('', include('django.contrib.auth.urls')),
9 | ]
10 |
--------------------------------------------------------------------------------
/apps/toppage/urls.py:
--------------------------------------------------------------------------------
1 | from django.urls import path
2 | from .views import index, supporter_index, customer_index
3 |
4 |
5 | app_name = 'toppage'
6 | urlpatterns = [
7 | path('', index, name='index'),
8 | path('supporter/', supporter_index, name='supporter_index'),
9 | path('customer/', customer_index, name='customer_index'),
10 | ]
--------------------------------------------------------------------------------
/apps/templates/base.html:
--------------------------------------------------------------------------------
1 | {% load admin_urls %}
2 |
3 |
4 |
5 |
6 | Title
7 |
8 |
9 |
10 | {% block content %}
11 | {% endblock %}
12 |
13 |
14 |
15 | {% if request.user.is_authenticated %}
16 |
Logout
17 | {% endif %}
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/apps/apps/wsgi.py:
--------------------------------------------------------------------------------
1 | """
2 | WSGI config for apps project.
3 |
4 | It exposes the WSGI callable as a module-level variable named ``application``.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/
8 | """
9 |
10 | import os
11 |
12 | from django.core.wsgi import get_wsgi_application
13 |
14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'apps.settings')
15 |
16 | application = get_wsgi_application()
17 |
--------------------------------------------------------------------------------
/apps/accounts/utils.py:
--------------------------------------------------------------------------------
1 | from django.core.exceptions import ObjectDoesNotExist
2 | from django.shortcuts import reverse, resolve_url
3 | from django.conf import settings
4 |
5 |
6 | def get_index_url(user):
7 | # FIXME: want have: self.request.customer or self.request.supporter
8 | if user.is_customer:
9 | return reverse('toppage:customer_index')
10 | if user.is_supporter:
11 | return reverse('toppage:supporter_index')
12 | return resolve_url(settings.LOGIN_REDIRECT_URL)
13 |
--------------------------------------------------------------------------------
/apps/accounts/views.py:
--------------------------------------------------------------------------------
1 | from django.contrib.auth.views import LoginView as BaseLoginView
2 | from django.contrib.auth import logout
3 | from django.shortcuts import redirect
4 | from .utils import get_index_url
5 |
6 |
7 | class LoginView(BaseLoginView):
8 |
9 | def get_success_url(self):
10 | url = self.get_redirect_url()
11 | return url or get_index_url(self.request.user)
12 |
13 |
14 | def logout_view(request):
15 | logout(request)
16 | return redirect('toppage:index')
17 |
--------------------------------------------------------------------------------
/apps/accounts/migrations/0002_auto_20200412_2319.py:
--------------------------------------------------------------------------------
1 | # Generated by Django 3.0.5 on 2020-04-12 14:19
2 |
3 | from django.db import migrations
4 |
5 |
6 | class Migration(migrations.Migration):
7 |
8 | dependencies = [
9 | ('accounts', '0001_initial'),
10 | ]
11 |
12 | operations = [
13 | migrations.AlterModelOptions(
14 | name='customeruser',
15 | options={'verbose_name': 'Customer', 'verbose_name_plural': 'Customers'},
16 | ),
17 | migrations.AlterModelOptions(
18 | name='supporteruser',
19 | options={'verbose_name': 'Supporter', 'verbose_name_plural': 'Supporters'},
20 | ),
21 | ]
22 |
--------------------------------------------------------------------------------
/apps/manage.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | """Django's command-line utility for administrative tasks."""
3 | import os
4 | import sys
5 |
6 |
7 | def main():
8 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'apps.settings')
9 | try:
10 | from django.core.management import execute_from_command_line
11 | except ImportError as exc:
12 | raise ImportError(
13 | "Couldn't import Django. Are you sure it's installed and "
14 | "available on your PYTHONPATH environment variable? Did you "
15 | "forget to activate a virtual environment?"
16 | ) from exc
17 | execute_from_command_line(sys.argv)
18 |
19 |
20 | if __name__ == '__main__':
21 | main()
22 |
--------------------------------------------------------------------------------
/apps/toppage/views.py:
--------------------------------------------------------------------------------
1 | from django.shortcuts import render
2 | from django.contrib.auth.decorators import login_required
3 | from accounts.decorators import login_customer_required, login_supporter_required
4 | from accounts.utils import get_index_url
5 | from django.shortcuts import redirect
6 |
7 |
8 | @login_required
9 | def index(request):
10 | url = get_index_url(request.user)
11 | return redirect(url)
12 |
13 |
14 | @login_customer_required
15 | def customer_index(request):
16 | return render(request, 'customer.html', context={'customer': request.user.customer})
17 |
18 |
19 | @login_supporter_required
20 | def supporter_index(request):
21 | return render(request, 'supporter.html', context={'supporter': request.user.supporter})
22 |
--------------------------------------------------------------------------------
/apps/apps/urls.py:
--------------------------------------------------------------------------------
1 | """apps URL Configuration
2 |
3 | The `urlpatterns` list routes URLs to views. For more information please see:
4 | https://docs.djangoproject.com/en/2.2/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
17 | from django.urls import path, include
18 |
19 |
20 | urlpatterns = [
21 | path('admin/', admin.site.urls),
22 | path('accounts/', include('accounts.urls')),
23 | path('', include('toppage.urls')),
24 | ]
25 |
--------------------------------------------------------------------------------
/apps/accounts/templates/registration/login.html:
--------------------------------------------------------------------------------
1 | {% extends "base.html" %}
2 |
3 | {% block content %}
4 |
5 | {% if form.errors %}
6 | Your username and password didn't match. Please try again.
7 | {% endif %}
8 |
9 | {% if next %}
10 | {% if user.is_authenticated %}
11 | Your account doesn't have access to this page. To proceed,
12 | please login with an account that has access.
13 | {% else %}
14 | Please login to see this page.
15 | {% endif %}
16 | {% endif %}
17 |
18 |
34 |
35 | {# Assumes you setup the password_reset view in your URLconf #}
36 | Lost password?
37 |
38 | {% endblock %}
--------------------------------------------------------------------------------
/apps/accounts/decorators.py:
--------------------------------------------------------------------------------
1 | from django.contrib.auth import REDIRECT_FIELD_NAME
2 | from django.contrib.auth.decorators import user_passes_test
3 |
4 |
5 | def login_customer_required(function=None, redirect_field_name=REDIRECT_FIELD_NAME, login_url=None):
6 | # FIXME: want to use psermission base testing: django.contrib.auth.decorators.permission_required
7 | actual_decorator = user_passes_test(
8 | lambda u: u.is_customer,
9 | login_url=login_url,
10 | redirect_field_name=redirect_field_name
11 | )
12 | if function:
13 | return actual_decorator(function)
14 | return actual_decorator
15 |
16 |
17 | def login_supporter_required(function=None, redirect_field_name=REDIRECT_FIELD_NAME, login_url=None):
18 | # FIXME: want to use psermission base testing: django.contrib.auth.decorators.permission_required
19 | actual_decorator = user_passes_test(
20 | lambda u: u.is_supporter,
21 | login_url=login_url,
22 | redirect_field_name=redirect_field_name
23 | )
24 | if function:
25 | return actual_decorator(function)
26 | return actual_decorator
27 |
--------------------------------------------------------------------------------
/apps/accounts/admin.py:
--------------------------------------------------------------------------------
1 | from django.contrib import admin
2 | from django.contrib.auth.admin import UserAdmin
3 | from django.utils.translation import gettext_lazy as _
4 |
5 | from .models import FrontUser, CustomerUser, SupporterUser
6 |
7 |
8 | # @admin.register(FrontUser)
9 | class FrontUserAdmin(UserAdmin):
10 | fieldsets = (
11 | (None, {'fields': ('email', 'password')}),
12 | (_('Permissions'), {
13 | 'fields': ('is_active',),
14 | }),
15 | (_('Important dates'), {'fields': ('last_login',)}),
16 | )
17 | add_fieldsets = (
18 | (None, {
19 | 'classes': ('wide',),
20 | 'fields': ('email', 'password1', 'password2'),
21 | }),
22 | )
23 | list_display = ('email', 'is_active', 'last_login')
24 | list_filter = ('is_active',)
25 | search_fields = ('email',)
26 | ordering = ('email',)
27 | filter_horizontal = ()
28 |
29 |
30 | @admin.register(CustomerUser)
31 | class CustomerUserAdmin(FrontUserAdmin):
32 | fieldsets = (
33 | FrontUserAdmin.fieldsets[0],
34 | ('Customer', {'fields': ('tel',)}),
35 | ) + FrontUserAdmin.fieldsets[1:]
36 | list_display = ('email', 'tel', 'is_active', 'last_login')
37 |
38 |
39 | @admin.register(SupporterUser)
40 | class SupporterUserAdmin(FrontUserAdmin):
41 | fieldsets = (
42 | FrontUserAdmin.fieldsets[0],
43 | ('Supporter', {'fields': ('organization',)}),
44 | ) + FrontUserAdmin.fieldsets[1:]
45 | list_display = ('email', 'organization', 'is_active', 'last_login')
46 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 |
6 | # C extensions
7 | *.so
8 |
9 | # Distribution / packaging
10 | .Python
11 | build/
12 | develop-eggs/
13 | dist/
14 | downloads/
15 | eggs/
16 | .eggs/
17 | lib/
18 | lib64/
19 | parts/
20 | sdist/
21 | var/
22 | wheels/
23 | *.egg-info/
24 | .installed.cfg
25 | *.egg
26 | MANIFEST
27 |
28 | # PyInstaller
29 | # Usually these files are written by a python script from a template
30 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
31 | *.manifest
32 | *.spec
33 |
34 | # Installer logs
35 | pip-log.txt
36 | pip-delete-this-directory.txt
37 |
38 | # Unit test / coverage reports
39 | htmlcov/
40 | .tox/
41 | .coverage
42 | .coverage.*
43 | .cache
44 | nosetests.xml
45 | coverage.xml
46 | *.cover
47 | .hypothesis/
48 | .pytest_cache/
49 |
50 | # Translations
51 | *.mo
52 | *.pot
53 |
54 | # Django stuff:
55 | *.log
56 | local_settings.py
57 | db.sqlite3
58 |
59 | # Flask stuff:
60 | instance/
61 | .webassets-cache
62 |
63 | # Scrapy stuff:
64 | .scrapy
65 |
66 | # Sphinx documentation
67 | docs/_build/
68 |
69 | # PyBuilder
70 | target/
71 |
72 | # Jupyter Notebook
73 | .ipynb_checkpoints
74 |
75 | # pyenv
76 | .python-version
77 |
78 | # celery beat schedule file
79 | celerybeat-schedule
80 |
81 | # SageMath parsed files
82 | *.sage.py
83 |
84 | # Environments
85 | .env
86 | .venv
87 | env/
88 | venv/
89 | ENV/
90 | env.bak/
91 | venv.bak/
92 |
93 | # Spyder project settings
94 | .spyderproject
95 | .spyproject
96 |
97 | # Rope project settings
98 | .ropeproject
99 |
100 | # mkdocs documentation
101 | /site
102 |
103 | # mypy
104 | .mypy_cache/
105 |
--------------------------------------------------------------------------------
/apps/accounts/migrations/0001_initial.py:
--------------------------------------------------------------------------------
1 | # Generated by Django 2.2.5 on 2019-09-04 18:48
2 |
3 | from django.db import migrations, models
4 | import django.db.models.deletion
5 |
6 |
7 | class Migration(migrations.Migration):
8 |
9 | initial = True
10 |
11 | dependencies = [
12 | ]
13 |
14 | operations = [
15 | migrations.CreateModel(
16 | name='FrontUser',
17 | fields=[
18 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
19 | ('password', models.CharField(max_length=128, verbose_name='password')),
20 | ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
21 | ('email', models.EmailField(max_length=254, unique=True, verbose_name='email address')),
22 | ('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
23 | ],
24 | options={
25 | 'verbose_name': 'front user',
26 | 'verbose_name_plural': 'front users',
27 | },
28 | ),
29 | migrations.CreateModel(
30 | name='CustomerUser',
31 | fields=[
32 | ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, related_name='customer', serialize=False, to='accounts.FrontUser')),
33 | ('tel', models.CharField(max_length=20, verbose_name='電話番号')),
34 | ],
35 | options={
36 | 'abstract': False,
37 | },
38 | bases=('accounts.frontuser',),
39 | ),
40 | migrations.CreateModel(
41 | name='SupporterUser',
42 | fields=[
43 | ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, related_name='supporter', serialize=False, to='accounts.FrontUser')),
44 | ('organization', models.CharField(max_length=64, verbose_name='組織')),
45 | ],
46 | options={
47 | 'abstract': False,
48 | },
49 | bases=('accounts.frontuser',),
50 | ),
51 | ]
52 |
--------------------------------------------------------------------------------
/apps/accounts/models.py:
--------------------------------------------------------------------------------
1 | from django.db import models
2 | from django.contrib.auth.models import AbstractBaseUser, BaseUserManager
3 | from django.utils.translation import gettext_lazy as _
4 | from django.core.mail import send_mail
5 | from django.core.exceptions import ObjectDoesNotExist
6 |
7 |
8 | class FrontUser(AbstractBaseUser):
9 | email = models.EmailField(_('email address'), unique=True)
10 | is_active = models.BooleanField(
11 | _('active'),
12 | default=True,
13 | help_text=_(
14 | 'Designates whether this user should be treated as active. '
15 | 'Unselect this instead of deleting accounts.'
16 | ),
17 | )
18 |
19 | objects = BaseUserManager()
20 |
21 | EMAIL_FIELD = 'email'
22 | USERNAME_FIELD = 'email'
23 | REQUIRED_FIELDS = []
24 |
25 | is_staff = False # Admin画面アクセス時に500エラーにしないために必要
26 | has_module_perms = lambda *args: False # Admin画面アクセス時に500エラーにしないために必要
27 |
28 | class Meta:
29 | verbose_name = _('front user')
30 | verbose_name_plural = _('front users')
31 |
32 | def clean(self):
33 | super().clean()
34 | self.email = self.__class__.objects.normalize_email(self.email)
35 |
36 | def email_user(self, subject, message, from_email=None, **kwargs):
37 | """Send an email to this user."""
38 | send_mail(subject, message, from_email, [self.email], **kwargs)
39 |
40 | @property
41 | def is_customer(self):
42 | try:
43 | return bool(self.customer)
44 | except ObjectDoesNotExist:
45 | return False
46 |
47 | @property
48 | def is_supporter(self):
49 | try:
50 | return bool(self.supporter)
51 | except ObjectDoesNotExist:
52 | return False
53 |
54 |
55 | class CustomerUser(FrontUser):
56 | user = models.OneToOneField(
57 | FrontUser, on_delete=models.CASCADE,
58 | parent_link=True,
59 | related_name='customer',
60 | )
61 | tel = models.CharField('電話番号', max_length=20)
62 |
63 | class Meta:
64 | verbose_name = _('Customer')
65 | verbose_name_plural = _('Customers')
66 |
67 |
68 | class SupporterUser(FrontUser):
69 | user = models.OneToOneField(
70 | FrontUser, on_delete=models.CASCADE,
71 | parent_link=True,
72 | related_name='supporter',
73 | )
74 | organization = models.CharField('組織', max_length=64)
75 |
76 | class Meta:
77 | verbose_name = _('Supporter')
78 | verbose_name_plural = _('Supporters')
79 |
--------------------------------------------------------------------------------
/dispatcher.py:
--------------------------------------------------------------------------------
1 | import os
2 |
3 | import bottle
4 | from urllib.request import urlopen, install_opener, Request, HTTPError
5 | from urllib.parse import urlparse, urlunparse
6 |
7 | PORT = os.environ.get('PORT', 8080)
8 |
9 |
10 | def opener_setup():
11 | from urllib.request import OpenerDirector, ProxyHandler, UnknownHandler, HTTPHandler, HTTPDefaultErrorHandler, DataHandler
12 | opener = OpenerDirector()
13 | for klass in [ProxyHandler, UnknownHandler, HTTPHandler, HTTPDefaultErrorHandler, DataHandler]:
14 | opener.add_handler(klass())
15 | install_opener(opener)
16 |
17 |
18 | class Router:
19 | def __init__(self, proto, domain):
20 | self.proto = proto
21 | self.domain = domain
22 |
23 | def route(self, **paths):
24 | parts = urlparse(bottle.request.url)
25 | url = urlunparse((self.proto, self.domain) + parts[2:])
26 | try:
27 | method = bottle.request.method
28 | data = bottle.request.body
29 | req = Request(url, data=data, headers=bottle.request.headers, method=method)
30 | opener_setup()
31 | uo = urlopen(req)
32 | headers = uo.getheaders()
33 | new_headers = []
34 | for k,v in headers:
35 | if self.domain in v:
36 | v = v.replace(self.domain, parts[1])
37 | new_headers.append((k, v))
38 | return bottle.HTTPResponse(uo.read(), status=uo.status, headers=dict(new_headers))
39 | except HTTPError as e:
40 | return bottle.HTTPResponse(e.reason, status=e.code, headers=dict(e.headers))
41 |
42 |
43 | front = Router('http', 'localhost:8000')
44 | admin = Router('http', 'localhost:8001')
45 |
46 | @bottle.route('/admin', method='GET')
47 | @bottle.route('/admin', method='POST')
48 | @bottle.route('/admin/', method='GET')
49 | @bottle.route('/admin/', method='POST')
50 | @bottle.route('/admin/', method='GET')
51 | @bottle.route('/admin/', method='POST')
52 | @bottle.route('/admin//', method='GET')
53 | @bottle.route('/admin//', method='POST')
54 | @bottle.route('/admin//', method='GET')
55 | @bottle.route('/admin//', method='POST')
56 | @bottle.route('/admin///', method='GET')
57 | @bottle.route('/admin///', method='POST')
58 | @bottle.route('/admin///', method='GET')
59 | @bottle.route('/admin///', method='POST')
60 | @bottle.route('/admin////', method='GET')
61 | @bottle.route('/admin////', method='POST')
62 | @bottle.route('/admin////', method='GET')
63 | @bottle.route('/admin////', method='POST')
64 | @bottle.route('/admin/////', method='GET')
65 | @bottle.route('/admin/////', method='POST')
66 | def router1(**paths):
67 | return admin.route(**paths)
68 |
69 |
70 | @bottle.route('/', method='GET')
71 | @bottle.route('/', method='POST')
72 | @bottle.route('/', method='GET')
73 | @bottle.route('/', method='POST')
74 | @bottle.route('//', method='GET')
75 | @bottle.route('//', method='POST')
76 | @bottle.route('//', method='GET')
77 | @bottle.route('//', method='POST')
78 | @bottle.route('///', method='GET')
79 | @bottle.route('///', method='POST')
80 | @bottle.route('///', method='GET')
81 | @bottle.route('///', method='POST')
82 | @bottle.route('////', method='GET')
83 | @bottle.route('////', method='POST')
84 | @bottle.route('////', method='GET')
85 | @bottle.route('////', method='POST')
86 | @bottle.route('/////', method='GET')
87 | @bottle.route('/////', method='POST')
88 | def router2(**paths):
89 | return front.route(**paths)
90 |
91 |
92 | bottle.run(host='localhost', port=int(PORT), debug=True)
93 |
94 |
--------------------------------------------------------------------------------
/apps/apps/settings.py:
--------------------------------------------------------------------------------
1 | """
2 | Django settings for apps project.
3 |
4 | Generated by 'django-admin startproject' using Django 2.2.5.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/2.2/topics/settings/
8 |
9 | For the full list of settings and their values, see
10 | https://docs.djangoproject.com/en/2.2/ref/settings/
11 | """
12 |
13 | import os
14 | import environ
15 |
16 | env = environ.Env()
17 | if env('USER_MODEL', default=None) == 'admin':
18 | AUTH_USER_MODEL = 'auth.User'
19 | SESSION_COOKIE_NAME = 'sessionadmin'
20 | else:
21 | AUTH_USER_MODEL = 'accounts.FrontUser'
22 |
23 |
24 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
25 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
26 |
27 |
28 | # Quick-start development settings - unsuitable for production
29 | # See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
30 |
31 | # SECURITY WARNING: keep the secret key used in production secret!
32 | SECRET_KEY = 'tvrx42$f()jkd-v&=n#u$txqqk51gv7sgp(jjz=!(2*w@tkya9'
33 |
34 | # SECURITY WARNING: don't run with debug turned on in production!
35 | DEBUG = True
36 |
37 | ALLOWED_HOSTS = []
38 |
39 |
40 | # Application definition
41 |
42 | INSTALLED_APPS = [
43 | 'django.contrib.admin',
44 | 'django.contrib.auth',
45 | 'django.contrib.contenttypes',
46 | 'django.contrib.sessions',
47 | 'django.contrib.messages',
48 | 'django.contrib.staticfiles',
49 |
50 | 'accounts.apps.AccountsConfig',
51 | 'toppage.apps.ToppageConfig',
52 | ]
53 |
54 | MIDDLEWARE = [
55 | 'django.middleware.security.SecurityMiddleware',
56 | 'django.contrib.sessions.middleware.SessionMiddleware',
57 | 'django.middleware.common.CommonMiddleware',
58 | 'django.middleware.csrf.CsrfViewMiddleware',
59 | 'django.contrib.auth.middleware.AuthenticationMiddleware',
60 | 'django.contrib.messages.middleware.MessageMiddleware',
61 | 'django.middleware.clickjacking.XFrameOptionsMiddleware',
62 | ]
63 |
64 | ROOT_URLCONF = 'apps.urls'
65 |
66 | TEMPLATES = [
67 | {
68 | 'BACKEND': 'django.template.backends.django.DjangoTemplates',
69 | 'DIRS': [os.path.join(BASE_DIR, 'templates')],
70 | # 'DIRS': [],
71 | 'APP_DIRS': True,
72 | 'OPTIONS': {
73 | 'context_processors': [
74 | 'django.template.context_processors.debug',
75 | 'django.template.context_processors.request',
76 | 'django.contrib.auth.context_processors.auth',
77 | 'django.contrib.messages.context_processors.messages',
78 | ],
79 | },
80 | },
81 | ]
82 |
83 | WSGI_APPLICATION = 'apps.wsgi.application'
84 |
85 |
86 | # Database
87 | # https://docs.djangoproject.com/en/2.2/ref/settings/#databases
88 |
89 | DATABASES = {
90 | 'default': {
91 | 'ENGINE': 'django.db.backends.sqlite3',
92 | 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
93 | }
94 | }
95 |
96 |
97 | # Password validation
98 | # https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators
99 |
100 | AUTH_PASSWORD_VALIDATORS = [
101 | {
102 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
103 | },
104 | {
105 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
106 | },
107 | {
108 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
109 | },
110 | {
111 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
112 | },
113 | ]
114 |
115 |
116 | # Internationalization
117 | # https://docs.djangoproject.com/en/2.2/topics/i18n/
118 |
119 | LANGUAGE_CODE = 'ja-JP'
120 |
121 | TIME_ZONE = 'Asia/Tokyo'
122 |
123 | USE_I18N = True
124 |
125 | USE_L10N = True
126 |
127 | USE_TZ = True
128 |
129 |
130 | # Static files (CSS, JavaScript, Images)
131 | # https://docs.djangoproject.com/en/2.2/howto/static-files/
132 |
133 | STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
134 | STATIC_URL = '/static/'
135 |
--------------------------------------------------------------------------------
/README-ja.md:
--------------------------------------------------------------------------------
1 | # django-multiple-type-user-auth
2 | Djangoの認証機構で複数のユーザー種別を扱う実証コード
3 |
4 | ## 実現したいこと
5 |
6 | * フロント側ユーザーとDjango管理画面のユーザーの管理を完全に分けたい
7 | * どちらの認証もDjango標準の認証機構を使いたい
8 | * フロント側ユーザーはさらに複数のユーザー種別があり、Django管理画面上での管理を別々に行いたい(一覧を別にしたい)
9 |
10 | ## 制約
11 |
12 | * Djangoの認証機構は、複数のユーザー種別を同時に扱えない(1つのユーザーテーブルのみ認証に利用できる)
13 |
14 | * "Django doesn't have multiple users" -- [django best approach for creating multiple type users](https://stackoverflow.com/a/25842236)
15 | * "First of all, you cannot make multiple authentication user base for a project." -- [python - Django 1.8, Multiple Custom User Types - Stack Overflow](https://stackoverflow.com/a/31103029)
16 |
17 | ## コンセプト
18 |
19 | * Djangoのフロント側サイトと管理画面用とで、認証に利用するユーザーモデルをそれぞれ指定するため、別々の[settings.AUTH_USER_MODEL](https://docs.djangoproject.com/ja/2.2/topics/auth/customizing/#substituting-a-custom-user-model)で起動する
20 | * フロント側ユーザーは認証用モデルを継承した [Multi Table Inheritance](https://docs.djangoproject.com/ja/2.2/topics/db/models/#multi-table-inheritance) によって別モデルとして扱う
21 |
22 | ## 仕様
23 |
24 | * 認証に使用するユーザー種別は `User` と `FrontUser`.
25 | * `User` はDjango管理画面にのみログイン可能
26 | * `FrontUser` はフロント側サイトにのみログイン可能
27 | * `FrontUser` にはさらに2種類ユーザー種別がある: `CustomerUser` と `SupporterUser`
28 | * `CustomerUser` はカスタマー用のviewにのみアクセス可能
29 | * `SupporterUser` はサポーター用のviewにのみアクセス可能
30 |
31 | ## セットアップ
32 |
33 | ```
34 | $ pip install -r requirements.txt
35 | $ python apps/manage.py migrate
36 | $ USER_MODEL=admin python apps/manage.py createsuperuser # for admin user
37 | ```
38 |
39 | ## 起動
40 |
41 | ```
42 | $ honcho start
43 | ```
44 |
45 | このコマンドで2つのDjangouプロセスと、1つのdispatcherが起動します。それぞれ以下のアドレスです:
46 |
47 | * フロント側サイト: http://localhost:8000/
48 | * Django管理サイト: http://localhost:8001/admin/
49 | * Dispatcher: http://localhost:8080/ (上記2つの手前でURL振り分ける)
50 |
51 | 最初に、先ほど作成したスーパーユーザーアカウントでDjango管理サイト http://localhost:8080/admin/ にログインして、
52 | "Customer" と "Supporter" のアカウントを作成してください。
53 |
54 | ## 動作
55 |
56 | * "Admin" ユーザーは http://localhost:8001/admin/ でのみログイン可能です
57 | * "Customer" と "Supporter" は http://localhost:8000/ でのみログイン可能です
58 | * "Customer" は http://localhost:8000/customer/ のみ表示できます
59 | * "Supporter" は http://localhost:8000/supporter/ のみ表示できます
60 | * 全てのユーザーは http://localhost:8000/accounts/logout.html でログアウトできます
61 |
62 | ## DBスキーマ
63 |
64 | `User` モデルのテーブル (django標準):
65 | ```
66 | CREATE TABLE "auth_user"
67 | (
68 | "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
69 | "password" varchar(128) NOT NULL,
70 | "last_login" datetime NULL,
71 | "is_superuser" bool NOT NULL,
72 | "username" varchar(150) NOT NULL UNIQUE,
73 | "first_name" varchar(30) NOT NULL,
74 | "email" varchar(254) NOT NULL,
75 | "is_staff" bool NOT NULL,
76 | "is_active" bool NOT NULL,
77 | "date_joined" datetime NOT NULL,
78 | "last_name" varchar(150) NOT NULL
79 | );
80 | ```
81 |
82 | `FrontUser` モデルのテーブル (フロント側ユーザーのベースモデル):
83 | ```
84 | CREATE TABLE "accounts_frontuser"
85 | (
86 | "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
87 | "password" varchar(128) NOT NULL,
88 | "last_login" datetime NULL,
89 | "email" varchar(254) NOT NULL UNIQUE,
90 | "is_active" bool NOT NULL
91 | );
92 | ```
93 |
94 | `CustomerUser` モデルのテーブル (multi-table inheritance):
95 | ```
96 | CREATE TABLE "accounts_customeruser"
97 | (
98 | "user_id" integer NOT NULL PRIMARY KEY REFERENCES "accounts_frontuser" ("id") DEFERRABLE INITIALLY DEFERRED,
99 | "tel" varchar(20) NOT NULL
100 | );
101 | ```
102 |
103 | `SupporterUser` モデルのテーブル (multi-table inheritance):
104 | ```
105 | CREATE TABLE "accounts_supporteruser"
106 | (
107 | "user_id" integer NOT NULL PRIMARY KEY REFERENCES "accounts_frontuser" ("id") DEFERRABLE INITIALLY DEFERRED,
108 | "organization" varchar(64) NOT NULL
109 | );
110 | ```
111 |
112 | # 参考文献
113 |
114 | * "カスタムの User モデルを置き換える" -- [Django の認証方法のカスタマイズ | Django ドキュメント | Django](https://docs.djangoproject.com/ja/2.2/topics/auth/customizing/#substituting-a-custom-user-model)
115 | * [Django における認証処理実装パターン - c-bata web](https://nwpct1.hatenablog.com/entry/django-auth-patterns)
116 | * [プロダクト開発してわかったDjangoの深〜いパーミッション管理の話 @ PyconJP2017](https://www.slideshare.net/hirokiky/django-pyconjp2017)
117 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # django-multiple-type-user-auth
2 | PoC django multiple type user authentication
3 |
4 | ## What I want to do
5 |
6 | * I want to completely separate user model of front-side users and Django Admin users.
7 | * Both authentication for user types must use Django's standard authentication mechanism.
8 | * Front-side users have multiple user type, so I want to manage them separately on the Django Admin.
9 |
10 | ## Constraints
11 |
12 | * Django's authentication mechanism cannot handle multiple user types in a project (only one user table can be used for authentication)
13 |
14 | * "Django doesn't have multiple users" -- [django best approach for creating multiple type users](https://stackoverflow.com/a/25842236)
15 | * "First of all, you cannot make multiple authentication user base for a project." -- [python - Django 1.8, Multiple Custom User Types - Stack Overflow](https://stackoverflow.com/a/31103029)
16 |
17 | ## Concept
18 |
19 | * Invoke server processes with separated [settings.AUTH_USER_MODEL](https://docs.djangoproject.com/en/2.2/topics/auth/customizing/#substituting-a-custom-user-model) to specify the different user model to be used for authentication on the front-side and the Django Admin.
20 | * Front-side user types are treated as separate models by [Multi Table Inheritance](https://docs.djangoproject.com/en/2.2/topics/db/models/#multi-table-inheritance), which inherits the authentication model.
21 |
22 | ## Spec
23 |
24 | * Two user models for authentication is: `User` and `FrontUser`.
25 | * `User` can only login "Django Admin".
26 | * `FrontUser` can only login "Front site".
27 | * `FrontUser` have two kind of concrete user types as `CustomerUser` and `SupporterUser`.
28 | * `CustomerUser` can access customer's views.
29 | * `SupporterUser` can access supporter's views.
30 |
31 | ## Setup
32 |
33 | ```
34 | $ pip install -r requirements.txt
35 | $ python apps/manage.py migrate
36 | $ USER_MODEL=admin python apps/manage.py createsuperuser # for admin user
37 | ```
38 |
39 | ## Invocation
40 |
41 | ```
42 | $ honcho start
43 | ```
44 |
45 | This command invokes 2 django application and 1 dispatcher process as:
46 |
47 | * Front: http://localhost:8000/
48 | * Admin: http://localhost:8001/admin/
49 | * Dispatcher: http://localhost:8080/
50 |
51 | At first, you must create "Customer" and "Supporter" users in Django Admin
52 | http://localhost:8080/admin/ with using created super user account.
53 |
54 | ## Behaviors
55 |
56 | * "Admin" user can only login from http://localhost:8001/admin/
57 | * "Customer" and "Supporter" can only login from http://localhost:8000/
58 | * "Customer" can only view http://localhost:8000/customer/
59 | * "Supporter" can only view http://localhost:8000/supporter/
60 | * All users can logout from http://localhost:8000/accounts/logout.html
61 |
62 | ## Schemas
63 |
64 | `User` model table (django default):
65 | ```
66 | CREATE TABLE "auth_user"
67 | (
68 | "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
69 | "password" varchar(128) NOT NULL,
70 | "last_login" datetime NULL,
71 | "is_superuser" bool NOT NULL,
72 | "username" varchar(150) NOT NULL UNIQUE,
73 | "first_name" varchar(30) NOT NULL,
74 | "email" varchar(254) NOT NULL,
75 | "is_staff" bool NOT NULL,
76 | "is_active" bool NOT NULL,
77 | "date_joined" datetime NOT NULL,
78 | "last_name" varchar(150) NOT NULL
79 | );
80 | ```
81 |
82 | `FrontUser` model table (Base user model for front side):
83 | ```
84 | CREATE TABLE "accounts_frontuser"
85 | (
86 | "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
87 | "password" varchar(128) NOT NULL,
88 | "last_login" datetime NULL,
89 | "email" varchar(254) NOT NULL UNIQUE,
90 | "is_active" bool NOT NULL
91 | );
92 | ```
93 |
94 | `CustomerUser` model table (multi-table inheritance):
95 | ```
96 | CREATE TABLE "accounts_customeruser"
97 | (
98 | "user_id" integer NOT NULL PRIMARY KEY REFERENCES "accounts_frontuser" ("id") DEFERRABLE INITIALLY DEFERRED,
99 | "tel" varchar(20) NOT NULL
100 | );
101 | ```
102 |
103 | `SupporterUser` model table (multi-table inheritance):
104 | ```
105 | CREATE TABLE "accounts_supporteruser"
106 | (
107 | "user_id" integer NOT NULL PRIMARY KEY REFERENCES "accounts_frontuser" ("id") DEFERRABLE INITIALLY DEFERRED,
108 | "organization" varchar(64) NOT NULL
109 | );
110 | ```
111 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------