Commit abc8d18b authored by Daniel W Bond's avatar Daniel W Bond
Browse files

completely rewrote account adapter, created page to remove social media connections

parent c2a08a84
......@@ -2,19 +2,60 @@
from __future__ import absolute_import, print_function
from datetime import datetime, timedelta
# core django imports
from django.shortcuts import resolve_url
from django.core.urlresolvers import reverse
from django.views.generic import FormView
# third party imports
from allauth.account.adapter import DefaultAccountAdapter
from allauth.socialaccount.adapter import DefaultSocialAccountAdapter
from allauth.socialaccount.views import ConnectionsView
from allauth.socialaccount.forms import DisconnectForm
from braces.views import LoginRequiredMixin
class AccountAdapter(DefaultSocialAccountAdapter):
class AccountAdapter(DefaultAccountAdapter):
# the request processed by the adapter is one from the successful oauth callback
def get_login_redirect_url(self, request):
threshold = 90 # seconds
#def pre_social_login(self, request, sociallogin):
#print(request.get_full_path(), 'pre_login')
def populate_user(self, request, sociallogin, data):
# we don't actually want to overwrite anything from the
# social media account user
user = sociallogin.user
return user
def get_connect_redirect_url(self, request, socialaccount):
# where the user is sent if the social account is indeed authenticated
assert request.user.is_authenticated()
if ((request.user.last_login - request.user.date_joined).seconds < threshold):
url = '/accounts/student/'
#if 'welcome' in request.get_full_path():
# ergo, we go with more of an approximation (at least for now)
if not request.user.student.completedSocial:
return reverse('welcomeSocial', kwargs={
'slug': request.user.username,
url = '/accounts/student/'
return resolve_url(url)
return reverse('updateStudent', kwargs={
'slug': request.user.username,
class RemoveSocialConfirmationView(LoginRequiredMixin, ConnectionsView):
template_name = "remove_social.html"
login_url = 'login'
def get(self, request, *args, **kwargs):
if not request.user.socialaccount_set.all():
# no social media accounts? back to the settings page with you!
return reverse('updateStudent',
return super(RemoveSocialConfirmationView, self).get(request, *args, **kwargs)
def form_valid(self, form):
return super(RemoveSocialConfirmationView, self).form_valid(form)
def get_success_url(self):
return reverse('updateStudent',
{% extends 'layouts/base.html' %}
{% block title %} SRCT RoomList | Remove Social Accounts {% endblock %}
{% block message_queue %}
{% endblock %}
{% block content %}
<div class="page-header" id="banner">
<div class="row">
<div class="col-md-12 text-center">
<p class="lead text-center">Remove My Social Media Accounts</p>
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">
<h1 class="panel-title text-center"><strong>Connected Social Media Accounts</strong></h1>
<div class="panel-body">
<form class="form-horizontal text-center" method="post" action="">{% csrf_token %}
{% if form.non_field_errors %}
<div id="errorMsg">{{ form.non_field_errors }}</div>
{% endif %}
{% for base_account in form.accounts %}
{% with base_account.get_provider_account as account %}
<p><label for="id_account_{{ }}" style="font-size:20px">
<input id="id_account_{{ }}" type="radio" name="account" value="{{ }}"/>
<span class="socialaccount_provider {{ base_account.provider }} {{ }}">
<i class="fa fa-{{base_account.provider}} fa-lg fa-fw"></i>
<small><em>{{ account }}</em></small>
{% endwith %}
{% endfor %}
<input type="submit" value="Remove" class="btn btn-danger"/>
<input type="cancel" value="Never Mind" class="btn btn-default" onclick="history.back()"/>
<div class="row">
<div class="col-md-8 col-md-offset-2 text-center">
<div class="alert alert-danger" role="alert">
<p><i class="fa fa-exclamation-circle fa-fw fa-lg"></i> While this form will
immediately delete your account from our database, it may still exist for
a time on the related social media account's database. Check that social media
profile's authorized apps page for more information.</p>
{% endblock %}
......@@ -8,6 +8,7 @@ from .views import (DetailStudent, UpdateStudent, DetailStudentSettings,
DetailCurrentStudent, DetailCurrentStudentSettings, ListMajors,
DetailMajor, WelcomeName, WelcomePrivacy, WelcomeMajor,
WelcomeSocial, CreateConfirmation, DeleteConfirmation)
from .adapter import RemoveSocialConfirmationView
urlpatterns = patterns('',
......@@ -38,6 +39,10 @@ urlpatterns = patterns('',
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