本文整理汇总了Python中Auth.get_user_id方法的典型用法代码示例。如果您正苦于以下问题:Python Auth.get_user_id方法的具体用法?Python Auth.get_user_id怎么用?Python Auth.get_user_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Auth
的用法示例。
在下文中一共展示了Auth.get_user_id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: del_asset
# 需要导入模块: import Auth [as 别名]
# 或者: from Auth import get_user_id [as 别名]
def del_asset():
"""Delete asset"""
# Target asset
asset_id = CTK.request.url.split('/')[-1]
try:
asset_id = __check_asset_id(asset_id)
asset = Asset (asset_id)
if not asset['id']:
return CTK.HTTP_Redir('/')
except:
return CTK.HTTP_Redir('/')
# Authentication
fail_admin = Auth.assert_is_role (Role.ROLE_ADMIN)
user_id = Auth.get_user_id()
is_creator = (asset['creator_id'] == user_id)
if fail_admin and not is_creator:
return fail_admin
op = OpAsset (asset)
result = op.delete()
if result['ret'] == False:
return default()
if result['type'] == 'total':
return CTK.HTTP_Redir(LOCATION)
return default (ERROR_IN_USE)
示例2: publish_asset_apply
# 需要导入模块: import Auth [as 别名]
# 或者: from Auth import get_user_id [as 别名]
def publish_asset_apply ():
# Authentication
fail = Auth.assert_is_role (Role.ROLE_PUBLISHER)
if fail: return fail
acl = ACL()
ret = []
for key in CTK.post:
if not key.startswith('published_'):
continue
flag = int(CTK.post[key])
asset_id = key[len('published_'):]
asset = Asset(asset_id)
if asset['published_flag'] == flag:
continue
asset['published_flag'] = flag
asset['publisher_id'] = Auth.get_user_id()
asset['date_available'] = "CURRENT_TIMESTAMP()"
op = OpAsset(asset)
ret.append(op.update())
if ret[-1] == False:
break
if asset['published_flag']:
acl.set_published_asset_acl(asset, True)
else:
acl.set_published_asset_acl(asset, False)
if False in ret:
return {'ret': "error"}
return {'ret': "ok"}
示例3: __init__
# 需要导入模块: import Auth [as 别名]
# 或者: from Auth import get_user_id [as 别名]
def __init__ (self, params = None):
if params:
self.roles = params['roles']
self.user_id = params['user_id']
else:
self.roles = Role.get_user_roles()
self.user_id = Auth.get_user_id()
示例4: __init__
# 需要导入模块: import Auth [as 别名]
# 或者: from Auth import get_user_id [as 别名]
def __init__ (self, props={}):
user_id = Auth.get_user_id()
bookmarks = Bookmark.get_user_bookmarks (user_id)
options = [('','--')]+[(b,'#%s'%b) for b in bookmarks]
props['selected'] = ''
renders = self._render_options (bookmarks)
ComboTextField.__init__ (self, props, options, renders)
示例5: create_collection
# 需要导入模块: import Auth [as 别名]
# 或者: from Auth import get_user_id [as 别名]
def create_collection (filename):
user_id = Auth.get_user_id()
col_name = filename.split(os.path.sep)[-1]
col = Collection.Collection()
col['name'] = col_name
col['creator_id'] = user_id
op = OpCollection (col)
op.add()
col = Collection.Collection(name_collection=col_name)
return col['id']
示例6: _get_bookmark_link
# 需要导入模块: import Auth [as 别名]
# 或者: from Auth import get_user_id [as 别名]
def _get_bookmark_link (self, asset_id):
bookmark = (asset_id, Auth.get_user_id())
ref = urllib.unquote_plus(CTK.request.url)
flag = Bookmark.bookmark_exists (bookmark)
table = CTK.Table ()
table [(1,1)] = CTK.RawHTML('Favorito')
table [(1,2)] = CTK.Checkbox({'name': 'bookmark', 'checked': flag})
submit = '/bookmark/%s;%s' % (asset_id, ref)
form = CTK.Submitter (submit)
form += table
return form
示例7: add_asset_apply
# 需要导入模块: import Auth [as 别名]
# 或者: from Auth import get_user_id [as 别名]
def add_asset_apply ():
# Authentication
fail = Auth.assert_is_role (Role.ROLE_UPLOADER)
if fail: return fail
asset = Asset()
asset['creator_id'] = Auth.get_user_id()
asset['version'] = 1
if 'parts' in CTK.post:
parts = CTK.post['parts']
if parts:
parts = Validations.split_list (CTK.post['parts'])
asset._parts['has_parts_of'] = [int(p) for p in parts]
if 'parent_id' in CTK.post:
asset._parent_id = int(CTK.post['parent_id'])
for key in ['asset_types_id', 'licenses_id', 'title',
'description', 'version', 'language', 'subject']:
if key in CTK.post:
asset[key] = CTK.post[key]
filenames = []
if 'name' in CTK.post and 'ref' in CTK.post:
tmp_name = CTK.post['ref']
src_name = CTK.post['name']
filenames = Upload.process_file (tmp_name, src_name)
#Collection
if len(filenames) > 1:
col_id = create_collection (src_name)
asset['collections_id'] = col_id
elif len(filenames) == 1:
info = Upload.get_info (filenames[0])
#If unique file is broken
if not info['filename']:
return {'ret': "ok",
'redirect': '%s/broken' %(LOCATION)}
ret = create_assets (asset, filenames)
if False in ret:
return {'ret': "error"}
return {'ret': "ok",
'redirect': LOCATION}
示例8: edit_user
# 需要导入模块: import Auth [as 别名]
# 或者: from Auth import get_user_id [as 别名]
def edit_user():
# Authentication
is_admin = Role.user_has_role (Role.ROLE_ADMIN)
user_id = CTK.request.url.split('/')[3]
profile_id = Profile.get_user_profile (user_id)
current_id = Auth.get_user_id()
try:
is_self = (int(user_id) == current_id)
except:
is_self = False
if not is_admin and not is_self:
return CTK.HTTP_Redir('/')
user_query = "SELECT * FROM users WHERE id = '%(user_id)s';" %(locals())
profile_query = "SELECT id, description FROM profiles;"
# Table
table = PropsAutoSQL ('/admin/user/apply', user_query)
table.AddConstant ('userid', user_id)
table.AddConstant ('old_password', table.SQL_result['password'][0])
if is_admin:
props = {}
if int(current_id) == int(user_id):
props['disabled'] = ''
props['selected'] = profile_id
profiles = ComboboxSQL (props, profile_query)
table.Add ('Profile',profiles, 'profile_id', 'Profile del usuario')
table.Add ('Login', CTK.TextField({'disabled':True}), 'username', 'Login de usuario')
table.Add ('Password', CTK.TextFieldPassword(), 'password', 'Clave de acceso')
table.Add ('Nombre', CTK.TextField(), 'forename', 'Nombre propio')
table.Add ('Apellido 1', CTK.TextField(), 'surname1', 'Primer Apellido')
table.Add ('Apellido 2', CTK.TextField(), 'surname2', 'Segundo Apellido')
table.Add ('E-Mail', CTK.TextField(), 'email', 'Cuenta de correo electronico')
page = Page.Default()
if is_admin:
title = '%s: %s' % (ADMIN_LINK, LINK_HREF % (LOCATION, 'Usuarios'))
else:
title = '%s Edición de usuario' % BACK_LINK
page += CTK.RawHTML ("<h1>%s</h1>" % title)
page += table
return page.Render()
示例9: __init__
# 需要导入模块: import Auth [as 别名]
# 或者: from Auth import get_user_id [as 别名]
def __init__ (self, target_file = None):
user_id = Auth.get_user_id ()
user_usage = Upload.get_usage_user (user_id)
system_usage = Upload.get_usage_system()
self.limits = {
'size' : LIMIT_ASSET_SIZE,
'files' : LIMIT_ASSET_FILES,
'total' : LIMIT_ASSET_TOTAL
}
self.usage = {
'size' : 0,
'files' : user_usage['files'],
'total' : system_usage['size']
}
if target_file:
self.usage['size'] = os.path.getsize (target_file)
示例10: default
# 需要导入模块: import Auth [as 别名]
# 或者: from Auth import get_user_id [as 别名]
def default ():
# Authentication
fail = Auth.assert_is_role (Role.ROLE_CONSUMER)
if fail: return fail
# List of assets
user_id = Auth.get_user_id()
assets = get_user_bookmarks (user_id)
contents = [(Asset, x) for x in assets]
page = Page.Default()
page += CTK.RawHTML ("<h1>Favoritos</h1>")
if len(contents):
page += Paginate(contents, AbstractWidget)
else:
page += CTK.RawHTML ("<h2>No hay favoritos</h2>")
return page.Render()
示例11: get_user_contents
# 需要导入模块: import Auth [as 别名]
# 或者: from Auth import get_user_id [as 别名]
def get_user_contents ():
user_id = Auth.get_user_id()
# List of collections
result = Collection.get_collections_list()
collections = [c['id'] for c in result if c['creator_id'] == user_id]
contents = [(Collection.Collection, x) for x in collections]
# List of assets
lookup = OpLookup()
search = {'creator_id': user_id,
'__order__': 'id'}
try:
result = lookup(search)
except:
result = []
contents += [(Asset.Asset, x) for x in result]
return contents
示例12: default
# 需要导入模块: import Auth [as 别名]
# 或者: from Auth import get_user_id [as 别名]
def default( message = None):
# Authentication
fail = Auth.assert_is_role (Role.ROLE_UPLOADER)
if fail: return fail
# List of assets
lookup = OpLookup()
search = {'creator_id': Auth.get_user_id(),
'__order__': 'id'}
if Role.user_has_role (Role.ROLE_ADMIN):
search = {'__order__': 'id'}
try:
result = lookup(search)
except:
result = []
contents = [(Asset, x) for x in result]
page = Page.Default ()
# Render
if Role.user_has_role (Role.ROLE_ADMIN):
page += CTK.RawHTML ("<h1>%s: Activos</h1>"%(ADMIN_LINK))
else:
page += CTK.RawHTML ("<h1>Administración de Activos</h1>")
if Role.user_has_role (Role.ROLE_UPLOADER):
page += CTK.RawHTML ("<p>%s</p>"%LINK_HREF%('%s/upload/new'%LOCATION, 'Añadir activo'))
if Role.user_has_role (Role.ROLE_PUBLISHER):
page += CTK.RawHTML ("<p>%s</p>"%LINK_HREF%('%s/publish'%LOCATION, 'Publicar activos'))
if Role.user_has_role (Role.ROLE_EDITOR):
page += CTK.RawHTML ("<p>%s</p>"%LINK_HREF%('%s/edit'%LOCATION, 'Editar activos'))
if len(contents):
page += Paginate(contents, DefaultWidget)
if message:
page += Message(message)
return page.Render()
示例13: edit_asset_apply
# 需要导入模块: import Auth [as 别名]
# 或者: from Auth import get_user_id [as 别名]
def edit_asset_apply():
# Authentication
fail = Auth.assert_is_role (Role.ROLE_EDITOR)
if fail: return fail
asset_id = CTK.post.pop('asset_id')
if not asset_id:
return CTK.HTTP_Error(400)
acl = ACL()
editable = acl.filter_assets ("ed" , [asset_id])
if not int(asset_id) in editable:
return CTK.HTTP_Error(401)
# Update the asset
asset = Asset(asset_id)
asset['edited_flag'] = 0
asset['creator_id'] = "%s" % (Auth.get_user_id())
sql_values = []
for key in ['asset_types_id', 'licenses_id', 'title',
'description', 'language', 'subject']:
if CTK.post[key]:
asset[key] = CTK.post[key]
# Always evolve the version number
post_version = asset['version']
if 'version' in CTK.post:
post_version = int(CTK.post['version'])
if post_version <= asset['version']:
asset['version'] += 1
else:
asset['version'] = post_version
# Duplicate the attached file
try:
attachment = File.clone_file (asset._file)
asset._file = attachment
except IOError,e:
# If file copying is not possible, report and abort
msg = 'File duplication could not be performed while editing asset ID %s.' %(asset_id)
msg += '\n%s\n' %(str(e))
print msg
return {'ret':"error"}
示例14: edit_user_apply
# 需要导入模块: import Auth [as 别名]
# 或者: from Auth import get_user_id [as 别名]
def edit_user_apply():
# Authentication
is_admin = Role.user_has_role (Role.ROLE_ADMIN)
user_id = CTK.post['userid']
current_id = Auth.get_user_id()
try:
is_self = (int(user_id) == current_id)
except:
is_self = False
if not is_admin and not is_self:
return CTK.HTTP_Error(403)
if not user_id:
return CTK.HTTP_Error(406)
# Update the database
sql_values = []
for key in ['username', 'forename', 'surname1', 'surname2', 'email']:
if key in CTK.post:
sql_values.append ("%s='%s'" %(key, CTK.post[key]))
if 'password' in CTK.post:
password = CTK.post['password']
hashed_password = md5(password).hexdigest()
old_password = CTK.post['old_password']
if not password == old_password:
sql_values.append ("password='%s'"%(hashed_password))
if is_admin:
key = 'profile_id'
if key in CTK.post:
sql_values.append ("%s=%s" %(key, CTK.post[key]))
q = "UPDATE users SET %s WHERE id = %s;" %(','.join(sql_values), user_id)
if not query_check_success (q):
return {'ret': "error"}
return {'ret': "ok"}
示例15: toggle_bookmark
# 需要导入模块: import Auth [as 别名]
# 或者: from Auth import get_user_id [as 别名]
def toggle_bookmark():
"""Bookmark asset"""
# Authentication
fail = Auth.assert_is_role (Role.ROLE_CONSUMER)
if fail: return fail
params = urllib.unquote_plus(CTK.request.url)
params = params.split('%s/'%LOCATION)[1].split(';')
asset_id = int(params[0])
asset = Asset (asset_id)
user_id = Auth.get_user_id()
if not asset['id']:
return {'ret': "error"}
bookmark = (asset_id, user_id)
if bookmark_exists (bookmark):
del_bookmark(bookmark)
else:
add_bookmark(bookmark)
return {'ret': "ok"}