Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Helios Server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TO
Helios Server
Commits
1f90b423
Commit
1f90b423
authored
9 years ago
by
Lukáš Nový
Browse files
Options
Downloads
Patches
Plain Diff
Add support for fetching constraints/categories from pirate graph database
parent
0fc70213
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
helios_auth/auth_systems/pirateid.py
+47
-5
47 additions, 5 deletions
helios_auth/auth_systems/pirateid.py
with
47 additions
and
5 deletions
helios_auth/auth_systems/pirateid.py
+
47
−
5
View file @
1f90b423
...
@@ -11,6 +11,10 @@ import sys, os, cgi, urllib, urllib2, re
...
@@ -11,6 +11,10 @@ import sys, os, cgi, urllib, urllib2, re
from
xml.etree
import
ElementTree
from
xml.etree
import
ElementTree
from
openid
import
view_helpers
from
openid
import
view_helpers
import
json
import
urllib2
import
logging
# some parameters to indicate that status updating is not possible
# some parameters to indicate that status updating is not possible
STATUS_UPDATES
=
False
STATUS_UPDATES
=
False
...
@@ -19,15 +23,24 @@ STATUS_UPDATES = False
...
@@ -19,15 +23,24 @@ STATUS_UPDATES = False
LOGIN_MESSAGE
=
"
Log in with my PirateID
"
LOGIN_MESSAGE
=
"
Log in with my PirateID
"
OPENID_ENDPOINT
=
'
https://openid.pirati.cz
'
OPENID_ENDPOINT
=
'
https://openid.pirati.cz
'
AX_REQUIRED_FIELDS
=
{
'
firstname
'
:
'
http://axschema.org/namePerson/first
'
,
'
lastname
'
:
'
http://axschema.org/namePerson/last
'
,
'
fullname
'
:
'
http://axschema.org/namePerson
'
,
'
email
'
:
'
http://axschema.org/contact/email
'
,
'
nickname
'
:
'
http://axschema.org/namePerson/friendly
'
}
def
get_auth_url
(
request
,
redirect_url
):
def
get_auth_url
(
request
,
redirect_url
):
request
.
session
[
'
pirateid_redirect_url
'
]
=
redirect_url
request
.
session
[
'
pirateid_redirect_url
'
]
=
redirect_url
url
=
view_helpers
.
start_openid
(
request
.
session
,
OPENID_ENDPOINT
,
redirect_url
,
redirect_url
)
url
=
view_helpers
.
start_openid
(
request
.
session
,
OPENID_ENDPOINT
,
redirect_url
,
redirect_url
,
ax_required_fields
=
AX_REQUIRED_FIELDS
)
return
url
return
url
def
get_user_info_after_auth
(
request
):
def
get_user_info_after_auth
(
request
):
data
=
view_helpers
.
finish_openid
(
request
.
session
,
request
.
GET
,
request
.
session
[
'
pirateid_redirect_url
'
])
data
=
view_helpers
.
finish_openid
(
request
.
session
,
request
.
GET
,
request
.
session
[
'
pirateid_redirect_url
'
]
,
ax_required_fields
=
AX_REQUIRED_FIELDS
)
return
{
'
type
'
:
'
pirateid
'
,
'
user_id
'
:
data
[
'
ax
'
][
'
email
'
][
0
],
'
name
'
:
data
[
'
ax
'
][
'
fullname
'
][
0
],
'
info
'
:
{
'
email
'
:
data
[
'
ax
'
][
'
email
'
][
0
]},
'
token
'
:{}}
return
{
'
type
'
:
'
pirateid
'
,
'
user_id
'
:
data
[
'
ax
'
][
'
nickname
'
][
0
],
'
name
'
:
data
[
'
ax
'
][
'
fullname
'
][
0
],
'
info
'
:
{
'
email
'
:
data
[
'
ax
'
][
'
email
'
][
0
]},
'
token
'
:{}}
def
do_logout
(
user
):
def
do_logout
(
user
):
"""
"""
...
@@ -47,9 +60,38 @@ def send_message(user_id, user_name, user_info, subject, body):
...
@@ -47,9 +60,38 @@ def send_message(user_id, user_name, user_info, subject, body):
"""
"""
send_mail
(
subject
,
body
,
settings
.
SERVER_EMAIL
,
[
"
%s <%s>
"
%
(
user_name
,
user_id
)],
fail_silently
=
False
)
send_mail
(
subject
,
body
,
settings
.
SERVER_EMAIL
,
[
"
%s <%s>
"
%
(
user_name
,
user_id
)],
fail_silently
=
False
)
def
check_constraint
(
constraint
,
user_info
):
def
generate_constraint
(
category_id
,
user
):
return
category_id
def
eligibility_category_id
(
constraint
):
return
constraint
import
pprint
pp
=
pprint
.
PrettyPrinter
(
indent
=
4
)
def
check_constraint
(
constraint
,
user
):
"""
"""
for eligibility
for eligibility
"""
"""
pass
userinfo
=
json
.
load
(
urllib2
.
urlopen
(
"
https://graph.pirati.cz/user/
"
+
user
.
user_id
))
id
=
userinfo
[
u
'
id
'
]
usergroups
=
json
.
load
(
urllib2
.
urlopen
(
"
https://graph.pirati.cz/
"
+
id
+
"
/groups
"
))
for
usergroup
in
usergroups
:
if
usergroup
[
u
'
id
'
]
==
constraint
:
return
True
return
False
def
can_list_categories
():
"""
we will use phpbb groups
"""
return
True
def
list_categories
(
user
):
"""
returns [{id,name},...]
"""
categories
=
[]
groups
=
json
.
load
(
urllib2
.
urlopen
(
"
https://graph.pirati.cz/groups
"
))
for
group
in
groups
:
categories
.
append
({
'
id
'
:
group
[
u
'
id
'
],
'
name
'
:
group
[
u
'
username
'
]})
return
categories
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment