├── .github └── dependabot.yml ├── .gitignore ├── .travis.yml ├── LICENSE ├── MANIFEST.in ├── README.rst ├── discord_bind ├── __init__.py ├── admin.py ├── apps.py ├── conf.py ├── migrations │ ├── 0001_initial.py │ ├── 0002_auto_20191006_1523.py │ └── __init__.py ├── models.py ├── tests │ ├── __init__.py │ ├── test_callback_view.py │ ├── test_index_view.py │ └── test_models.py ├── urls.py └── views.py ├── docs ├── Makefile ├── changelog.rst ├── conf.py ├── index.rst ├── installation.rst ├── make.bat └── settings.rst ├── manage.py ├── requirements.txt ├── setup.cfg ├── setup.py └── test_settings.py /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: pip 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | open-pull-requests-limit: 10 8 | -------------------------------------------------------------------------------- /.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 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | local_settings.py 55 | pep8.txt 56 | test.db 57 | 58 | # Flask stuff: 59 | instance/ 60 | .webassets-cache 61 | 62 | # Scrapy stuff: 63 | .scrapy 64 | 65 | # Sphinx documentation 66 | docs/_build/ 67 | 68 | # PyBuilder 69 | target/ 70 | 71 | # IPython Notebook 72 | .ipynb_checkpoints 73 | 74 | # pyenv 75 | .python-version 76 | 77 | # celery beat schedule file 78 | celerybeat-schedule 79 | 80 | # dotenv 81 | .env 82 | 83 | # virtualenv 84 | venv/ 85 | ENV/ 86 | 87 | # Spyder project settings 88 | .spyderproject 89 | 90 | # Rope project settings 91 | .ropeproject 92 | 93 | # PyDev 94 | .project 95 | .pydevproject 96 | .settings/ 97 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: 3 | - "2.7" 4 | - "3.4" 5 | - "3.5" 6 | env: 7 | - DJANGO=1.9 8 | - DJANGO=1.10 9 | install: 10 | - pip install -q Django==$DJANGO 11 | - python setup.py -q install 12 | script: 13 | - python setup.py test 14 | notifications: 15 | email: false 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Mark Rogaski 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include LICENSE 2 | include README.rst 3 | recursive-include docs * 4 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | django-discord-bind 2 | =================== 3 | 4 | *A Django app for securely associating a user with a Discord account.* 5 | 6 | .. image:: https://badge.fury.io/py/django-discord-bind.svg 7 | :target: https://badge.fury.io/py/django-discord-bind 8 | :alt: Git Repository 9 | .. image:: https://travis-ci.org/mrogaski/django-discord-bind.svg?branch=master 10 | :target: https://travis-ci.org/mrogaski/django-discord-bind 11 | :alt: Build Status 12 | .. image:: https://readthedocs.org/projects/django-discord-bind/badge/?version=latest 13 | :target: http://django-discord-bind.readthedocs.io/en/latest/?badge=latest 14 | :alt: Documentation Status 15 | 16 | This is a simple Django application that allows users to associate one or 17 | more Discord accounts to their Django accounts and automatically join a 18 | partner Discord server using the 19 | `OAuth2 functionality of the Discord API `_. 20 | 21 | Requirements 22 | ------------ 23 | 24 | * Python 2.7, 3.4, 3.5 25 | * Django 1.9, 1.10 26 | 27 | License 28 | ------- 29 | 30 | django-discord-bind is released under the terms of the MIT license. 31 | Full details in LICENSE file. 32 | 33 | -------------------------------------------------------------------------------- /discord_bind/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016, Mark Rogaski 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | """ 26 | # following PEP 386 27 | __version__ = '0.2.1' 28 | 29 | default_app_config = 'discord_bind.apps.DiscordBindConfig' 30 | -------------------------------------------------------------------------------- /discord_bind/admin.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016, Mark Rogaski 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | """ 26 | from django.contrib import admin 27 | from .models import DiscordUser, DiscordInvite 28 | 29 | 30 | @admin.register(DiscordUser) 31 | class DiscordUserAdmin(admin.ModelAdmin): 32 | list_display = ('user', 33 | 'uid', 34 | 'username', 35 | 'discriminator', 36 | 'email') 37 | list_display_links = ('uid',) 38 | fieldsets = ( 39 | (None, { 40 | 'fields': ('user',), 41 | }), 42 | ('Discord Account', { 43 | 'fields': ('uid', 44 | ('username', 'discriminator'), 45 | 'email', 'avatar'), 46 | }), 47 | ('OAuth2', { 48 | 'classes': ('collapse',), 49 | 'fields': ('access_token', 'refresh_token', 'scope', 'expiry'), 50 | }), 51 | ) 52 | readonly_fields = ('user', 53 | 'uid', 54 | 'access_token', 55 | 'refresh_token', 56 | 'scope', 57 | 'expiry') 58 | search_fields = ['user__username', 59 | 'user__email', 60 | 'username', 61 | 'discriminator', 62 | 'uid', 63 | 'email'] 64 | 65 | 66 | @admin.register(DiscordInvite) 67 | class DiscordInviteAdmin(admin.ModelAdmin): 68 | list_display = ('code', 69 | 'active', 70 | 'description', 71 | 'guild_name', 72 | 'channel_name', 73 | 'channel_type') 74 | list_display_links = ('code',) 75 | fieldsets = ( 76 | (None, { 77 | 'fields': (('code', 'active'), 'description', 'groups'), 78 | }), 79 | ('Discord Guild', { 80 | 'fields': ('guild_name', 'guild_id', 'guild_icon'), 81 | }), 82 | ('Discord Channel', { 83 | 'fields': ('channel_name', 'channel_id', 'channel_type'), 84 | }), 85 | ) 86 | readonly_fields = ('guild_name', 87 | 'guild_id', 88 | 'guild_icon', 89 | 'channel_name', 90 | 'channel_id', 91 | 'channel_type') 92 | filter_horizontal = ('groups',) 93 | actions = ['update_context'] 94 | 95 | def update_context(self, request, queryset): 96 | """ Pull invite details from Discord """ 97 | update = 0 98 | delete = 0 99 | invites = queryset.all() 100 | for invite in invites: 101 | if invite.update_context(): 102 | update += 1 103 | else: 104 | invite.delete() 105 | delete += 1 106 | self.message_user(request, '%d updated, %d deleted' % (update, delete)) 107 | update_context.short_description = 'Update invite context' 108 | -------------------------------------------------------------------------------- /discord_bind/apps.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016, Mark Rogaski 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | """ 26 | from django.apps import AppConfig 27 | from django.utils.translation import gettext_lazy as _ 28 | 29 | 30 | class DiscordBindConfig(AppConfig): 31 | """Application config""" 32 | 33 | name = "discord_bind" 34 | verbose_name = _("Discord Binding") 35 | 36 | def ready(self): 37 | from . import conf 38 | -------------------------------------------------------------------------------- /discord_bind/conf.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016, Mark Rogaski 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | """ 26 | from __future__ import unicode_literals 27 | 28 | from django.conf import settings 29 | from appconf import AppConf 30 | 31 | 32 | class DiscordBindConf(AppConf): 33 | """ Application settings """ 34 | # API service endpoints 35 | BASE_URI = 'https://discordapp.com/api' 36 | AUTHZ_PATH = '/oauth2/authorize' 37 | TOKEN_PATH = '/oauth2/token' 38 | 39 | # OAuth2 application credentials 40 | CLIENT_ID = None 41 | CLIENT_SECRET = None 42 | 43 | # OAuth2 scope 44 | EMAIL_SCOPE = True 45 | 46 | # URI settings 47 | REDIRECT_URI = None 48 | INVITE_URI = 'https://discordapp.com/channels/@me' 49 | RETURN_URI = '/' 50 | 51 | # For upgrade to Django 3.2 52 | default_auto_field = 'django.db.models.AutoField' 53 | 54 | class Meta: 55 | proxy = True 56 | prefix = 'discord' 57 | required = ['CLIENT_ID', 'CLIENT_SECRET'] 58 | -------------------------------------------------------------------------------- /discord_bind/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Generated by Django 1.10 on 2016-08-13 12:50 3 | from __future__ import unicode_literals 4 | 5 | from django.conf import settings 6 | from django.db import migrations, models 7 | import django.db.models.deletion 8 | 9 | 10 | class Migration(migrations.Migration): 11 | 12 | initial = True 13 | 14 | dependencies = [] 15 | 16 | operations = [ 17 | migrations.CreateModel( 18 | name='DiscordInvite', 19 | fields=[ 20 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 21 | ('code', models.CharField(max_length=32, unique=True)), 22 | ('active', models.BooleanField(default=False)), 23 | ('description', models.CharField(blank=True, max_length=256)), 24 | ('guild_name', models.CharField(blank=True, max_length=64)), 25 | ('guild_id', models.CharField(blank=True, max_length=20)), 26 | ('guild_icon', models.CharField(blank=True, max_length=32)), 27 | ('channel_name', models.CharField(blank=True, max_length=64)), 28 | ('channel_id', models.CharField(blank=True, max_length=20)), 29 | ('channel_type', models.CharField(blank=True, choices=[('text', 'text'), ('voice', 'voice')], max_length=5)), 30 | ('groups', models.ManyToManyField(blank=True, related_name='discord_invites', to='auth.Group')), 31 | ], 32 | ), 33 | migrations.CreateModel( 34 | name='DiscordUser', 35 | fields=[ 36 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 37 | ('uid', models.CharField(max_length=20, unique=True)), 38 | ('username', models.CharField(max_length=254)), 39 | ('discriminator', models.CharField(max_length=4)), 40 | ('avatar', models.CharField(blank=True, max_length=32)), 41 | ('email', models.EmailField(blank=True, max_length=254)), 42 | ('access_token', models.CharField(blank=True, max_length=32)), 43 | ('refresh_token', models.CharField(blank=True, max_length=32)), 44 | ('scope', models.CharField(blank=True, max_length=256)), 45 | ('expiry', models.DateTimeField(null=True)), 46 | ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), 47 | ], 48 | ), 49 | ] 50 | -------------------------------------------------------------------------------- /discord_bind/migrations/0002_auto_20191006_1523.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 2.2.6 on 2019-10-06 15:23 2 | 3 | from django.conf import settings 4 | from django.db import migrations, models 5 | import django.db.models.deletion 6 | 7 | 8 | class Migration(migrations.Migration): 9 | 10 | dependencies = [ 11 | ('discord_bind', '0001_initial'), 12 | ] 13 | 14 | operations = [ 15 | migrations.AlterField( 16 | model_name='discorduser', 17 | name='user', 18 | field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='discord_user', to=settings.AUTH_USER_MODEL), 19 | ), 20 | ] 21 | -------------------------------------------------------------------------------- /discord_bind/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiarena/django-discord-bind/6c987450c2573ae73537d4ea89ec76679c0418f2/discord_bind/migrations/__init__.py -------------------------------------------------------------------------------- /discord_bind/models.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016, Mark Rogaski 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | """ 26 | from __future__ import unicode_literals 27 | 28 | import requests 29 | from django.db import models 30 | from django.contrib.auth.models import User, Group 31 | from six import python_2_unicode_compatible 32 | from discord_bind.conf import settings 33 | from django.conf import settings as django_settings 34 | 35 | import logging 36 | logger = logging.getLogger(__name__) 37 | 38 | 39 | @python_2_unicode_compatible 40 | class DiscordUser(models.Model): 41 | """ Discord User mapping. """ 42 | user = models.OneToOneField(django_settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="discord_user") 43 | uid = models.CharField(max_length=20, blank=False, unique=True) 44 | username = models.CharField(max_length=254) 45 | discriminator = models.CharField(max_length=4) 46 | avatar = models.CharField(max_length=32, blank=True) 47 | email = models.EmailField(max_length=254, blank=True) 48 | access_token = models.CharField(max_length=32, blank=True) 49 | refresh_token = models.CharField(max_length=32, blank=True) 50 | scope = models.CharField(max_length=256, blank=True) 51 | expiry = models.DateTimeField(null=True) 52 | 53 | def __str__(self): 54 | return self.username + '.' + self.discriminator 55 | 56 | 57 | @python_2_unicode_compatible 58 | class DiscordInvite(models.Model): 59 | """ Discord instant invites """ 60 | TEXT = 'text' 61 | VOICE = 'voice' 62 | CHANNEL_TYPE_CHOICES = ( 63 | (TEXT, 'text'), 64 | (VOICE, 'voice'), 65 | ) 66 | 67 | code = models.CharField(max_length=32, unique=True) 68 | active = models.BooleanField(default=False) 69 | groups = models.ManyToManyField(Group, blank=True, 70 | related_name='discord_invites') 71 | description = models.CharField(max_length=256, blank=True) 72 | guild_name = models.CharField(max_length=64, blank=True) 73 | guild_id = models.CharField(max_length=20, blank=True) 74 | guild_icon = models.CharField(max_length=32, blank=True) 75 | channel_name = models.CharField(max_length=64, blank=True) 76 | channel_id = models.CharField(max_length=20, blank=True) 77 | channel_type = models.CharField(max_length=5, blank=True, 78 | choices=CHANNEL_TYPE_CHOICES) 79 | 80 | def __str__(self): 81 | return self.code 82 | 83 | def update_context(self): 84 | result = False 85 | r = requests.get(settings.DISCORD_BASE_URI + '/invites/' + self.code) 86 | if r.status_code == requests.codes.ok: 87 | logger.info('fetched data for Discord invite %s' % self.code) 88 | invite = r.json() 89 | try: 90 | self.guild_name = invite['guild']['name'] 91 | self.guild_id = invite['guild']['id'] 92 | self.guild_icon = invite['guild']['icon'] 93 | self.channel_name = invite['channel']['name'] 94 | self.channel_id = invite['channel']['id'] 95 | self.channel_type = invite['channel']['type'] 96 | self.save() 97 | result = True 98 | except KeyError: 99 | pass 100 | else: 101 | logger.error(('failed to fetch data for ' 102 | 'Discord invite %s: %d %s') % (self.code, 103 | r.status_code, 104 | r.reason)) 105 | return result 106 | -------------------------------------------------------------------------------- /discord_bind/tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aiarena/django-discord-bind/6c987450c2573ae73537d4ea89ec76679c0418f2/discord_bind/tests/__init__.py -------------------------------------------------------------------------------- /discord_bind/tests/test_callback_view.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016, Mark Rogaski 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | """ 26 | from __future__ import unicode_literals 27 | 28 | try: 29 | from unittest.mock import patch, Mock, MagicMock 30 | except ImportError: 31 | from mock import patch, Mock, MagicMock 32 | try: 33 | from urllib.parse import urlparse 34 | except ImportError: 35 | from urlparse import urlparse 36 | import os 37 | 38 | from django.test import TestCase, RequestFactory, override_settings 39 | from django.contrib.sessions.middleware import SessionMiddleware 40 | from django.contrib.auth.models import User, AnonymousUser, Group 41 | from django.core.urlresolvers import reverse 42 | 43 | from discord_bind.views import callback 44 | from discord_bind.models import DiscordInvite 45 | from discord_bind.conf import settings 46 | 47 | os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1' 48 | 49 | 50 | class TestAccessTokenRequest(TestCase): 51 | """ Test the authorization request view """ 52 | def setUp(self): 53 | self.factory = RequestFactory() 54 | self.user = User.objects.create_user(username="Ralff", 55 | email="ralff@example.com", 56 | password="test") 57 | g = Group.objects.create(name='Discord Users') 58 | g.user_set.add(self.user) 59 | for code in ['code0', 'code1', 'code2', 'code3']: 60 | DiscordInvite.objects.create(code=code, active=False) 61 | 62 | def tearDown(self): 63 | self.user.delete() 64 | 65 | @override_settings(DISCORD_CLIENT_ID='212763200357720576') 66 | def test_get_callback(self): 67 | 68 | @patch('discord_bind.views.OAuth2Session.get') 69 | @patch('discord_bind.views.OAuth2Session.fetch_token') 70 | def get_callback(user, query, mock_fetch, mock_get): 71 | # build request 72 | url = reverse('discord_bind_callback') 73 | if query != '': 74 | url = url + '?' + query 75 | request = self.factory.get(url) 76 | 77 | # add user and session 78 | request.user = user 79 | middleware = SessionMiddleware() 80 | middleware.process_request(request) 81 | request.session['discord_bind_oauth_state'] = 'xyz' 82 | request.session['discord_bind_invite_uri'] = ( 83 | settings.DISCORD_INVITE_URI) 84 | request.session['discord_bind_return_uri'] = ( 85 | settings.DISCORD_RETURN_URI) 86 | request.session.save() 87 | 88 | # build mock harness 89 | mock_fetch.return_value = { 90 | "access_token": "tvYhMddlVlxNGPtsAN34w9P6pivuLG", 91 | "token_type": "Bearer", 92 | "expires_in": 604800, 93 | "refresh_token": "pUbZsF6BBZ8cD1CZqwxW25hCPUkQF5", 94 | "scope": "email" 95 | } 96 | user_data = { 97 | "avatar": "000d1294c515f3331cf32b31bc132f92", 98 | "discriminator": "4021", 99 | "email": "stigg@example.com", 100 | "id": "132196734423007232", 101 | "mfa_enabled": True, 102 | "username": "stigg", 103 | "verified": True 104 | } 105 | mock_response = Mock() 106 | mock_response.json.return_value = user_data 107 | mock_get.return_value = mock_response 108 | 109 | # fire 110 | return callback(request) 111 | 112 | # Anonymous users should bounce to the login page 113 | response = get_callback(AnonymousUser(), '') 114 | self.assertEqual(response.status_code, 302) 115 | self.assertTrue('login' in response['location']) 116 | 117 | # Discord user binding 118 | response = get_callback(self.user, 119 | 'code=SplxlOBeZQQYbYS6WxSbIA&state=xyz') 120 | self.assertEqual(response.status_code, 302) 121 | self.assertEqual(response['location'], settings.DISCORD_RETURN_URI) 122 | 123 | # Missing code 124 | response = get_callback(self.user, 125 | 'state=xyz') 126 | self.assertEqual(response.status_code, 302) 127 | self.assertEqual(response['location'], settings.DISCORD_RETURN_URI) 128 | 129 | # CSRF 130 | response = get_callback(self.user, 131 | 'code=SplxlOBeZQQYbYS6WxSbIA&state=abc') 132 | self.assertEqual(response.status_code, 403) 133 | response = get_callback(self.user, 134 | 'error=server_error&state=abc') 135 | self.assertEqual(response.status_code, 403) 136 | 137 | # Missing state 138 | response = get_callback(self.user, 139 | 'code=SplxlOBeZQQYbYS6WxSbIA') 140 | self.assertEqual(response.status_code, 403) 141 | response = get_callback(self.user, 142 | 'error=server_error') 143 | self.assertEqual(response.status_code, 403) 144 | 145 | # Valid error responses 146 | for error in ['invalid_request', 'unauthorized_client', 147 | 'access_denied', 'unsupported_response_type', 148 | 'invalid_scope', 'server_error', 149 | 'temporarily_unavailable']: 150 | response = get_callback(self.user, 151 | 'error=%s&state=xyz' % error) 152 | self.assertEqual(response.status_code, 302) 153 | self.assertEqual(response['location'], settings.DISCORD_RETURN_URI) 154 | -------------------------------------------------------------------------------- /discord_bind/tests/test_index_view.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016, Mark Rogaski 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | """ 26 | from __future__ import unicode_literals 27 | 28 | try: 29 | from unittest.mock import patch, MagicMock 30 | except ImportError: 31 | from mock import patch, MagicMock 32 | try: 33 | from urllib.parse import urlparse 34 | except ImportError: 35 | from urlparse import urlparse 36 | import os 37 | 38 | from django.test import TestCase, RequestFactory, override_settings 39 | from django.contrib.sessions.middleware import SessionMiddleware 40 | from django.contrib.auth.models import User, AnonymousUser 41 | from django.core.urlresolvers import reverse 42 | 43 | from discord_bind.views import index 44 | 45 | 46 | class TestAuthorizationRequest(TestCase): 47 | """ Test the authorization request view """ 48 | def setUp(self): 49 | self.factory = RequestFactory() 50 | self.user = User.objects.create_user(username="Hoots", 51 | email="hoots@example.com", 52 | password="test") 53 | 54 | def tearDown(self): 55 | self.user.delete() 56 | 57 | @override_settings(DISCORD_CLIENT_ID='212763200357720576') 58 | def test_get_index(self): 59 | def user_request(user, query=''): 60 | url = reverse('discord_bind_index') 61 | if query != '': 62 | url = url + '?' + query 63 | request = self.factory.get(url) 64 | request.user = user 65 | middleware = SessionMiddleware() 66 | middleware.process_request(request) 67 | request.session.save() 68 | return request 69 | 70 | # Anonymous users should bounce to the login page 71 | request = user_request(AnonymousUser()) 72 | response = index(request) 73 | self.assertEqual(response.status_code, 302) 74 | self.assertTrue('login' in response['location']) 75 | 76 | # Loggied in users bounce to the auth request page 77 | request = user_request(self.user) 78 | response = index(request) 79 | self.assertEqual(response.status_code, 302) 80 | url = urlparse(response['location']) 81 | self.assertEqual('https://discordapp.com/api/oauth2/authorize', 82 | url.scheme + '://' + url.netloc + url.path) 83 | self.assertIn('response_type=code', url.query) 84 | self.assertIn('client_id=212763200357720576', url.query) 85 | self.assertIn('redirect_uri=http%3A%2F%2Ftestserver%2Fcb', url.query) 86 | self.assertIn('scope=email+guilds.join', url.query) 87 | self.assertIn('state=%s' % request.session['discord_bind_oauth_state'], 88 | url.query) 89 | 90 | # Limited scope 91 | with self.settings(DISCORD_EMAIL_SCOPE=False): 92 | request = user_request(self.user) 93 | response = index(request) 94 | url = urlparse(response['location']) 95 | self.assertIn('scope=identity+guilds.join', url.query) 96 | 97 | # URI settings 98 | with self.settings(DISCORD_BASE_URI='https://www.example.com/api'): 99 | request = user_request(self.user) 100 | response = index(request) 101 | url = urlparse(response['location']) 102 | self.assertEqual('https://www.example.com/api/oauth2/authorize', 103 | url.scheme + '://' + url.netloc + url.path) 104 | 105 | with self.settings(DISCORD_AUTHZ_PATH='/foo/bar'): 106 | request = user_request(self.user) 107 | response = index(request) 108 | url = urlparse(response['location']) 109 | self.assertEqual('https://discordapp.com/api/foo/bar', 110 | url.scheme + '://' + url.netloc + url.path) 111 | 112 | # redirect uri tests 113 | request = user_request(self.user, 'redirect_uri=https://foo.bar/cb') 114 | response = index(request) 115 | # We don't support this case 116 | self.assertNotIn('redirect_uri=https%3A%2F%2Ffoo.bar%2Fcb', url.query) 117 | 118 | with self.settings(DISCORD_REDIRECT_URI='https://foo.bar/cb'): 119 | request = user_request(self.user) 120 | response = index(request) 121 | url = urlparse(response['location']) 122 | self.assertIn('redirect_uri=https%3A%2F%2Ffoo.bar%2Fcb', url.query) 123 | 124 | # invite uri tests 125 | request = user_request(self.user) 126 | response = index(request) 127 | self.assertEqual(request.session['discord_bind_invite_uri'], 128 | 'https://discordapp.com/channels/@me') 129 | 130 | request = user_request(self.user, 'invite_uri=/foo') 131 | response = index(request) 132 | self.assertEqual(request.session['discord_bind_invite_uri'], '/foo') 133 | 134 | with self.settings(DISCORD_INVITE_URI='https://www.example.com/'): 135 | request = user_request(self.user) 136 | response = index(request) 137 | self.assertEqual(request.session['discord_bind_invite_uri'], 138 | 'https://www.example.com/') 139 | 140 | # return uri tests 141 | request = user_request(self.user) 142 | response = index(request) 143 | self.assertEqual(request.session['discord_bind_return_uri'], '/') 144 | 145 | request = user_request(self.user, 'return_uri=/foo') 146 | response = index(request) 147 | self.assertEqual(request.session['discord_bind_return_uri'], '/foo') 148 | 149 | with self.settings(DISCORD_RETURN_URI='https://www.example.com/'): 150 | request = user_request(self.user) 151 | response = index(request) 152 | self.assertEqual(request.session['discord_bind_return_uri'], 153 | 'https://www.example.com/') 154 | -------------------------------------------------------------------------------- /discord_bind/tests/test_models.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016, Mark Rogaski 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | """ 26 | from __future__ import unicode_literals 27 | 28 | try: 29 | from unittest.mock import patch, Mock 30 | except ImportError: 31 | from mock import patch, Mock 32 | 33 | from django.test import TestCase 34 | from django.contrib.auth.models import User, Group 35 | from django.db import IntegrityError, transaction 36 | 37 | from discord_bind.models import DiscordUser, DiscordInvite 38 | 39 | 40 | class TestDiscordUser(TestCase): 41 | """ Test the Discord user model """ 42 | def setUp(self): 43 | self.user = User.objects.create(username='henry') 44 | 45 | def tearDown(self): 46 | self.user.delete() 47 | 48 | def test_discord_user(self): 49 | u = DiscordUser.objects.create(user=self.user, 50 | uid='172150183260323840', 51 | username='Henry G. Tiger', 52 | discriminator='1738') 53 | self.assertEqual(str(u), '%s.%s' % (u.username, u.discriminator)) 54 | 55 | 56 | class TestDiscordInvite(TestCase): 57 | """ Test the Discord invite model """ 58 | def setUp(self): 59 | self.red = Group.objects.create(name='Red Team') 60 | self.blue = Group.objects.create(name='Blue Team') 61 | self.invite_json = {"code": "aY1XeQGDKL8iCRvJ", 62 | "guild": { 63 | "splash": None, 64 | "id": "132196927679889408", 65 | "icon": "b472e4221e5b24f4de1583be747ca1bd", 66 | "name": "Alea Iacta Est"}, 67 | "channel": {"type": "text", 68 | "id": "132196927679889408", 69 | "name": "general"}} 70 | 71 | def tearDown(self): 72 | self.red.delete() 73 | self.blue.delete() 74 | pass 75 | 76 | def test_discord_invite(self): 77 | DiscordInvite.objects.create(code='EzqS3tytSpUCa7Lr', 78 | active=True) 79 | 80 | inv = DiscordInvite.objects.create(code='8UQcx0Ychpq1Kmqs', 81 | active=True) 82 | inv.groups.add(self.blue) 83 | 84 | inv = DiscordInvite.objects.create(code='9dbFpT89bmXzejG9', 85 | active=False) 86 | inv.groups.add(self.red) 87 | 88 | inv = DiscordInvite.objects.create(code='pMqXoCQT41S7e4LK') 89 | inv.groups.add(self.red) 90 | inv.groups.add(self.blue) 91 | 92 | with self.assertRaises(IntegrityError): 93 | with transaction.atomic(): 94 | DiscordInvite.objects.create(code='EzqS3tytSpUCa7Lr', 95 | active=True) 96 | 97 | self.assertEqual(DiscordInvite.objects.filter(groups=self.blue 98 | ).count(), 2) 99 | self.assertEqual(DiscordInvite.objects.filter(groups=self.red 100 | ).count(), 2) 101 | self.assertEqual(DiscordInvite.objects.filter(groups__isnull=True 102 | ).count(), 1) 103 | 104 | self.assertEqual(DiscordInvite.objects.filter(active=True 105 | ).count(), 2) 106 | self.assertEqual(DiscordInvite.objects.filter(active=False 107 | ).count(), 2) 108 | 109 | @patch('discord_bind.models.requests.get') 110 | def test_invite_update(self, mock_get): 111 | mock_get.return_value = mock_response = Mock() 112 | mock_response.status_code = 200 113 | mock_response.json.return_value = self.invite_json 114 | obj = DiscordInvite.objects.create(code='aY1XeQGDKL8iCRvJ') 115 | obj.update_context() 116 | mock_get.assert_called_once_with('https://discordapp.com/api' 117 | '/invites/aY1XeQGDKL8iCRvJ') 118 | self.assertEqual(obj.guild_id, "132196927679889408") 119 | self.assertEqual(obj.guild_name, "Alea Iacta Est") 120 | self.assertEqual(obj.guild_icon, "b472e4221e5b24f4de1583be747ca1bd") 121 | self.assertEqual(obj.channel_id, "132196927679889408") 122 | self.assertEqual(obj.channel_name, "general") 123 | self.assertEqual(obj.channel_type, "text") 124 | -------------------------------------------------------------------------------- /discord_bind/urls.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016, Mark Rogaski 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | """ 26 | from __future__ import unicode_literals 27 | 28 | from django.urls import re_path 29 | 30 | from . import views 31 | 32 | urlpatterns = [ 33 | re_path(r"^$", views.index, name="discord_bind_index"), 34 | re_path(r"^cb$", views.callback, name="discord_bind_callback"), 35 | ] 36 | -------------------------------------------------------------------------------- /discord_bind/views.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016, Mark Rogaski 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | """ 26 | from __future__ import unicode_literals 27 | 28 | from datetime import datetime 29 | 30 | from django.http import HttpResponseRedirect, HttpResponseForbidden 31 | try: 32 | from django.urls import reverse 33 | except ImportError: 34 | from django.core.urlresolvers import reverse 35 | from django.contrib.auth.decorators import login_required 36 | from django.utils.timezone import make_aware 37 | from django.db.models import Q 38 | from django.contrib import messages 39 | 40 | import requests 41 | from requests_oauthlib import OAuth2Session 42 | 43 | from discord_bind.models import DiscordUser, DiscordInvite 44 | from discord_bind.conf import settings 45 | 46 | import logging 47 | logger = logging.getLogger(__name__) 48 | 49 | 50 | def oauth_session(request, state=None, token=None): 51 | """ Constructs the OAuth2 session object. """ 52 | if settings.DISCORD_REDIRECT_URI is not None: 53 | redirect_uri = settings.DISCORD_REDIRECT_URI 54 | else: 55 | redirect_uri = request.build_absolute_uri( 56 | reverse('discord_bind_callback')) 57 | return OAuth2Session(settings.DISCORD_CLIENT_ID() if callable(settings.DISCORD_CLIENT_ID) else settings.DISCORD_CLIENT_ID, 58 | redirect_uri=redirect_uri, 59 | scope=['identify'], 60 | token=token, 61 | state=state) 62 | 63 | 64 | @login_required 65 | def index(request): 66 | # Record the final redirect alternatives 67 | if 'invite_uri' in request.GET: 68 | request.session['discord_bind_invite_uri'] = request.GET['invite_uri'] 69 | else: 70 | request.session['discord_bind_invite_uri'] = ( 71 | settings.DISCORD_INVITE_URI) 72 | 73 | if 'return_uri' in request.GET: 74 | request.session['discord_bind_return_uri'] = request.GET['return_uri'] 75 | else: 76 | request.session['discord_bind_return_uri'] = ( 77 | settings.DISCORD_RETURN_URI) 78 | 79 | # Compute the authorization URI 80 | oauth = oauth_session(request) 81 | url, state = oauth.authorization_url(settings.DISCORD_BASE_URI + 82 | settings.DISCORD_AUTHZ_PATH) 83 | request.session['discord_bind_oauth_state'] = state 84 | return HttpResponseRedirect(url) 85 | 86 | 87 | @login_required 88 | def callback(request): 89 | def decompose_data(user, token): 90 | """ Extract the important details """ 91 | data = { 92 | 'uid': user['id'], 93 | 'username': user['username'], 94 | 'discriminator': user['discriminator'], 95 | 'email': user.get('email', ''), 96 | 'avatar': user.get('avatar', ''), 97 | 'access_token': token['access_token'], 98 | 'refresh_token': token.get('refresh_token', ''), 99 | 'scope': ' '.join(token.get('scope', '')), 100 | } 101 | for k in data: 102 | if data[k] is None: 103 | data[k] = '' 104 | try: 105 | expiry = datetime.utcfromtimestamp(float(token['expires_at'])) 106 | if settings.USE_TZ: 107 | expiry = make_aware(expiry) 108 | data['expiry'] = expiry 109 | except KeyError: 110 | pass 111 | return data 112 | 113 | def bind_user(request, data): 114 | """ Create or update a DiscordUser instance """ 115 | uid = data.pop('uid') 116 | count = DiscordUser.objects.filter(uid=uid).update(user=request.user, 117 | **data) 118 | if count == 0: 119 | DiscordUser.objects.create(uid=uid, 120 | user=request.user, 121 | **data) 122 | 123 | response = request.build_absolute_uri() 124 | state = request.session['discord_bind_oauth_state'] 125 | if 'state' not in request.GET or request.GET['state'] != state: 126 | return HttpResponseForbidden() 127 | oauth = oauth_session(request, state=state) 128 | token = oauth.fetch_token(settings.DISCORD_BASE_URI + 129 | settings.DISCORD_TOKEN_PATH, 130 | client_secret=settings.DISCORD_CLIENT_SECRET() if callable(settings.DISCORD_CLIENT_SECRET) else settings.DISCORD_CLIENT_SECRET, 131 | authorization_response=response) 132 | 133 | # Get Discord user data 134 | user = oauth.get(settings.DISCORD_BASE_URI + '/users/@me').json() 135 | data = decompose_data(user, token) 136 | bind_user(request, data) 137 | 138 | # Accept Discord invites 139 | groups = request.user.groups.all() 140 | invites = DiscordInvite.objects.filter(active=True).filter( 141 | Q(groups__in=groups) | Q(groups=None)) 142 | count = 0 143 | for invite in invites: 144 | r = oauth.post(settings.DISCORD_BASE_URI + '/invites/' + invite.code) 145 | if r.status_code == requests.codes.ok: 146 | count += 1 147 | logger.info(('accepted Discord ' 148 | 'invite for %s/%s') % (invite.guild_name, 149 | invite.channel_name)) 150 | else: 151 | logger.error(('failed to accept Discord ' 152 | 'invite for %s/%s: %d %s') % (invite.guild_name, 153 | invite.channel_name, 154 | r.status_code, 155 | r.reason)) 156 | 157 | # Select return target 158 | if count > 0: 159 | messages.success(request, '%d Discord invite(s) accepted.' % count) 160 | url = request.session['discord_bind_invite_uri'] 161 | else: 162 | url = request.session['discord_bind_return_uri'] 163 | 164 | # Clean up 165 | del request.session['discord_bind_oauth_state'] 166 | del request.session['discord_bind_invite_uri'] 167 | del request.session['discord_bind_return_uri'] 168 | 169 | return HttpResponseRedirect(url) 170 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = _build 9 | 10 | # Internal variables. 11 | PAPEROPT_a4 = -D latex_paper_size=a4 12 | PAPEROPT_letter = -D latex_paper_size=letter 13 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 14 | # the i18n builder cannot share the environment and doctrees with the others 15 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 16 | 17 | .PHONY: help 18 | help: 19 | @echo "Please use \`make ' where is one of" 20 | @echo " html to make standalone HTML files" 21 | @echo " dirhtml to make HTML files named index.html in directories" 22 | @echo " singlehtml to make a single large HTML file" 23 | @echo " pickle to make pickle files" 24 | @echo " json to make JSON files" 25 | @echo " htmlhelp to make HTML files and a HTML help project" 26 | @echo " qthelp to make HTML files and a qthelp project" 27 | @echo " applehelp to make an Apple Help Book" 28 | @echo " devhelp to make HTML files and a Devhelp project" 29 | @echo " epub to make an epub" 30 | @echo " epub3 to make an epub3" 31 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 32 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 33 | @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" 34 | @echo " text to make text files" 35 | @echo " man to make manual pages" 36 | @echo " texinfo to make Texinfo files" 37 | @echo " info to make Texinfo files and run them through makeinfo" 38 | @echo " gettext to make PO message catalogs" 39 | @echo " changes to make an overview of all changed/added/deprecated items" 40 | @echo " xml to make Docutils-native XML files" 41 | @echo " pseudoxml to make pseudoxml-XML files for display purposes" 42 | @echo " linkcheck to check all external links for integrity" 43 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 44 | @echo " coverage to run coverage check of the documentation (if enabled)" 45 | @echo " dummy to check syntax errors of document sources" 46 | 47 | .PHONY: clean 48 | clean: 49 | rm -rf $(BUILDDIR)/* 50 | 51 | .PHONY: html 52 | html: 53 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 54 | @echo 55 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 56 | 57 | .PHONY: dirhtml 58 | dirhtml: 59 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 60 | @echo 61 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 62 | 63 | .PHONY: singlehtml 64 | singlehtml: 65 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 66 | @echo 67 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 68 | 69 | .PHONY: pickle 70 | pickle: 71 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 72 | @echo 73 | @echo "Build finished; now you can process the pickle files." 74 | 75 | .PHONY: json 76 | json: 77 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 78 | @echo 79 | @echo "Build finished; now you can process the JSON files." 80 | 81 | .PHONY: htmlhelp 82 | htmlhelp: 83 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 84 | @echo 85 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 86 | ".hhp project file in $(BUILDDIR)/htmlhelp." 87 | 88 | .PHONY: qthelp 89 | qthelp: 90 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 91 | @echo 92 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 93 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 94 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/django-discord-bind.qhcp" 95 | @echo "To view the help file:" 96 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/django-discord-bind.qhc" 97 | 98 | .PHONY: applehelp 99 | applehelp: 100 | $(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp 101 | @echo 102 | @echo "Build finished. The help book is in $(BUILDDIR)/applehelp." 103 | @echo "N.B. You won't be able to view it unless you put it in" \ 104 | "~/Library/Documentation/Help or install it in your application" \ 105 | "bundle." 106 | 107 | .PHONY: devhelp 108 | devhelp: 109 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 110 | @echo 111 | @echo "Build finished." 112 | @echo "To view the help file:" 113 | @echo "# mkdir -p $$HOME/.local/share/devhelp/django-discord-bind" 114 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/django-discord-bind" 115 | @echo "# devhelp" 116 | 117 | .PHONY: epub 118 | epub: 119 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 120 | @echo 121 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 122 | 123 | .PHONY: epub3 124 | epub3: 125 | $(SPHINXBUILD) -b epub3 $(ALLSPHINXOPTS) $(BUILDDIR)/epub3 126 | @echo 127 | @echo "Build finished. The epub3 file is in $(BUILDDIR)/epub3." 128 | 129 | .PHONY: latex 130 | latex: 131 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 132 | @echo 133 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 134 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 135 | "(use \`make latexpdf' here to do that automatically)." 136 | 137 | .PHONY: latexpdf 138 | latexpdf: 139 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 140 | @echo "Running LaTeX files through pdflatex..." 141 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 142 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 143 | 144 | .PHONY: latexpdfja 145 | latexpdfja: 146 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 147 | @echo "Running LaTeX files through platex and dvipdfmx..." 148 | $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja 149 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 150 | 151 | .PHONY: text 152 | text: 153 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 154 | @echo 155 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 156 | 157 | .PHONY: man 158 | man: 159 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 160 | @echo 161 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 162 | 163 | .PHONY: texinfo 164 | texinfo: 165 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 166 | @echo 167 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 168 | @echo "Run \`make' in that directory to run these through makeinfo" \ 169 | "(use \`make info' here to do that automatically)." 170 | 171 | .PHONY: info 172 | info: 173 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 174 | @echo "Running Texinfo files through makeinfo..." 175 | make -C $(BUILDDIR)/texinfo info 176 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 177 | 178 | .PHONY: gettext 179 | gettext: 180 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 181 | @echo 182 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 183 | 184 | .PHONY: changes 185 | changes: 186 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 187 | @echo 188 | @echo "The overview file is in $(BUILDDIR)/changes." 189 | 190 | .PHONY: linkcheck 191 | linkcheck: 192 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 193 | @echo 194 | @echo "Link check complete; look for any errors in the above output " \ 195 | "or in $(BUILDDIR)/linkcheck/output.txt." 196 | 197 | .PHONY: doctest 198 | doctest: 199 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 200 | @echo "Testing of doctests in the sources finished, look at the " \ 201 | "results in $(BUILDDIR)/doctest/output.txt." 202 | 203 | .PHONY: coverage 204 | coverage: 205 | $(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage 206 | @echo "Testing of coverage in the sources finished, look at the " \ 207 | "results in $(BUILDDIR)/coverage/python.txt." 208 | 209 | .PHONY: xml 210 | xml: 211 | $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml 212 | @echo 213 | @echo "Build finished. The XML files are in $(BUILDDIR)/xml." 214 | 215 | .PHONY: pseudoxml 216 | pseudoxml: 217 | $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml 218 | @echo 219 | @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." 220 | 221 | .PHONY: dummy 222 | dummy: 223 | $(SPHINXBUILD) -b dummy $(ALLSPHINXOPTS) $(BUILDDIR)/dummy 224 | @echo 225 | @echo "Build finished. Dummy builder generates no files." 226 | -------------------------------------------------------------------------------- /docs/changelog.rst: -------------------------------------------------------------------------------- 1 | Change Log 2 | ========== 3 | 4 | This project uses `Semantic Versioning `__. 5 | 6 | 0.2.0 -- 2016-08-19 7 | ------------------- 8 | 9 | Added 10 | ~~~~~ 11 | 12 | - Added the DISCORD_REDIRECT_URI setting. 13 | - Added state validation to prevent CSRF attacks. 14 | 15 | Updated 16 | ~~~~~~~ 17 | 18 | - Added more documentation. 19 | 20 | 0.1.3 -- 2016-08-14 21 | ------------------- 22 | 23 | Fixed 24 | ~~~~~ 25 | 26 | - Corrected all PEP8 issues. 27 | 28 | Updated 29 | ~~~~~~~ 30 | 31 | - Documented all settings options. 32 | 33 | 0.1.2 -- 2016-08-13 34 | ------------------- 35 | 36 | Fixed 37 | ~~~~~ 38 | 39 | - Cleaned up package configuration. 40 | 41 | Changed 42 | ~~~~~~~ 43 | 44 | - Disabled TravisCI e-mail notifications. 45 | 46 | 0.1.1 -- 2016-08-13 47 | ------------------- 48 | 49 | Fixed 50 | ~~~~~ 51 | 52 | - Removed migration dependencies. 53 | - Cleaned up TravisCI configuration. 54 | 55 | 0.1.0 -- 2016-08-13 56 | ------------------- 57 | 58 | Initial release. 59 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # 4 | # django-discord-bind documentation build configuration file, created by 5 | # sphinx-quickstart on Fri Aug 19 01:33:24 2016. 6 | # 7 | # This file is execfile()d with the current directory set to its 8 | # containing dir. 9 | # 10 | # Note that not all possible configuration values are present in this 11 | # autogenerated file. 12 | # 13 | # All configuration values have a default; values that are commented out 14 | # serve to show the default. 15 | 16 | # If extensions (or modules to document with autodoc) are in another directory, 17 | # add these directories to sys.path here. If the directory is relative to the 18 | # documentation root, use os.path.abspath to make it absolute, like shown here. 19 | # 20 | # import os 21 | # import sys 22 | # sys.path.insert(0, os.path.abspath('.')) 23 | 24 | # -- General configuration ------------------------------------------------ 25 | 26 | # If your documentation needs a minimal Sphinx version, state it here. 27 | # 28 | # needs_sphinx = '1.0' 29 | 30 | # Add any Sphinx extension module names here, as strings. They can be 31 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 32 | # ones. 33 | extensions = [] 34 | 35 | # Add any paths that contain templates here, relative to this directory. 36 | templates_path = ['_templates'] 37 | 38 | # The suffix(es) of source filenames. 39 | # You can specify multiple suffix as a list of string: 40 | # 41 | # source_suffix = ['.rst', '.md'] 42 | source_suffix = '.rst' 43 | 44 | # The encoding of source files. 45 | # 46 | # source_encoding = 'utf-8-sig' 47 | 48 | # The master toctree document. 49 | master_doc = 'index' 50 | 51 | # General information about the project. 52 | project = 'django-discord-bind' 53 | copyright = '2016, Mark Rogaski' 54 | author = 'Mark Rogaski' 55 | 56 | # The version info for the project you're documenting, acts as replacement for 57 | # |version| and |release|, also used in various other places throughout the 58 | # built documents. 59 | # 60 | try: 61 | from discord_bind import __version__ 62 | # The short X.Y version. 63 | version = '.'.join(__version__.split('.')[:2]) 64 | # The full version, including alpha/beta/rc tags. 65 | release = __version__ 66 | except ImportError: 67 | version = release = 'dev' 68 | 69 | # The language for content autogenerated by Sphinx. Refer to documentation 70 | # for a list of supported languages. 71 | # 72 | # This is also used if you do content translation via gettext catalogs. 73 | # Usually you set "language" from the command line for these cases. 74 | language = None 75 | 76 | # There are two options for replacing |today|: either, you set today to some 77 | # non-false value, then it is used: 78 | # 79 | # today = '' 80 | # 81 | # Else, today_fmt is used as the format for a strftime call. 82 | # 83 | # today_fmt = '%B %d, %Y' 84 | 85 | # List of patterns, relative to source directory, that match files and 86 | # directories to ignore when looking for source files. 87 | # This patterns also effect to html_static_path and html_extra_path 88 | exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] 89 | 90 | # The reST default role (used for this markup: `text`) to use for all 91 | # documents. 92 | # 93 | # default_role = None 94 | 95 | # If true, '()' will be appended to :func: etc. cross-reference text. 96 | # 97 | # add_function_parentheses = True 98 | 99 | # If true, the current module name will be prepended to all description 100 | # unit titles (such as .. function::). 101 | # 102 | # add_module_names = True 103 | 104 | # If true, sectionauthor and moduleauthor directives will be shown in the 105 | # output. They are ignored by default. 106 | # 107 | # show_authors = False 108 | 109 | # The name of the Pygments (syntax highlighting) style to use. 110 | pygments_style = 'sphinx' 111 | 112 | # A list of ignored prefixes for module index sorting. 113 | # modindex_common_prefix = [] 114 | 115 | # If true, keep warnings as "system message" paragraphs in the built documents. 116 | # keep_warnings = False 117 | 118 | # If true, `todo` and `todoList` produce output, else they produce nothing. 119 | todo_include_todos = False 120 | 121 | 122 | # -- Options for HTML output ---------------------------------------------- 123 | 124 | # The theme to use for HTML and HTML Help pages. See the documentation for 125 | # a list of builtin themes. 126 | # 127 | html_theme = 'default' 128 | 129 | # Theme options are theme-specific and customize the look and feel of a theme 130 | # further. For a list of options available for each theme, see the 131 | # documentation. 132 | # 133 | # html_theme_options = {} 134 | 135 | # Add any paths that contain custom themes here, relative to this directory. 136 | # html_theme_path = [] 137 | 138 | # The name for this set of Sphinx documents. 139 | # " v documentation" by default. 140 | # 141 | # html_title = 'django-discord-bind v0.2.1' 142 | 143 | # A shorter title for the navigation bar. Default is the same as html_title. 144 | # 145 | # html_short_title = None 146 | 147 | # The name of an image file (relative to this directory) to place at the top 148 | # of the sidebar. 149 | # 150 | # html_logo = None 151 | 152 | # The name of an image file (relative to this directory) to use as a favicon of 153 | # the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 154 | # pixels large. 155 | # 156 | # html_favicon = None 157 | 158 | # Add any paths that contain custom static files (such as style sheets) here, 159 | # relative to this directory. They are copied after the builtin static files, 160 | # so a file named "default.css" will overwrite the builtin "default.css". 161 | html_static_path = ['_static'] 162 | 163 | # Add any extra paths that contain custom files (such as robots.txt or 164 | # .htaccess) here, relative to this directory. These files are copied 165 | # directly to the root of the documentation. 166 | # 167 | # html_extra_path = [] 168 | 169 | # If not None, a 'Last updated on:' timestamp is inserted at every page 170 | # bottom, using the given strftime format. 171 | # The empty string is equivalent to '%b %d, %Y'. 172 | # 173 | # html_last_updated_fmt = None 174 | 175 | # If true, SmartyPants will be used to convert quotes and dashes to 176 | # typographically correct entities. 177 | # 178 | # html_use_smartypants = True 179 | 180 | # Custom sidebar templates, maps document names to template names. 181 | # 182 | # html_sidebars = {} 183 | 184 | # Additional templates that should be rendered to pages, maps page names to 185 | # template names. 186 | # 187 | # html_additional_pages = {} 188 | 189 | # If false, no module index is generated. 190 | # 191 | # html_domain_indices = True 192 | 193 | # If false, no index is generated. 194 | # 195 | # html_use_index = True 196 | 197 | # If true, the index is split into individual pages for each letter. 198 | # 199 | # html_split_index = False 200 | 201 | # If true, links to the reST sources are added to the pages. 202 | # 203 | # html_show_sourcelink = True 204 | 205 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. 206 | # 207 | # html_show_sphinx = True 208 | 209 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. 210 | # 211 | # html_show_copyright = True 212 | 213 | # If true, an OpenSearch description file will be output, and all pages will 214 | # contain a tag referring to it. The value of this option must be the 215 | # base URL from which the finished HTML is served. 216 | # 217 | # html_use_opensearch = '' 218 | 219 | # This is the file name suffix for HTML files (e.g. ".xhtml"). 220 | # html_file_suffix = None 221 | 222 | # Language to be used for generating the HTML full-text search index. 223 | # Sphinx supports the following languages: 224 | # 'da', 'de', 'en', 'es', 'fi', 'fr', 'h', 'it', 'ja' 225 | # 'nl', 'no', 'pt', 'ro', 'r', 'sv', 'tr', 'zh' 226 | # 227 | # html_search_language = 'en' 228 | 229 | # A dictionary with options for the search language support, empty by default. 230 | # 'ja' uses this config value. 231 | # 'zh' user can custom change `jieba` dictionary path. 232 | # 233 | # html_search_options = {'type': 'default'} 234 | 235 | # The name of a javascript file (relative to the configuration directory) that 236 | # implements a search results scorer. If empty, the default will be used. 237 | # 238 | # html_search_scorer = 'scorer.js' 239 | 240 | # Output file base name for HTML help builder. 241 | htmlhelp_basename = 'django-discord-binddoc' 242 | 243 | # -- Options for LaTeX output --------------------------------------------- 244 | 245 | latex_elements = { 246 | # The paper size ('letterpaper' or 'a4paper'). 247 | # 248 | # 'papersize': 'letterpaper', 249 | 250 | # The font size ('10pt', '11pt' or '12pt'). 251 | # 252 | # 'pointsize': '10pt', 253 | 254 | # Additional stuff for the LaTeX preamble. 255 | # 256 | # 'preamble': '', 257 | 258 | # Latex figure (float) alignment 259 | # 260 | # 'figure_align': 'htbp', 261 | } 262 | 263 | # Grouping the document tree into LaTeX files. List of tuples 264 | # (source start file, target name, title, 265 | # author, documentclass [howto, manual, or own class]). 266 | latex_documents = [ 267 | (master_doc, 'django-discord-bind.tex', 'django-discord-bind Documentation', 268 | 'Mark Rogaski', 'manual'), 269 | ] 270 | 271 | # The name of an image file (relative to this directory) to place at the top of 272 | # the title page. 273 | # 274 | # latex_logo = None 275 | 276 | # For "manual" documents, if this is true, then toplevel headings are parts, 277 | # not chapters. 278 | # 279 | # latex_use_parts = False 280 | 281 | # If true, show page references after internal links. 282 | # 283 | # latex_show_pagerefs = False 284 | 285 | # If true, show URL addresses after external links. 286 | # 287 | # latex_show_urls = False 288 | 289 | # Documents to append as an appendix to all manuals. 290 | # 291 | # latex_appendices = [] 292 | 293 | # It false, will not define \strong, \code, itleref, \crossref ... but only 294 | # \sphinxstrong, ..., \sphinxtitleref, ... To help avoid clash with user added 295 | # packages. 296 | # 297 | # latex_keep_old_macro_names = True 298 | 299 | # If false, no module index is generated. 300 | # 301 | # latex_domain_indices = True 302 | 303 | 304 | # -- Options for manual page output --------------------------------------- 305 | 306 | # One entry per manual page. List of tuples 307 | # (source start file, name, description, authors, manual section). 308 | man_pages = [ 309 | (master_doc, 'django-discord-bind', 'django-discord-bind Documentation', 310 | [author], 1) 311 | ] 312 | 313 | # If true, show URL addresses after external links. 314 | # 315 | # man_show_urls = False 316 | 317 | 318 | # -- Options for Texinfo output ------------------------------------------- 319 | 320 | # Grouping the document tree into Texinfo files. List of tuples 321 | # (source start file, target name, title, author, 322 | # dir menu entry, description, category) 323 | texinfo_documents = [ 324 | (master_doc, 'django-discord-bind', 'django-discord-bind Documentation', 325 | author, 'django-discord-bind', 'One line description of project.', 326 | 'Miscellaneous'), 327 | ] 328 | 329 | # Documents to append as an appendix to all manuals. 330 | # 331 | # texinfo_appendices = [] 332 | 333 | # If false, no module index is generated. 334 | # 335 | # texinfo_domain_indices = True 336 | 337 | # How to display URL addresses: 'footnote', 'no', or 'inline'. 338 | # 339 | # texinfo_show_urls = 'footnote' 340 | 341 | # If true, do not generate a @detailmenu in the "Top" node's menu. 342 | # 343 | # texinfo_no_detailmenu = False 344 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../README.rst 2 | 3 | Contents 4 | ======== 5 | 6 | .. toctree:: 7 | :maxdepth: 1 8 | 9 | installation 10 | settings 11 | changelog 12 | 13 | 14 | Indices and tables 15 | ================== 16 | 17 | * :ref:`genindex` 18 | * :ref:`modindex` 19 | * :ref:`search` 20 | -------------------------------------------------------------------------------- /docs/installation.rst: -------------------------------------------------------------------------------- 1 | .. _installation: 2 | 3 | Installation 4 | ------------ 5 | 6 | Install with pip:: 7 | 8 | pip install django-discord-bind 9 | 10 | Add `discord_bind` to your `INSTALLED_APPS` setting: 11 | 12 | .. code-block:: python 13 | 14 | INSTALLED_APPS = [ 15 | ... 16 | 'discord_bind', 17 | ] 18 | 19 | Include the URL configuration in your project **urls.py**: 20 | 21 | .. code-block:: python 22 | 23 | urlpatterns = [ 24 | ... 25 | url(r'^discord/', include('discord_bind.urls')), 26 | ] 27 | 28 | Run ``python manage.py migrate`` to create the discord_bind models. 29 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Command file for Sphinx documentation 4 | 5 | if "%SPHINXBUILD%" == "" ( 6 | set SPHINXBUILD=sphinx-build 7 | ) 8 | set BUILDDIR=_build 9 | set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . 10 | set I18NSPHINXOPTS=%SPHINXOPTS% . 11 | if NOT "%PAPER%" == "" ( 12 | set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% 13 | set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% 14 | ) 15 | 16 | if "%1" == "" goto help 17 | 18 | if "%1" == "help" ( 19 | :help 20 | echo.Please use `make ^` where ^ is one of 21 | echo. html to make standalone HTML files 22 | echo. dirhtml to make HTML files named index.html in directories 23 | echo. singlehtml to make a single large HTML file 24 | echo. pickle to make pickle files 25 | echo. json to make JSON files 26 | echo. htmlhelp to make HTML files and a HTML help project 27 | echo. qthelp to make HTML files and a qthelp project 28 | echo. devhelp to make HTML files and a Devhelp project 29 | echo. epub to make an epub 30 | echo. epub3 to make an epub3 31 | echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter 32 | echo. text to make text files 33 | echo. man to make manual pages 34 | echo. texinfo to make Texinfo files 35 | echo. gettext to make PO message catalogs 36 | echo. changes to make an overview over all changed/added/deprecated items 37 | echo. xml to make Docutils-native XML files 38 | echo. pseudoxml to make pseudoxml-XML files for display purposes 39 | echo. linkcheck to check all external links for integrity 40 | echo. doctest to run all doctests embedded in the documentation if enabled 41 | echo. coverage to run coverage check of the documentation if enabled 42 | echo. dummy to check syntax errors of document sources 43 | goto end 44 | ) 45 | 46 | if "%1" == "clean" ( 47 | for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i 48 | del /q /s %BUILDDIR%\* 49 | goto end 50 | ) 51 | 52 | 53 | REM Check if sphinx-build is available and fallback to Python version if any 54 | %SPHINXBUILD% 1>NUL 2>NUL 55 | if errorlevel 9009 goto sphinx_python 56 | goto sphinx_ok 57 | 58 | :sphinx_python 59 | 60 | set SPHINXBUILD=python -m sphinx.__init__ 61 | %SPHINXBUILD% 2> nul 62 | if errorlevel 9009 ( 63 | echo. 64 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 65 | echo.installed, then set the SPHINXBUILD environment variable to point 66 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 67 | echo.may add the Sphinx directory to PATH. 68 | echo. 69 | echo.If you don't have Sphinx installed, grab it from 70 | echo.http://sphinx-doc.org/ 71 | exit /b 1 72 | ) 73 | 74 | :sphinx_ok 75 | 76 | 77 | if "%1" == "html" ( 78 | %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html 79 | if errorlevel 1 exit /b 1 80 | echo. 81 | echo.Build finished. The HTML pages are in %BUILDDIR%/html. 82 | goto end 83 | ) 84 | 85 | if "%1" == "dirhtml" ( 86 | %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml 87 | if errorlevel 1 exit /b 1 88 | echo. 89 | echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. 90 | goto end 91 | ) 92 | 93 | if "%1" == "singlehtml" ( 94 | %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml 95 | if errorlevel 1 exit /b 1 96 | echo. 97 | echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. 98 | goto end 99 | ) 100 | 101 | if "%1" == "pickle" ( 102 | %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle 103 | if errorlevel 1 exit /b 1 104 | echo. 105 | echo.Build finished; now you can process the pickle files. 106 | goto end 107 | ) 108 | 109 | if "%1" == "json" ( 110 | %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json 111 | if errorlevel 1 exit /b 1 112 | echo. 113 | echo.Build finished; now you can process the JSON files. 114 | goto end 115 | ) 116 | 117 | if "%1" == "htmlhelp" ( 118 | %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp 119 | if errorlevel 1 exit /b 1 120 | echo. 121 | echo.Build finished; now you can run HTML Help Workshop with the ^ 122 | .hhp project file in %BUILDDIR%/htmlhelp. 123 | goto end 124 | ) 125 | 126 | if "%1" == "qthelp" ( 127 | %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp 128 | if errorlevel 1 exit /b 1 129 | echo. 130 | echo.Build finished; now you can run "qcollectiongenerator" with the ^ 131 | .qhcp project file in %BUILDDIR%/qthelp, like this: 132 | echo.^> qcollectiongenerator %BUILDDIR%\qthelp\django-discord-bind.qhcp 133 | echo.To view the help file: 134 | echo.^> assistant -collectionFile %BUILDDIR%\qthelp\django-discord-bind.ghc 135 | goto end 136 | ) 137 | 138 | if "%1" == "devhelp" ( 139 | %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp 140 | if errorlevel 1 exit /b 1 141 | echo. 142 | echo.Build finished. 143 | goto end 144 | ) 145 | 146 | if "%1" == "epub" ( 147 | %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub 148 | if errorlevel 1 exit /b 1 149 | echo. 150 | echo.Build finished. The epub file is in %BUILDDIR%/epub. 151 | goto end 152 | ) 153 | 154 | if "%1" == "epub3" ( 155 | %SPHINXBUILD% -b epub3 %ALLSPHINXOPTS% %BUILDDIR%/epub3 156 | if errorlevel 1 exit /b 1 157 | echo. 158 | echo.Build finished. The epub3 file is in %BUILDDIR%/epub3. 159 | goto end 160 | ) 161 | 162 | if "%1" == "latex" ( 163 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 164 | if errorlevel 1 exit /b 1 165 | echo. 166 | echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. 167 | goto end 168 | ) 169 | 170 | if "%1" == "latexpdf" ( 171 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 172 | cd %BUILDDIR%/latex 173 | make all-pdf 174 | cd %~dp0 175 | echo. 176 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 177 | goto end 178 | ) 179 | 180 | if "%1" == "latexpdfja" ( 181 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 182 | cd %BUILDDIR%/latex 183 | make all-pdf-ja 184 | cd %~dp0 185 | echo. 186 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 187 | goto end 188 | ) 189 | 190 | if "%1" == "text" ( 191 | %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text 192 | if errorlevel 1 exit /b 1 193 | echo. 194 | echo.Build finished. The text files are in %BUILDDIR%/text. 195 | goto end 196 | ) 197 | 198 | if "%1" == "man" ( 199 | %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man 200 | if errorlevel 1 exit /b 1 201 | echo. 202 | echo.Build finished. The manual pages are in %BUILDDIR%/man. 203 | goto end 204 | ) 205 | 206 | if "%1" == "texinfo" ( 207 | %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo 208 | if errorlevel 1 exit /b 1 209 | echo. 210 | echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. 211 | goto end 212 | ) 213 | 214 | if "%1" == "gettext" ( 215 | %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale 216 | if errorlevel 1 exit /b 1 217 | echo. 218 | echo.Build finished. The message catalogs are in %BUILDDIR%/locale. 219 | goto end 220 | ) 221 | 222 | if "%1" == "changes" ( 223 | %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes 224 | if errorlevel 1 exit /b 1 225 | echo. 226 | echo.The overview file is in %BUILDDIR%/changes. 227 | goto end 228 | ) 229 | 230 | if "%1" == "linkcheck" ( 231 | %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck 232 | if errorlevel 1 exit /b 1 233 | echo. 234 | echo.Link check complete; look for any errors in the above output ^ 235 | or in %BUILDDIR%/linkcheck/output.txt. 236 | goto end 237 | ) 238 | 239 | if "%1" == "doctest" ( 240 | %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest 241 | if errorlevel 1 exit /b 1 242 | echo. 243 | echo.Testing of doctests in the sources finished, look at the ^ 244 | results in %BUILDDIR%/doctest/output.txt. 245 | goto end 246 | ) 247 | 248 | if "%1" == "coverage" ( 249 | %SPHINXBUILD% -b coverage %ALLSPHINXOPTS% %BUILDDIR%/coverage 250 | if errorlevel 1 exit /b 1 251 | echo. 252 | echo.Testing of coverage in the sources finished, look at the ^ 253 | results in %BUILDDIR%/coverage/python.txt. 254 | goto end 255 | ) 256 | 257 | if "%1" == "xml" ( 258 | %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml 259 | if errorlevel 1 exit /b 1 260 | echo. 261 | echo.Build finished. The XML files are in %BUILDDIR%/xml. 262 | goto end 263 | ) 264 | 265 | if "%1" == "pseudoxml" ( 266 | %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml 267 | if errorlevel 1 exit /b 1 268 | echo. 269 | echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. 270 | goto end 271 | ) 272 | 273 | if "%1" == "dummy" ( 274 | %SPHINXBUILD% -b dummy %ALLSPHINXOPTS% %BUILDDIR%/dummy 275 | if errorlevel 1 exit /b 1 276 | echo. 277 | echo.Build finished. Dummy builder generates no files. 278 | goto end 279 | ) 280 | 281 | :end 282 | -------------------------------------------------------------------------------- /docs/settings.rst: -------------------------------------------------------------------------------- 1 | .. _settings: 2 | 3 | Settings 4 | ======== 5 | 6 | .. currentmodule:: django.conf.settings 7 | 8 | Django Discord Bind has a number of settings that control its behavior. 9 | 10 | 11 | Required Settings 12 | ----------------- 13 | 14 | DISCORD_CLIENT_ID 15 | ~~~~~~~~~~~~~~~~~ 16 | 17 | The client identifier issued by the Discord authorization server. This 18 | identifier is used in the authorization request of the OAuth 2.0 19 | Authorization Code Grant workflow. 20 | 21 | DISCORD_CLIENT_SECRET 22 | ~~~~~~~~~~~~~~~~~~~~~ 23 | 24 | A shared secret issued by the Discord authorization server. This 25 | identifier is used in the access token request of the OAuth 2.0 26 | Authorization Code Grant workflow. 27 | 28 | Optional Settings 29 | ----------------- 30 | 31 | DISCORD_AUTHZ_PATH 32 | ~~~~~~~~~~~~~~~~~~ 33 | 34 | Default: ``/oauth2/authorize`` 35 | 36 | The path of the authorization request service endpoint, which will be 37 | appended to the DISCORD_BASE_URI setting. 38 | 39 | DISCORD_BASE_URI 40 | ~~~~~~~~~~~~~~~~ 41 | 42 | Default: ``https://discordapp.com/api`` 43 | 44 | The base URI for the Discord API. 45 | 46 | DISCORD_INVITE_URI 47 | ~~~~~~~~~~~~~~~~~~ 48 | 49 | Default: ``https://discordapp.com/channels/@me`` 50 | 51 | The URI that the user will be redirected to after one or more successful 52 | auto-invites. 53 | 54 | DISCORD_REDIRECT_URI 55 | ~~~~~~~~~~~~~~~~~~ 56 | 57 | Default: ``reverse('discord_bind_callback')`` 58 | 59 | The URI that will be passed to the Discord authorization endpoint as the 60 | URI for the callback route. Normally this is determined by Django, but 61 | it can be set manually if the application is behind a proxy. 62 | 63 | DISCORD_RETURN_URI 64 | ~~~~~~~~~~~~~~~~~~ 65 | 66 | Default: ``/`` 67 | 68 | The URI that the user will be redirected to if no auto-invites are 69 | attempted or successful. 70 | 71 | DISCORD_TOKEN_PATH 72 | ~~~~~~~~~~~~~~~~~~ 73 | 74 | Default: ``/oauth2/token`` 75 | 76 | The path of the access token request service endpoint, which will be 77 | appended to the DISCORD_BASE_URI setting. 78 | -------------------------------------------------------------------------------- /manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | 4 | The MIT License (MIT) 5 | 6 | Copyright (c) 2016 Mark Rogaski 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | 26 | """ 27 | 28 | import os 29 | import sys 30 | 31 | if __name__ == "__main__": 32 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_settings") 33 | 34 | from django.core.management import execute_from_command_line 35 | 36 | execute_from_command_line(sys.argv) 37 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | Django>=1.9 2 | django-appconf>=1.0.2 3 | django-setuptest>=0.2.1 4 | requests>=2.11.0 5 | requests-oauthlib>=0.6.2 -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [bdist_wheel] 2 | universal=1 3 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016, Mark Rogaski 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | """ 26 | from __future__ import unicode_literals 27 | 28 | import os 29 | from setuptools import find_packages, setup 30 | 31 | with open(os.path.join(os.path.dirname(__file__), 'README.rst')) as readme: 32 | README = readme.read() 33 | 34 | # allow setup.py to be run from any path 35 | os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir))) 36 | 37 | setup( 38 | name='django-discord-bind', 39 | version='0.2.1', 40 | packages=find_packages(), 41 | include_package_data=True, 42 | license='MIT License', # example license 43 | description='A Django app for securely associating a user with a Discord account.', 44 | long_description=README, 45 | url='https://github.com/mrogaski/django-discord-bind', 46 | author='Mark Rogaski', 47 | author_email='mrogaski@pobox.com', 48 | classifiers=[ 49 | 'Development Status :: 3 - Alpha', 50 | 'Environment :: Web Environment', 51 | 'Framework :: Django', 52 | 'Framework :: Django :: 1.9', 53 | 'Framework :: Django :: 1.10', 54 | 'Intended Audience :: Developers', 55 | 'License :: OSI Approved :: MIT License', # example license 56 | 'Operating System :: OS Independent', 57 | 'Programming Language :: Python', 58 | 'Programming Language :: Python :: 2', 59 | 'Programming Language :: Python :: 2.7', 60 | 'Programming Language :: Python :: 3', 61 | 'Programming Language :: Python :: 3.4', 62 | 'Programming Language :: Python :: 3.5', 63 | 'Topic :: Communications :: Chat', 64 | 'Topic :: Internet :: WWW/HTTP', 65 | 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', 66 | ], 67 | install_requires=[ 68 | "Django >= 1.9", 69 | "requests-oauthlib >= 0.6", 70 | "django-appconf >= 1.0", 71 | ], 72 | tests_require=[ 73 | "django-setuptest >= 0.2.1", 74 | "mock" 75 | ], 76 | test_suite='setuptest.setuptest.SetupTestSuite', 77 | ) -------------------------------------------------------------------------------- /test_settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | The MIT License (MIT) 4 | 5 | Copyright (c) 2016, Mark Rogaski 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | """ 26 | 27 | DATABASES = { 28 | 'default': { 29 | 'NAME': 'test.db', 30 | 'ENGINE': 'django.db.backends.sqlite3', 31 | } 32 | } 33 | 34 | INSTALLED_APPS = ( 35 | 'django.contrib.auth', 36 | 'django.contrib.contenttypes', 37 | 'django.contrib.sessions', 38 | 'django.contrib.messages', 39 | 'discord_bind', 40 | ) 41 | 42 | SECRET_KEY = 'vn5v8g+q3q*ll)a3kh10wlj#(tc=738cklg9(z3***kw%qhnv-' 43 | 44 | ROOT_URLCONF = 'discord_bind.urls' 45 | --------------------------------------------------------------------------------