Commit b0b19bd5 authored by Jason D Yeomans's avatar Jason D Yeomans
Browse files

Added social auth for facebook, google, and twitter. /accounts/student/...

Added social auth for facebook, google, and twitter. /accounts/student/ displays current user, added /accounts/settings/ for connecting social accounts
parent c85557ae
......@@ -26,3 +26,22 @@ class StudentForm( forms.ModelForm ):
class Meta:
model = Student
class UserSettingsForm( forms.ModelForm ):
def __init__(self, *args, **kwargs):
self.helper = FormHelper()
self.helper.layout = Layout(
'user',
PrependedText('room', 'Room'),
'class',
AppendedText('major', 'Major'),
)
self.helper.form_method = 'post'
self.helper.add_input(Submit('submit', 'Submit'))
super(StudentForm, self).__init__(*args, **kwargs)
class Meta:
model = Student
{% extends 'layouts/base.html' %} {% block title %} GMU RoomList | {{ student.user.first_name }} {{ student.user.last_name }} {% endblock %} {% block content %} {% load gravatar %}
<div class="page-header" id="banner">
<div class="row">
<div class="col-md-8 col-md-offset-2 text-center">
<img class="img-circle img-responsive center center-block" src="{% gravatar_url student.user.email 175 %}" alt="{{ student.user.first_name }} Gravatar picture">
<h1>{{ student.user.first_name }} {{ student.user.last_name }}, {{ student.user.username }}</h1>
</div>
</div>
</div>
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-body">
<table class="table table-hover text-center">
<tbody>
<tr>
<td><i class="fa fa-facebook fa-lg"></i>
</td>
<td>
{% load socialaccount %} {% providers_media_js %}
<a href="{% provider_login_url 'facebook' method='js_sdk' process='connect' next='/accounts/student/' %}">Facebook Connect</a>
</td>
</tr>
<tr>
<td><i class="fa fa-google fa-lg"></i>
</td>
<td>
<a href="{% provider_login_url 'google' process='connect' next='/accounts/student/' %}">Connect to Google</a>
</td>
</tr>
<tr>
<td><i class="fa fa-twitter fa-lg"></i>
</td>
<td>
<a href="{% provider_login_url 'twitter' process='connect' next='/accounts/student/' %}">Connect to Twitter</a>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
{% endblock %}
from django.conf.urls import patterns, include, url
from accounts.views import DetailStudent, CreateStudent
from accounts.views import DetailStudent, CreateStudent, DetailStudentSettings, DetailCurrentStudent, DetailCurrentStudentSettings
from accounts.models import Student
from django.contrib import admin
......@@ -7,7 +7,7 @@ admin.autodiscover()
urlpatterns = patterns('',
url(r'^', include('allauth.urls')),
url(r'', include('allauth.urls')),
# login and logout
url(r'^login/$', 'django.contrib.auth.views.login', {'template_name': 'login.html'}, name='login'),
......@@ -20,9 +20,30 @@ urlpatterns = patterns('',
template_name='detailStudent.html'),
name='detailStudent'),
url(r'^student/$',
DetailCurrentStudent.as_view(
model=Student,
context_object_name='student',
template_name='detailStudent.html'),
name='detailCurrentStudent'),
url(r'^create/$',
CreateStudent.as_view(
model=Student,
template_name="createStudent.html"),
name='createStudent'),
url(r'^settings/(?P<slug>[\w-]+)/$',
DetailStudentSettings.as_view(
model=Student,
context_object_name='student',
template_name="studentSettings.html"),
name='studentSettings'),
url(r'^settings/$',
DetailCurrentStudentSettings.as_view(
model=Student,
context_object_name='student',
template_name="studentSettings.html"),
name='currentStudentSettings'),
)
from django.shortcuts import render
from django.shortcuts import render, get_object_or_404
from django.views.generic import DetailView, ListView, CreateView, UpdateView, DeleteView
......@@ -18,3 +18,23 @@ class CreateStudent(LoginRequiredMixin, CreateView):
class DetailStudent(LoginRequiredMixin, DetailView):
model = Student
login_url = '/'
# changeable student settings
class DetailStudentSettings(LoginRequiredMixin, DetailView):
model = Student
login_url = '/'
class DetailCurrentStudent(LoginRequiredMixin, DetailView):
#model = Student
def get_object(self):
return get_object_or_404(Student, pk=self.request.session['_auth_user_id'])
class DetailCurrentStudentSettings(LoginRequiredMixin, DetailView):
#model = Student
def get_object(self):
return get_object_or_404(Student, pk=self.request.session['_auth_user_id'])
......@@ -123,6 +123,8 @@ USE_L10N = True
USE_TZ = True
SITE_ID = 2
AUTHENTICATION_BACKENDS = (
# Needed to login by username in Django admin, regardless of `allauth`
"django.contrib.auth.backends.ModelBackend",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment