diff options
Diffstat (limited to 'pyload')
| -rw-r--r-- | pyload/Api.py | 27 | ||||
| -rw-r--r-- | pyload/api/UserApi.py | 41 | ||||
| -rw-r--r-- | pyload/api/__init__.py | 2 | ||||
| -rw-r--r-- | pyload/remote/pyload.thrift | 6 | 
4 files changed, 47 insertions, 29 deletions
| diff --git a/pyload/Api.py b/pyload/Api.py index 32a077c08..81e39d82d 100644 --- a/pyload/Api.py +++ b/pyload/Api.py @@ -128,8 +128,6 @@ class Api(Iface):      #  Auth+User Information      ############################# -    # TODO -      @RequirePerm(Permission.All)      def login(self, username, password, remoteip=None):          """Login into pyLoad, this **must** be called when using rpc before any methods can be used. @@ -153,7 +151,8 @@ class Api(Iface):          return self.core.db.checkAuth(username, password) -    def isAuthorized(self, func, user): +    @staticmethod +    def isAuthorized(func, user):          """checks if the user is authorized for specific method          :param func: function name @@ -167,28 +166,6 @@ class Api(Iface):          else:              return False -    # TODO -    @RequirePerm(Permission.All) -    def getUserData(self, username, password): -        """similar to `checkAuth` but returns UserData thrift type """ -        user = self.checkAuth(username, password) -        if not user: -            raise UserDoesNotExists(username) - -        return user.toUserData() - -    def getAllUserData(self): -        """returns all known user and info""" -        return self.core.db.getAllUserData() - -    def changePassword(self, username, oldpw, newpw): -        """ changes password for specific user """ -        return self.core.db.changePassword(username, oldpw, newpw) - -    def setUserPermission(self, user, permission, role): -        self.core.db.setPermission(user, permission) -        self.core.db.setRole(user, role) -  class UserApi(Api):      """  Proxy object for api that provides all methods in user context """ diff --git a/pyload/api/UserApi.py b/pyload/api/UserApi.py new file mode 100644 index 000000000..250b9080c --- /dev/null +++ b/pyload/api/UserApi.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from pyload.Api import Api, RequirePerm, Permission + +from ApiComponent import ApiComponent + + +class UserApi(ApiComponent): +    """ Api methods to retrieve user profile and manage users. """ + +    @RequirePerm(Permission.All) +    def getUserData(self): +        """ Retrieves :class:`UserData` for the currently logged in user. """ + +    @RequirePerm(Permission.All) +    def setPassword(self, username, old_password, new_password): +        """ Changes password for specific user. User can only change their password. +        Admins can change every password! """ + +    def getAllUserData(self): +        """ Retrieves :class:`UserData` of all exisitng users.""" + +    def addUser(self, username, password): +        """ Adds an user to the db. +        :param username: desired username +        :param password: password for authentication +        """ + +    def updateUserData(self, data): +        """ Change parameters of user account.  """ + +    def removeUser(self, uid): +        """ Removes user from the db. + +        :param uid: users uid +        """ + + +if Api.extend(UserApi): +    del UserApi
\ No newline at end of file diff --git a/pyload/api/__init__.py b/pyload/api/__init__.py index bea46011d..a2b292a27 100644 --- a/pyload/api/__init__.py +++ b/pyload/api/__init__.py @@ -1,5 +1,5 @@  __all__ = ["CoreApi", "ConfigApi", "DownloadApi", "DownloadPreparingApi", "FileApi", -            "UserInteractionApi", "AccountApi", "AddonApi"] +            "UserInteractionApi", "AccountApi", "AddonApi", "UserApi"]  # Import all components  # from .import * diff --git a/pyload/remote/pyload.thrift b/pyload/remote/pyload.thrift index 905be22b0..3d0f201e7 100644 --- a/pyload/remote/pyload.thrift +++ b/pyload/remote/pyload.thrift @@ -495,6 +495,9 @@ service Pyload {    // returns own user data    UserData getUserData(), +  // works contextual, admin can change every password +  bool setPassword(1: string username, 2: string old_password, 3: string new_password), +    // all user, for admins only    map<UserID, UserData> getAllUserData(), @@ -504,9 +507,6 @@ service Pyload {    void updateUserData(1: UserData data),    void removeUser(1: UserID uid), -  // works contextual, admin can change every password -  bool setPassword(1: string username, 2: string old_password, 3: string new_password), -    ///////////////////////    // Addon Methods    /////////////////////// | 
