Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
664beaeb
authored
Feb 02, 2013
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
school: refactor eduid login
parent
16814bd6
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
38 deletions
+6
-38
school/views.py
+6
-38
No files found.
school/views.py
View file @
664beaeb
...
@@ -9,7 +9,6 @@ from django.core.mail import mail_managers, send_mail
...
@@ -9,7 +9,6 @@ from django.core.mail import mail_managers, send_mail
from
django.db
import
transaction
from
django.db
import
transaction
from
django.forms
import
ModelForm
,
Textarea
from
django.forms
import
ModelForm
,
Textarea
from
django.http
import
Http404
from
django.http
import
Http404
#from django_shibboleth.forms import BaseRegisterForm
from
django.shortcuts
import
render
,
render_to_response
,
get_object_or_404
,
redirect
from
django.shortcuts
import
render
,
render_to_response
,
get_object_or_404
,
redirect
from
django.template
import
RequestContext
from
django.template
import
RequestContext
from
django.template.loader
import
render_to_string
from
django.template.loader
import
render_to_string
...
@@ -25,53 +24,21 @@ import logging
...
@@ -25,53 +24,21 @@ import logging
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
SHIB_ATTRIBUTE_MAP
=
{
"HTTP_SHIB_IDENTITY_PROVIDER"
:
(
True
,
"idp"
),
"email"
:
(
True
,
"email"
),
"sn"
:
(
True
,
"sn"
),
"givenName"
:
(
True
,
"givenName"
),
"niifPersonOrgID"
:
(
True
,
"niifPersonOrgID"
),
}
def
parse_attributes
(
META
):
shib_attrs
=
{}
error
=
False
for
header
,
attr
in
SHIB_ATTRIBUTE_MAP
.
items
():
required
,
name
=
attr
values
=
META
.
get
(
header
,
None
)
value
=
None
if
values
:
# If multiple attributes releases just care about the 1st one
try
:
value
=
values
.
split
(
';'
)[
0
]
except
:
value
=
values
shib_attrs
[
name
]
=
value
if
not
value
or
value
==
''
:
if
required
:
error
=
True
return
shib_attrs
,
error
def
logout
(
request
):
def
logout
(
request
):
auth
.
logout
(
request
)
auth
.
logout
(
request
)
return
redirect
(
'/Shibboleth.sso/Logout?return=https
%3
a
%2
f
%2
fcloud.ik.bme.hu
%2
f'
)
return
redirect
(
'/Shibboleth.sso/Logout?return=https
%3
a
%2
f
%2
fcloud.ik.bme.hu
%2
f'
)
def
login
(
request
):
def
login
(
request
):
attr
,
error
=
parse_attributes
(
request
.
META
)
try
:
if
not
attr
[
'niifPersonOrgID'
]:
user
=
User
.
objects
.
get
(
username
=
request
.
META
[
'niifPersonOrgID'
])
except
KeyError
:
messages
.
error
(
request
,
_
(
'EduID is not available.'
))
messages
.
error
(
request
,
_
(
'EduID is not available.'
))
return
redirect
(
'/admin'
)
return
redirect
(
'/admin'
)
try
:
user
=
User
.
objects
.
get
(
username
=
attr
[
'niifPersonOrgID'
])
except
User
.
DoesNotExist
:
except
User
.
DoesNotExist
:
user
=
User
(
username
=
attr
[
'niifPersonOrgID'
])
user
=
User
(
username
=
attr
[
'niifPersonOrgID'
])
user
.
set_unusable_password
()
user
.
set_unusable_password
()
user
.
first_name
=
attr
[
'givenName'
]
user
.
first_name
=
request
.
META
[
'givenName'
]
user
.
last_name
=
attr
[
'sn'
]
user
.
last_name
=
request
.
META
[
'sn'
]
user
.
email
=
attr
[
'email'
]
user
.
email
=
attr
[
'email'
]
user
.
save
()
user
.
save
()
...
@@ -79,6 +46,7 @@ def login(request):
...
@@ -79,6 +46,7 @@ def login(request):
auth
.
login
(
request
,
user
)
auth
.
login
(
request
,
user
)
logger
.
warning
(
"Shib login with
%
s"
%
request
.
META
)
logger
.
warning
(
"Shib login with
%
s"
%
request
.
META
)
redirect_to
=
request
.
REQUEST
.
get
(
auth
.
REDIRECT_FIELD_NAME
,
''
)
redirect_to
=
request
.
REQUEST
.
get
(
auth
.
REDIRECT_FIELD_NAME
,
''
)
if
not
is_safe_url
(
url
=
redirect_to
,
host
=
request
.
get_host
()):
if
not
is_safe_url
(
url
=
redirect_to
,
host
=
request
.
get_host
()):
redirect_to
=
settings
.
LOGIN_REDIRECT_URL
redirect_to
=
settings
.
LOGIN_REDIRECT_URL
...
...
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