more user stuff
This commit is contained in:
parent
f17d53296e
commit
517e147028
|
@ -285,11 +285,13 @@ class PysonicApi(object):
|
||||||
def getUser_view(self, u, username, **kwargs):
|
def getUser_view(self, u, username, **kwargs):
|
||||||
cherrypy.response.headers['Content-Type'] = 'text/xml; charset=utf-8'
|
cherrypy.response.headers['Content-Type'] = 'text/xml; charset=utf-8'
|
||||||
doc, root = self.response()
|
doc, root = self.response()
|
||||||
user = doc.new_tag("user",
|
|
||||||
username="admin",
|
user = {} if self.options.disable_auth else self.library.db.get_user(cherrypy.request.login)
|
||||||
email="admin@localhost",
|
tag = doc.new_tag("user",
|
||||||
|
username=user["username"],
|
||||||
|
email=user["email"],
|
||||||
scrobblingEnabled="false",
|
scrobblingEnabled="false",
|
||||||
adminRole="false",
|
adminRole="true" if user["admin"] else "false",
|
||||||
settingsRole="false",
|
settingsRole="false",
|
||||||
downloadRole="true",
|
downloadRole="true",
|
||||||
uploadRole="false",
|
uploadRole="false",
|
||||||
|
@ -302,8 +304,9 @@ class PysonicApi(object):
|
||||||
shareRole="true",
|
shareRole="true",
|
||||||
videoConversionRole="false",
|
videoConversionRole="false",
|
||||||
avatarLastChanged="2017-08-07T20:16:24.596Z")
|
avatarLastChanged="2017-08-07T20:16:24.596Z")
|
||||||
root.append(user)
|
root.append(tag)
|
||||||
folder = doc.new_tag("folder")
|
folder = doc.new_tag("folder")
|
||||||
folder.append("0")
|
folder.append("0")
|
||||||
user.append(folder)
|
tag.append(folder)
|
||||||
yield doc.prettify()
|
yield doc.prettify()
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,7 @@ def main():
|
||||||
logging.warning("Artists: {}".format([i["name"] for i in library.get_artists()]))
|
logging.warning("Artists: {}".format([i["name"] for i in library.get_artists()]))
|
||||||
logging.warning("Albums: {}".format(len(library.get_albums())))
|
logging.warning("Albums: {}".format(len(library.get_albums())))
|
||||||
|
|
||||||
|
api = PysonicApi(db, library, args)
|
||||||
api_config = {}
|
api_config = {}
|
||||||
if args.disable_auth:
|
if args.disable_auth:
|
||||||
logging.warning("starting up with auth disabled")
|
logging.warning("starting up with auth disabled")
|
||||||
|
@ -52,7 +53,7 @@ def main():
|
||||||
api_config.update({'tools.auth_basic.on': True,
|
api_config.update({'tools.auth_basic.on': True,
|
||||||
'tools.auth_basic.realm': 'pysonic',
|
'tools.auth_basic.realm': 'pysonic',
|
||||||
'tools.auth_basic.checkpassword': db.validate_password})
|
'tools.auth_basic.checkpassword': db.validate_password})
|
||||||
cherrypy.tree.mount(PysonicApi(db, library, args), '/rest/', {'/': api_config})
|
cherrypy.tree.mount(api, '/rest/', {'/': api_config})
|
||||||
|
|
||||||
cherrypy.config.update({
|
cherrypy.config.update({
|
||||||
'sessionFilter.on': True,
|
'sessionFilter.on': True,
|
||||||
|
|
|
@ -17,6 +17,10 @@ def dict_factory(cursor, row):
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
|
class NotFoundError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class PysonicDatabase(object):
|
class PysonicDatabase(object):
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
self.sqlite_opts = dict(check_same_thread=False, cached_statements=0, isolation_level=None)
|
self.sqlite_opts = dict(check_same_thread=False, cached_statements=0, isolation_level=None)
|
||||||
|
@ -141,3 +145,12 @@ class PysonicDatabase(object):
|
||||||
with closing(self.db.cursor()) as cursor:
|
with closing(self.db.cursor()) as cursor:
|
||||||
cursor.execute("REPLACE INTO users (username, password, admin) VALUES (?, ?, ?)",
|
cursor.execute("REPLACE INTO users (username, password, admin) VALUES (?, ?, ?)",
|
||||||
(username, self.hashit(password), is_admin)).fetchall()
|
(username, self.hashit(password), is_admin)).fetchall()
|
||||||
|
|
||||||
|
def get_user(self, user):
|
||||||
|
with closing(self.db.cursor()) as cursor:
|
||||||
|
try:
|
||||||
|
column = "id" if type(user) is int else "username"
|
||||||
|
return cursor.execute("SELECT * FROM users WHERE {}=?;".format(column), (user, )).fetchall()[0]
|
||||||
|
except IndexError:
|
||||||
|
raise NotFoundError("User doesn't exist")
|
||||||
|
|
||||||
|
|
|
@ -93,3 +93,7 @@ class PysonicLibrary(object):
|
||||||
"mediumImageUrl": "",
|
"mediumImageUrl": "",
|
||||||
"largeImageUrl": "",
|
"largeImageUrl": "",
|
||||||
"similarArtists": []}
|
"similarArtists": []}
|
||||||
|
|
||||||
|
def get_user(self, user):
|
||||||
|
if type(user) is int:
|
||||||
|
return self.db.get_user(username)
|
||||||
|
|
Loading…
Reference in New Issue