Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F95814306
settings.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Dec 19, 13:15
Size
2 KB
Mime Type
text/x-python
Expires
Sat, Dec 21, 13:15 (1 d, 21 h)
Engine
blob
Format
Raw Data
Handle
23062415
Attached To
R3600 invenio-infoscience
settings.py
View Options
# -*- coding: utf-8 -*-
##
## This file is part of Invenio.
## Copyright (C) 2014 CERN.
##
## Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
"""
OAuth Client Settings Blueprint
"""
from
__future__
import
absolute_import
import
six
from
operator
import
itemgetter
from
flask
import
Blueprint
,
render_template
,
request
#from flask import redirect, url_for
from
flask.ext.login
import
login_required
,
current_user
from
flask.ext.breadcrumbs
import
register_breadcrumb
from
flask.ext.menu
import
register_menu
from
invenio.base.i18n
import
_
from
invenio.base.globals
import
cfg
#from invenio.ext.sqlalchemy import db
from
invenio.ext.sslify
import
ssl_required
from
..models
import
RemoteAccount
from
..client
import
oauth
blueprint
=
Blueprint
(
'oauthclient_settings'
,
__name__
,
url_prefix
=
"/account/settings/linkedaccounts"
,
static_folder
=
"../static"
,
template_folder
=
"../templates"
,
)
@blueprint.route
(
"/"
,
methods
=
[
'GET'
,
'POST'
])
@ssl_required
@login_required
@register_menu
(
blueprint
,
'settings.oauthclient'
,
_
(
'
%(icon)s
Linked accounts'
,
icon
=
'<i class="fa fa-link fa-fw"></i>'
),
order
=
3
,
active_when
=
lambda
:
request
.
endpoint
.
startswith
(
"oauthclient_settings."
)
)
@register_breadcrumb
(
blueprint
,
'breadcrumbs.settings.oauthclient'
,
_
(
'Linked accounts'
)
)
def
index
():
services
=
[]
service_map
=
{}
i
=
0
for
appid
,
conf
in
six
.
iteritems
(
cfg
[
'OAUTHCLIENT_REMOTE_APPS'
]):
if
not
conf
.
get
(
'hide'
,
False
):
services
.
append
(
dict
(
appid
=
appid
,
title
=
conf
[
'title'
],
icon
=
conf
.
get
(
'icon'
,
None
),
description
=
conf
.
get
(
'description'
,
None
),
account
=
None
))
service_map
[
oauth
.
remote_apps
[
appid
]
.
consumer_key
]
=
i
i
+=
1
# Fetch already linked accounts
accounts
=
RemoteAccount
.
query
.
filter_by
(
user_id
=
current_user
.
get_id
()
)
.
all
()
for
a
in
accounts
:
if
a
.
client_id
in
service_map
:
services
[
service_map
[
a
.
client_id
]][
'account'
]
=
a
# Sort according to title
services
.
sort
(
key
=
itemgetter
(
'title'
))
return
render_template
(
"oauthclient/settings/index.html"
,
services
=
services
)
Event Timeline
Log In to Comment