Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-openid-auth
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
django-openid-auth
Commits
8df11b12
Commit
8df11b12
authored
Jan 12, 2011
by
Anthony Lenton
Browse files
Options
Browse Files
Download
Plain Diff
Merged lp:~michael.nelson/django-openid-auth/701489-fire-event-with-sreg-response
parents
ef6a8680
83746113
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
1 deletions
+74
-1
django_openid_auth/signals.py
+34
-0
django_openid_auth/tests/test_views.py
+29
-0
django_openid_auth/views.py
+11
-1
No files found.
django_openid_auth/signals.py
0 → 100644
View file @
8df11b12
# django-openid-auth - OpenID integration for django.contrib.auth
#
# Copyright (C) 2007 Simon Willison
# Copyright (C) 2008-2010 Canonical Ltd.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
import
django.dispatch
oauth_login_complete
=
django
.
dispatch
.
Signal
(
providing_args
=
[
'request'
,
'sreg_response'
])
django_openid_auth/tests/test_views.py
View file @
8df11b12
...
...
@@ -31,6 +31,7 @@ import unittest
from
django.conf
import
settings
from
django.contrib.auth.models
import
User
,
Group
from
django.http
import
HttpRequest
from
django.test
import
TestCase
from
openid.extensions
import
ax
,
sreg
from
openid.fetchers
import
(
...
...
@@ -42,6 +43,7 @@ from openid.store.memstore import MemoryStore
from
django_openid_auth
import
teams
from
django_openid_auth.models
import
UserOpenID
from
django_openid_auth.views
import
sanitise_redirect_url
from
django_openid_auth.signals
import
oauth_login_complete
ET
=
importElementTree
()
...
...
@@ -536,6 +538,33 @@ class RelyingPartyTests(TestCase):
response
=
self
.
complete
(
openid_response
)
return
User
.
objects
.
get
(
username
=
user
.
username
)
def
test_login_complete_signals_login
(
self
):
# An oauth_login_complete signal is emitted including the
# request and sreg_response.
user
=
User
.
objects
.
create_user
(
'someuser'
,
'someone@example.com'
)
useropenid
=
UserOpenID
(
user
=
user
,
claimed_id
=
'http://example.com/identity'
,
display_id
=
'http://example.com/identity'
)
useropenid
.
save
()
response
=
self
.
client
.
post
(
'/openid/login/'
,
{
'openid_identifier'
:
'http://example.com/identity'
})
openid_request
=
self
.
provider
.
parseFormPost
(
response
.
content
)
openid_response
=
openid_request
.
answer
(
True
)
# Use a closure to test whether the signal handler was called.
self
.
signal_handler_called
=
False
def
login_callback
(
sender
,
**
kwargs
):
self
.
assertTrue
(
kwargs
.
has_key
(
'request'
))
self
.
assertTrue
(
kwargs
.
has_key
(
'sreg_response'
))
self
.
assertTrue
(
isinstance
(
kwargs
[
'request'
],
HttpRequest
))
self
.
signal_handler_called
=
True
oauth_login_complete
.
connect
(
login_callback
)
response
=
self
.
complete
(
openid_response
)
self
.
assertTrue
(
self
.
signal_handler_called
)
oauth_login_complete
.
disconnect
(
login_callback
)
class
HelperFunctionsTest
(
TestCase
):
def
test_sanitise_redirect_url
(
self
):
...
...
django_openid_auth/views.py
View file @
8df11b12
...
...
@@ -52,6 +52,8 @@ from openid.extensions import sreg, ax
from
django_openid_auth
import
teams
from
django_openid_auth.forms
import
OpenIDLoginForm
from
django_openid_auth.models
import
UserOpenID
from
django_openid_auth.signals
import
oauth_login_complete
from
django_openid_auth.store
import
DjangoOpenIDStore
...
...
@@ -242,7 +244,15 @@ def login_complete(request, redirect_field_name=REDIRECT_FIELD_NAME,
if
user
is
not
None
:
if
user
.
is_active
:
auth_login
(
request
,
user
)
return
HttpResponseRedirect
(
sanitise_redirect_url
(
redirect_to
))
response
=
HttpResponseRedirect
(
sanitise_redirect_url
(
redirect_to
))
# Notify any listeners that we successfully logged in.
sreg_response
=
sreg
.
SRegResponse
.
fromSuccessResponse
(
openid_response
)
oauth_login_complete
.
send
(
sender
=
UserOpenID
,
request
=
request
,
sreg_response
=
sreg_response
)
return
response
else
:
return
render_failure
(
request
,
'Disabled account'
)
else
:
...
...
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