Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
roomlist
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
23
Issues
23
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
SRCT
roomlist
Commits
88565977
Commit
88565977
authored
May 23, 2017
by
Daniel W Bond
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
backend modifications to support individual confirmation pages for each social app
parent
d689e354
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
11 deletions
+63
-11
roomlist/accounts/adapter.py
roomlist/accounts/adapter.py
+62
-10
roomlist/accounts/urls.py
roomlist/accounts/urls.py
+1
-1
No files found.
roomlist/accounts/adapter.py
View file @
88565977
...
...
@@ -4,10 +4,13 @@ from __future__ import absolute_import, print_function
from
django.core.urlresolvers
import
reverse
from
django.contrib
import
messages
from
django.http
import
HttpResponseRedirect
from
django.views.generic
import
FormView
from
django.forms
import
Form
# third party imports
from
allauth.account.adapter
import
get_adapter
as
get_account_adapter
from
allauth.socialaccount.adapter
import
DefaultSocialAccountAdapter
from
allauth.socialaccount.views
import
ConnectionsView
from
allauth.socialaccount.models
import
SocialAccount
from
allauth.socialaccount.signals
import
social_account_removed
from
allauth.exceptions
import
ImmediateHttpResponse
from
braces.views
import
LoginRequiredMixin
...
...
@@ -74,29 +77,78 @@ class AccountAdapter(DefaultSocialAccountAdapter):
raise
ImmediateHttpResponse
(
update_redirect
)
class
RemoveSocialConfirmationView
(
LoginRequiredMixin
,
Connections
View
):
class
RemoveSocialConfirmationView
(
LoginRequiredMixin
,
Form
View
):
"""To customize where users are sent when removing their social media connections.
We have written our own template to handle this feature that is much prettier than
the one provided by allauth."""
# we're not using this, but we're not allowed to have None
form_class
=
Form
template_name
=
"social/remove_social.html"
login_url
=
'login'
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
if
not
request
.
user
.
socialaccount_set
.
all
():
current_url
=
self
.
request
.
get_full_path
()
# [u'', u'accounts', u'student', u'dbond2', u'settings', u'social', u'github', u'remove', u'']
social_application
=
current_url
.
split
(
'/'
)[
6
]
connected_accounts
=
[
account
.
provider
for
account
in
request
.
user
.
socialaccount_set
.
all
()]
# first, check that the user has an account of the type specified in the url
if
not
(
social_application
in
connected_accounts
):
# no social media accounts? back to the settings page with you!
messages
.
add_message
(
self
.
request
,
messages
.
INFO
,
"Select a social media icon to connect an account."
)
return
HttpResponseRedirect
(
reverse
(
'update_student'
,
kwargs
=
{
'slug'
:
self
.
request
.
user
.
username
}))
else
:
return
super
(
RemoveSocialConfirmationView
,
self
).
get
(
request
,
*
args
,
**
kwargs
)
def
form_valid
(
self
,
form
):
# copied directly, except using SUCCESS rather than INFO
get_account_adapter
().
add_message
(
self
.
request
,
messages
.
SUCCESS
,
'socialaccount/messages/'
'account_disconnected.txt'
)
form
.
save
()
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
(
RemoveSocialConfirmationView
,
self
).
get_context_data
(
**
kwargs
)
current_url
=
self
.
request
.
get_full_path
()
social_application
=
current_url
.
split
(
'/'
)[
6
]
for
account
in
self
.
request
.
user
.
socialaccount_set
.
all
():
if
account
.
provider
==
social_application
:
branding
=
account
.
get_provider
().
name
context
[
'branding'
]
=
branding
context
[
'application'
]
=
social_application
return
context
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
current_url
=
self
.
request
.
get_full_path
()
social_application
=
current_url
.
split
(
'/'
)[
6
]
for
account
in
request
.
user
.
socialaccount_set
.
all
():
if
account
.
provider
==
social_application
:
social_account
=
account
branding
=
account
.
get_provider
().
name
# we do not need to use validate_disconnect, because accounts are not
# associated with being able to log in
try
:
social_account
.
delete
()
social_account_removed
.
send
(
sender
=
SocialAccount
,
request
=
request
,
socialaccount
=
social_account
)
message
=
"%s has been successfully disconnected."
%
branding
messages
.
add_message
(
self
.
request
,
messages
.
SUCCESS
,
message
)
# if multiple posts went in, there won't be any 'social_account' or 'branding'
# basically, that means it's already gone and it already works
except
UnboundLocalError
:
get_account_adapter
().
add_message
(
self
.
request
,
messages
.
SUCCESS
,
'socialaccount/messages/'
'account_disconnected.txt'
)
return
HttpResponseRedirect
(
self
.
get_success_url
())
def
get_success_url
(
self
):
...
...
roomlist/accounts/urls.py
View file @
88565977
...
...
@@ -33,7 +33,7 @@ urlpatterns = [
DeleteStudent
.
as_view
(),
name
=
'delete_student'
),
# custom allauth page to disconnect a social media account
url
(
r
'^student/(?P<slug>[\w-]+)/settings/social/remove/$'
,
url
(
r
'^student/(?P<slug>[\w-]+)/settings/social/
(?P<application>[\w-]+)/
remove/$'
,
RemoveSocialConfirmationView
.
as_view
(),
name
=
'remove_social'
),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment