Browse Source

more user stuff

podcasts
dave 5 years ago
parent
commit
517e147028
  1. 41
      pysonic/api.py
  2. 3
      pysonic/daemon.py
  3. 13
      pysonic/database.py
  4. 4
      pysonic/library.py

41
pysonic/api.py

@ -285,25 +285,28 @@ class PysonicApi(object):
def getUser_view(self, u, username, **kwargs):
cherrypy.response.headers['Content-Type'] = 'text/xml; charset=utf-8'
doc, root = self.response()
user = doc.new_tag("user",
username="admin",
email="admin@localhost",
scrobblingEnabled="false",
adminRole="false",
settingsRole="false",
downloadRole="true",
uploadRole="false",
playlistRole="true",
coverArtRole="false",
commentRole="false",
podcastRole="false",
streamRole="true",
jukeboxRole="false",
shareRole="true",
videoConversionRole="false",
avatarLastChanged="2017-08-07T20:16:24.596Z")
root.append(user)
user = {} if self.options.disable_auth else self.library.db.get_user(cherrypy.request.login)
tag = doc.new_tag("user",
username=user["username"],
email=user["email"],
scrobblingEnabled="false",
adminRole="true" if user["admin"] else "false",
settingsRole="false",
downloadRole="true",
uploadRole="false",
playlistRole="true",
coverArtRole="false",
commentRole="false",
podcastRole="false",
streamRole="true",
jukeboxRole="false",
shareRole="true",
videoConversionRole="false",
avatarLastChanged="2017-08-07T20:16:24.596Z")
root.append(tag)
folder = doc.new_tag("folder")
folder.append("0")
user.append(folder)
tag.append(folder)
yield doc.prettify()

3
pysonic/daemon.py

@ -45,6 +45,7 @@ def main():
logging.warning("Artists: {}".format([i["name"] for i in library.get_artists()]))
logging.warning("Albums: {}".format(len(library.get_albums())))
api = PysonicApi(db, library, args)
api_config = {}
if args.disable_auth:
logging.warning("starting up with auth disabled")
@ -52,7 +53,7 @@ def main():
api_config.update({'tools.auth_basic.on': True,
'tools.auth_basic.realm': 'pysonic',
'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({
'sessionFilter.on': True,

13
pysonic/database.py

@ -17,6 +17,10 @@ def dict_factory(cursor, row):
return d
class NotFoundError(Exception):
pass
class PysonicDatabase(object):
def __init__(self, path):
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:
cursor.execute("REPLACE INTO users (username, password, admin) VALUES (?, ?, ?)",
(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")

4
pysonic/library.py

@ -93,3 +93,7 @@ class PysonicLibrary(object):
"mediumImageUrl": "",
"largeImageUrl": "",
"similarArtists": []}
def get_user(self, user):
if type(user) is int:
return self.db.get_user(username)

Loading…
Cancel
Save