Skip to content

Commit 4140a14

Browse files
committed
linkedin authentication works
0 parents  commit 4140a14

29 files changed

+589
-0
lines changed

db.sqlite3

164 KB
Binary file not shown.

manage.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env python
2+
import os
3+
import sys
4+
5+
if __name__ == "__main__":
6+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mep_django.settings")
7+
8+
from django.core.management import execute_from_command_line
9+
10+
execute_from_command_line(sys.argv)

mep_django/__init__.py

Whitespace-only changes.

mep_django/__init__.pyc

153 Bytes
Binary file not shown.

mep_django/linkedin/__init__.py

Whitespace-only changes.

mep_django/linkedin/__init__.pyc

162 Bytes
Binary file not shown.

mep_django/linkedin/admin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.

mep_django/linkedin/admin.pyc

219 Bytes
Binary file not shown.

mep_django/linkedin/models.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from django.db import models
2+
3+
# Create your models here.
4+
'''from django.contrib.auth.models import AbstractUser, UserManager
5+
6+
7+
class CustomUser(AbstractUser):
8+
objects = UserManager()
9+
'''

mep_django/linkedin/models.pyc

218 Bytes
Binary file not shown.

mep_django/linkedin/pipeline.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from django.shortcuts import redirect
2+
3+
from social.pipeline.partial import partial
4+
5+
6+
@partial
7+
def require_email(strategy, details, user=None, is_new=False, *args, **kwargs):
8+
if user and user.email:
9+
return
10+
elif is_new and not details.get('email'):
11+
if strategy.session_get('saved_email'):
12+
details['email'] = strategy.session_pop('saved_email')
13+
else:
14+
return redirect('require_email')

mep_django/linkedin/pipeline.pyc

752 Bytes
Binary file not shown.

mep_django/linkedin/tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

mep_django/linkedin/views.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from django.conf import settings
2+
from django.template import RequestContext
3+
from django.shortcuts import redirect, render, render_to_response
4+
from django.contrib.auth.decorators import login_required
5+
from django.contrib.auth import logout as auth_logout
6+
from django.http import HttpResponse
7+
8+
from social.backends.linkedin import LinkedinOAuth
9+
10+
def logout(request):
11+
"""Logs out user"""
12+
auth_logout(request)
13+
return render_to_response('home.html', {}, RequestContext(request))
14+
15+
def home(request):
16+
"""Home view, displays login mechanism"""
17+
if request.user.is_authenticated():
18+
return redirect('done')
19+
return render_to_response('home.html', {
20+
#'plus_id': getattr(settings, 'SOCIAL_AUTH_GOOGLE_PLUS_KEY', None)
21+
'linkedin_id': getattr(settings, 'SOCIAL_AUTH_LINKEDIN_KEY', None)
22+
}, RequestContext(request))
23+
24+
@login_required
25+
def done(request):
26+
"""Login complete view, displays user data"""
27+
scope = ' '.join(settings.SOCIAL_AUTH_LINKEDIN_SCOPE)
28+
return render_to_response('done.html', {
29+
'user': request.user,
30+
'linkedin_id': getattr(settings, 'SOCIAL_AUTH_LINKED_IN_KEY', None),
31+
'linkedin_scope': scope
32+
}, RequestContext(request))
33+
34+
def signup_email(request):
35+
return render_to_response('email_signup.html', {}, RequestContext(request))
36+
37+
38+
def validation_sent(request):
39+
return render_to_response('validation_sent.html', {
40+
'email': request.session.get('email_validation_address')
41+
}, RequestContext(request))
42+
43+
44+
def require_email(request):
45+
if request.method == 'POST':
46+
request.session['saved_email'] = request.POST.get('email')
47+
backend = request.session['partial_pipeline']['backend']
48+
return redirect('social:complete', backend=backend)
49+
return render_to_response('email.html', RequestContext(request))

mep_django/linkedin/views.pyc

2.72 KB
Binary file not shown.

