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
3ebd1b44
Commit
3ebd1b44
authored
Sep 21, 2015
by
Ricardo Kirkner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support custom user model instead of hardcoded contrib User model
this requires to depend on django >= 1.5
parent
d091f448
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
22 additions
and
24 deletions
+22
-24
django_openid_auth/admin.py
+2
-2
django_openid_auth/auth.py
+14
-10
django_openid_auth/models.py
+3
-2
setup.py
+2
-2
tox.ini
+1
-8
No files found.
django_openid_auth/admin.py
View file @
3ebd1b44
...
@@ -97,8 +97,8 @@ def _openid_login(instance, request, error_message='', extra_context=None):
...
@@ -97,8 +97,8 @@ def _openid_login(instance, request, error_message='', extra_context=None):
if
not
request
.
user
.
is_staff
:
if
not
request
.
user
.
is_staff
:
return
views
.
default_render_failure
(
return
views
.
default_render_failure
(
request
,
"
User
%
s does not have admin/staff access."
request
,
"
%
s
%
s does not have admin/staff access."
%
request
.
user
.
username
)
%
(
settings
.
AUTH_USER_MODEL
,
request
.
user
.
username
)
)
# No error message was supplied
# No error message was supplied
assert
error_message
,
"Unknown Error:
%
s"
%
error_message
assert
error_message
,
"Unknown Error:
%
s"
%
error_message
...
...
django_openid_auth/auth.py
View file @
3ebd1b44
...
@@ -35,7 +35,8 @@ __metaclass__ = type
...
@@ -35,7 +35,8 @@ __metaclass__ = type
import
re
import
re
from
django.conf
import
settings
from
django.conf
import
settings
from
django.contrib.auth.models
import
User
,
Group
,
Permission
from
django.contrib.auth
import
get_user_model
from
django.contrib.auth.models
import
Group
,
Permission
from
openid.consumer.consumer
import
SUCCESS
from
openid.consumer.consumer
import
SUCCESS
from
openid.extensions
import
ax
,
sreg
,
pape
from
openid.extensions
import
ax
,
sreg
,
pape
...
@@ -50,6 +51,9 @@ from django_openid_auth.exceptions import (
...
@@ -50,6 +51,9 @@ from django_openid_auth.exceptions import (
)
)
USER_MODEL
=
get_user_model
()
class
OpenIDBackend
:
class
OpenIDBackend
:
"""A django.contrib.auth backend that authenticates the user based on
"""A django.contrib.auth backend that authenticates the user based on
an OpenID response."""
an OpenID response."""
...
@@ -59,8 +63,8 @@ class OpenIDBackend:
...
@@ -59,8 +63,8 @@ class OpenIDBackend:
def
get_user
(
self
,
user_id
):
def
get_user
(
self
,
user_id
):
try
:
try
:
return
U
ser
.
objects
.
get
(
pk
=
user_id
)
return
U
SER_MODEL
.
objects
.
get
(
pk
=
user_id
)
except
U
ser
.
DoesNotExist
:
except
U
SER_MODEL
.
DoesNotExist
:
return
None
return
None
def
authenticate
(
self
,
**
kwargs
):
def
authenticate
(
self
,
**
kwargs
):
...
@@ -203,8 +207,8 @@ class OpenIDBackend:
...
@@ -203,8 +207,8 @@ class OpenIDBackend:
# See if we already have this nickname assigned to a username
# See if we already have this nickname assigned to a username
try
:
try
:
U
ser
.
objects
.
get
(
username__exact
=
nickname
)
U
SER_MODEL
.
objects
.
get
(
username__exact
=
nickname
)
except
U
ser
.
DoesNotExist
:
except
U
SER_MODEL
.
DoesNotExist
:
# No conflict, we can use this nickname
# No conflict, we can use this nickname
return
nickname
return
nickname
...
@@ -236,7 +240,7 @@ class OpenIDBackend:
...
@@ -236,7 +240,7 @@ class OpenIDBackend:
pass
pass
if
getattr
(
settings
,
'OPENID_STRICT_USERNAMES'
,
False
):
if
getattr
(
settings
,
'OPENID_STRICT_USERNAMES'
,
False
):
if
U
ser
.
objects
.
filter
(
username__exact
=
nickname
)
.
count
()
>
0
:
if
U
SER_MODEL
.
objects
.
filter
(
username__exact
=
nickname
)
.
count
()
>
0
:
raise
DuplicateUsernameViolation
(
raise
DuplicateUsernameViolation
(
"The username (
%
s) with which you tried to log in is "
"The username (
%
s) with which you tried to log in is "
"already in use for a different account."
%
nickname
)
"already in use for a different account."
%
nickname
)
...
@@ -245,14 +249,14 @@ class OpenIDBackend:
...
@@ -245,14 +249,14 @@ class OpenIDBackend:
# checking for conflicts. Start with number of existing users who's
# checking for conflicts. Start with number of existing users who's
# username starts with this nickname to avoid having to iterate over
# username starts with this nickname to avoid having to iterate over
# all of the existing ones.
# all of the existing ones.
i
=
U
ser
.
objects
.
filter
(
username__startswith
=
nickname
)
.
count
()
+
1
i
=
U
SER_MODEL
.
objects
.
filter
(
username__startswith
=
nickname
)
.
count
()
+
1
while
True
:
while
True
:
username
=
nickname
username
=
nickname
if
i
>
1
:
if
i
>
1
:
username
+=
str
(
i
)
username
+=
str
(
i
)
try
:
try
:
U
ser
.
objects
.
get
(
username__exact
=
username
)
U
SER_MODEL
.
objects
.
get
(
username__exact
=
username
)
except
U
ser
.
DoesNotExist
:
except
U
SER_MODEL
.
DoesNotExist
:
break
break
i
+=
1
i
+=
1
return
username
return
username
...
@@ -276,7 +280,7 @@ class OpenIDBackend:
...
@@ -276,7 +280,7 @@ class OpenIDBackend:
username
=
self
.
_get_available_username
(
username
=
self
.
_get_available_username
(
nickname
,
openid_response
.
identity_url
)
nickname
,
openid_response
.
identity_url
)
user
=
U
ser
.
objects
.
create_user
(
username
,
email
,
password
=
None
)
user
=
U
SER_MODEL
.
objects
.
create_user
(
username
,
email
,
password
=
None
)
self
.
associate_openid
(
user
,
openid_response
)
self
.
associate_openid
(
user
,
openid_response
)
self
.
update_user_details
(
user
,
details
,
openid_response
)
self
.
update_user_details
(
user
,
details
,
openid_response
)
...
...
django_openid_auth/models.py
View file @
3ebd1b44
...
@@ -29,8 +29,9 @@
...
@@ -29,8 +29,9 @@
from
__future__
import
unicode_literals
from
__future__
import
unicode_literals
from
django.conf
import
settings
from
django.db
import
models
from
django.db
import
models
from
django.contrib.auth.models
import
Permission
,
User
from
django.contrib.auth.models
import
Permission
class
Nonce
(
models
.
Model
):
class
Nonce
(
models
.
Model
):
...
@@ -55,7 +56,7 @@ class Association(models.Model):
...
@@ -55,7 +56,7 @@ class Association(models.Model):
class
UserOpenID
(
models
.
Model
):
class
UserOpenID
(
models
.
Model
):
user
=
models
.
ForeignKey
(
User
)
user
=
models
.
ForeignKey
(
settings
.
AUTH_USER_MODEL
)
claimed_id
=
models
.
TextField
(
max_length
=
2047
,
unique
=
True
)
claimed_id
=
models
.
TextField
(
max_length
=
2047
,
unique
=
True
)
display_id
=
models
.
TextField
(
max_length
=
2047
)
display_id
=
models
.
TextField
(
max_length
=
2047
)
...
...
setup.py
View file @
3ebd1b44
...
@@ -43,7 +43,7 @@ from setuptools import find_packages, setup
...
@@ -43,7 +43,7 @@ from setuptools import find_packages, setup
description
,
long_description
=
__doc__
.
split
(
'
\n\n
'
,
1
)
description
,
long_description
=
__doc__
.
split
(
'
\n\n
'
,
1
)
VERSION
=
'0.
6
'
VERSION
=
'0.
7
'
setup
(
setup
(
name
=
'django-openid-auth'
,
name
=
'django-openid-auth'
,
...
@@ -51,7 +51,7 @@ setup(
...
@@ -51,7 +51,7 @@ setup(
packages
=
find_packages
(),
packages
=
find_packages
(),
install_requires
=
[
install_requires
=
[
'django>=1.
4
'
,
'django>=1.
5
'
,
'python-openid>=2.2.0'
,
'python-openid>=2.2.0'
,
'south'
,
'south'
,
],
],
...
...
tox.ini
View file @
3ebd1b44
[tox]
[tox]
envlist
=
envlist
=
py2.7-django1.
4,
py2.7-django1.
5,
py2.7-django1.6,
py2.7-django1.7,
py2.7-django1.8
py2.7-django1.5,
py2.7-django1.6,
py2.7-django1.7,
py2.7-django1.8
[testenv]
[testenv]
commands
=
python manage.py test django_openid_auth
commands
=
python manage.py test django_openid_auth
...
@@ -8,13 +8,6 @@ deps=
...
@@ -8,13 +8,6 @@ deps=
mock
mock
python-openid
python-openid
[testenv:py2.7-django1.4]
basepython
=
python2.7
deps
=
django
>=
1.4,
<
1.5
{
[testenv]
deps}
south
=
=1.0
[testenv:py2.7-django1.5]
[testenv:py2.7-django1.5]
basepython
=
python2.7
basepython
=
python2.7
deps
=
deps
=
...
...
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