Skip to content
This repository has been archived by the owner on Jan 26, 2021. It is now read-only.

feat: Allow user signup using Github #1082

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified requirements.txt
Binary file not shown.
3 changes: 3 additions & 0 deletions vms/authentication/templates/authentication/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,8 @@ <h2 class="header">{% trans "Please sign in" %}</h2>
<button class="primaryAction btn btn-lg btn-primary btn-block" type="submit">
{% trans "Sign In" %}
</button>
<a href="{% url 'social:begin' 'github' %}" id="github-button" class="btn btn-lg btn-primary btn-block">
Sign in with Github
</a>
</form>
{% endblock %}
21 changes: 20 additions & 1 deletion vms/authentication/views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# Django
from django.urls import reverse
from django.shortcuts import redirect
from social_django.models import UserSocialAuth
from django.shortcuts import render

# local Django
from vms import settings

from registration.views import VolunteerSignupView
from registration.forms import UserForm
from volunteer.forms import VolunteerForm

def index(request):
return redirect(reverse('authentication:login_process'))
Expand All @@ -24,3 +28,18 @@ def as_view(request, *args, **kwargs):

return as_view

def github_auth_dialog_step(strategy, backend, request, details, *args, **kwargs):
print(details)
# print(kwargs)
user_form = UserForm(prefix='usr')
volunteer_form = VolunteerForm(prefix="vol")

# print(volunteer_form)

return render(
request, 'registration/signup_volunteer.html', {
'user_form' : user_form,
'username': details["username"],
'volunteer_form': volunteer_form,
})

28 changes: 28 additions & 0 deletions vms/vms/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'social_django',
'administrator',
'event',
'home',
Expand Down Expand Up @@ -58,6 +59,29 @@

WSGI_APPLICATION = 'vms.wsgi.application'

# Social Authentication
AUTHENTICATION_BACKENDS = (
'social_core.backends.github.GithubOAuth2',
'django.contrib.auth.backends.ModelBackend',
)

SOCIAL_AUTH_GITHUB_KEY = config('GITHUB_KEY')
SOCIAL_AUTH_GITHUB_SECRET = config('GITHUB_SECRET')

# User details from social profiles.
SOCIAL_AUTH_PIPELINE = (
'social_core.pipeline.social_auth.social_details',
'social_core.pipeline.social_auth.social_uid',
'social_core.pipeline.social_auth.social_user',
'social_core.pipeline.user.get_username',
'social_core.pipeline.social_auth.associate_by_email',
'social_core.pipeline.user.create_user',
'social_core.pipeline.social_auth.associate_user',
'social_core.pipeline.social_auth.load_extra_data',
'social_core.pipeline.user.user_details',
'authentication.views.github_auth_dialog_step',
)

# Database
# Change these database settings if your database engine, database name,
# username or password changes
Expand All @@ -71,6 +95,8 @@
}
}

# This must be set to true for social auth in postgres.
SOCIAL_AUTH_POSTGRES_JSONFIELD = True

TEMPLATES = [
{
Expand All @@ -83,6 +109,8 @@
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'social_django.context_processors.backends',
'social_django.context_processors.login_redirect',
],
},
},
Expand Down
1 change: 1 addition & 0 deletions vms/vms/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
include('registration.urls', namespace='registration')),
url(r'^shift/', include('shift.urls', namespace='shift')),
url(r'^volunteer/', include('volunteer.urls', namespace='volunteer')),
url(r'^social-auth/', include('social_django.urls', namespace='social')),
)

if settings.DEBUG:
Expand Down