mep_django/settings.old.py

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
"""
2+
Django settings for mep_django_new project.
3+
4+
For more information on this file, see
5+
https://docs.djangoproject.com/en/1.6/topics/settings/
6+
7+
For the full list of settings and their values, see
8+
https://docs.djangoproject.com/en/1.6/ref/settings/
9+
"""
10+
11+
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
12+
import os
13+
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
14+
15+
16+
# Quick-start development settings - unsuitable for production
17+
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/
18+
19+
# SECURITY WARNING: keep the secret key used in production secret!
20+
SECRET_KEY = '8!flv-=lu1s)k*a+6upg1q3ep91z0))-+ho3nih#nme6wqg93b'
21+
22+
# SECURITY WARNING: don't run with debug turned on in production!
23+
DEBUG = True
24+
25+
TEMPLATE_DEBUG = True
26+
27+
ALLOWED_HOSTS = []
28+
29+
30+
# Application definition
31+
32+
INSTALLED_APPS = (
33+
'django.contrib.admin',
34+
'django.contrib.auth',
35+
'django.contrib.contenttypes',
36+
'django.contrib.sessions',
37+
'django.contrib.messages',
38+
'django.contrib.staticfiles',
39+
'social.apps.django_app.default', # added by chad
40+
#'social.apps.django_app.me', # added by chad
41+
#'mongoengine.django.mongo_auth', # added by chad - part of mongodoc http://mongoengine-odm.readthedocs.org/en/latest/django.html
42+
)
43+
44+
#AUTH_USER_MODEL = 'mongo_auth.MongoUser' # added by chad - part of mongodoc http://mongoengine-odm.readthedocs.org/en/latest/django.html
45+
#MONGOENGINE_USER_DOCUMENT = 'mongoengine.django.auth.User' # added by chad - part of mongodoc http://mongoengine-odm.readthedocs.org/en/latest/django.html
46+
47+
MIDDLEWARE_CLASSES = (
48+
'django.contrib.sessions.middleware.SessionMiddleware',
49+
'django.middleware.common.CommonMiddleware',
50+
'django.middleware.csrf.CsrfViewMiddleware',
51+
'django.contrib.auth.middleware.AuthenticationMiddleware',
52+
'django.contrib.messages.middleware.MessageMiddleware',
53+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
54+
)
55+
56+
ROOT_URLCONF = 'mep_django_new.urls'
57+
58+
WSGI_APPLICATION = 'mep_django_new.wsgi.application'
59+
60+
61+
# Database
62+
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases
63+
64+
DATABASES = {
65+
'default': {
66+
'ENGINE': 'django.db.backends.sqlite3',
67+
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
68+
}
69+
#'default': {
70+
# 'ENGINE': 'django.db.backends.mongoengine',
71+
# 'NAME': os.path.join(BASE_DIR, 'db.mongoengine'),
72+
#}
73+
}
74+
75+
# Internationalization
76+
# https://docs.djangoproject.com/en/1.6/topics/i18n/
77+
78+
LANGUAGE_CODE = 'en-us'
79+
80+
TIME_ZONE = 'UTC'
81+
82+
USE_I18N = True
83+
84+
USE_L10N = True
85+
86+
USE_TZ = True
87+
88+
89+
# Static files (CSS, JavaScript, Images)
90+
# https://docs.djangoproject.com/en/1.6/howto/static-files/
91+
92+
STATIC_URL = '/static/'
93+
94+
'''
95+
This is all added by Chad
96+
'''
97+
98+
SOCIAL_AUTH_LINKEDIN_KEY = '75l485e9k29snc'
99+
SOCIAL_AUTH_LINKEDIN_SECRET = 'iw7fONMpJZcY5HOb'
100+
101+
AUTHENTICATION_BACKENDS = (
102+
'social.backends.linkedin.LinkedinOauth',
103+
#'mongoengine.django.auth.MongoEngineBackend',
104+
)
105+
106+
SOCIAL_AUTH_LOGIN_REDIRECT_URL = '/logged-in/'
107+
SOCIAL_AUTH_LOGIN_ERROR_URL = '/login-error/'
108+
SOCIAL_AUTH_LOGIN_URL = '/login-url/'
109+
SOCIAL_AUTH_NEW_USER_REDIRECT_URL = '/new-users-redirect-url/'
110+
SOCIAL_AUTH_NEW_ASSOCIATION_REDIRECT_URL = '/new-association-redirect-url/'
111+
SOCIAL_AUTH_DISCONNECT_REDIRECT_URL = '/account-disconnected-redirect-url/'
112+
SOCIAL_AUTH_INACTIVE_USER_URL = '/inactive-user/'
113+
114+
#SOCIAL_AUTH_STORAGE = 'social.apps.django_app.me.models.DjangoStorage'
115+
116+
TEMPLATE_CONTEXT_PROCESSORS = (
117+
'social.apps.django_app.context_processors.backends',
118+
'social.apps.django_app.context_processors.login_redirect',
119+
)
120+
121+
#SESSION_ENGINE = 'mongoengine.django.sessions'
122+
#SESSION_SERIALIZER = 'mongoengine.django.sessions.BSONSerializer'
123+
124+
#SOCIAL_AUTH_USER_MODEL = 'mongoengine.django.auth.User'

0 commit comments

Comments
 (0)