diff options
author | 2014-10-20 02:20:56 +0200 | |
---|---|---|
committer | 2014-10-20 02:20:56 +0200 | |
commit | f70cd18b0c7cb303597a06becc791035f7fd7bd6 (patch) | |
tree | b9348d03114caf482ca7edbce0d37e32b698d02d /module | |
parent | Tiny code cosmetics in Ftp and Http accounts (diff) | |
download | pyload-f70cd18b0c7cb303597a06becc791035f7fd7bd6.tar.xz |
[XFSPAccount] Fixed broken login due missing HOSTER_URL
Diffstat (limited to 'module')
-rw-r--r-- | module/plugins/Account.py | 29 | ||||
-rw-r--r-- | module/plugins/internal/XFSPAccount.py | 7 |
2 files changed, 32 insertions, 4 deletions
diff --git a/module/plugins/Account.py b/module/plugins/Account.py index 1adba6af4..9c97d2cf9 100644 --- a/module/plugins/Account.py +++ b/module/plugins/Account.py @@ -39,16 +39,19 @@ class Account(Base): self.manager = manager self.accounts = {} - self.infos = {} # cache for account information + self.infos = {} #: cache for account information self.lock = RLock() - self.timestamps = {} - self.setAccounts(accounts) + self.init() + self.setAccounts(accounts) + + def init(self): pass + def login(self, user, data, req): """login into account, the cookies will be saved so user can be recognized @@ -58,6 +61,7 @@ class Account(Base): """ pass + @lock def _login(self, user, data): # set timestamp for login @@ -85,6 +89,7 @@ class Account(Base): req.close() return success + def relogin(self, user): req = self.getAccountRequest(user) if req: @@ -95,12 +100,14 @@ class Account(Base): return self._login(user, self.accounts[user]) + def setAccounts(self, accounts): self.accounts = accounts for user, data in self.accounts.iteritems(): self._login(user, data) self.infos[user] = {} + def updateAccounts(self, user, password=None, options={}): """ updates account and return true if anything changed """ @@ -119,6 +126,7 @@ class Account(Base): self._login(user, self.accounts[user]) return True + def removeAccount(self, user): if user in self.accounts: del self.accounts[user] @@ -127,6 +135,7 @@ class Account(Base): if user in self.timestamps: del self.timestamps[user] + @lock def getAccountInfo(self, name, force=False): """retrieve account infos for an user, do **not** overwrite this method!\\ @@ -165,10 +174,12 @@ class Account(Base): data.update(self.infos[name]) return data + def isPremium(self, user): info = self.getAccountInfo(user) return info['premium'] + def loadAccountInfo(self, name, req=None): """this should be overwritten in account plugin,\ and retrieving account information for user @@ -190,9 +201,11 @@ class Account(Base): "type": self.__name__, } + def getAllAccounts(self, force=False): return [self.getAccountInfo(user, force) for user, data in self.accounts.iteritems()] + def getAccountRequest(self, user=None): if not user: user, data = self.selectAccount() @@ -202,6 +215,7 @@ class Account(Base): req = self.core.requestFactory.getRequest(self.__name__, user) return req + def getAccountCookies(self, user=None): if not user: user, data = self.selectAccount() @@ -211,9 +225,11 @@ class Account(Base): cj = self.core.requestFactory.getCookieJar(self.__name__, user) return cj + def getAccountData(self, user): return self.accounts[user] + def selectAccount(self): """ returns an valid account name and data""" usable = [] @@ -243,15 +259,19 @@ class Account(Base): if not usable: return None, None return choice(usable) + def canUse(self): return False if self.selectAccount() == (None, None) else True + def parseTraffic(self, string): #returns kbyte return parseFileSize(string) / 1024 + def wrongPassword(self): raise WrongPassword + def empty(self, user): if user in self.infos: self.logWarning(_("Account %s has not enough traffic, checking again in 30min") % user) @@ -259,6 +279,7 @@ class Account(Base): self.infos[user].update({"trafficleft": 0}) self.scheduleRefresh(user, 30 * 60) + def expired(self, user): if user in self.infos: self.logWarning(_("Account %s is expired, checking again in 1h") % user) @@ -266,11 +287,13 @@ class Account(Base): self.infos[user].update({"validuntil": time() - 1}) self.scheduleRefresh(user, 60 * 60) + def scheduleRefresh(self, user, time=0, force=True): """ add task to refresh account info to sheduler """ self.logDebug("Scheduled Account refresh for %s in %s seconds." % (user, time)) self.core.scheduler.addJob(time, self.getAccountInfo, [user, force]) + @lock def checkLogin(self, user): """ checks if user is still logged in """ diff --git a/module/plugins/internal/XFSPAccount.py b/module/plugins/internal/XFSPAccount.py index 713bf827d..c2d779c29 100644 --- a/module/plugins/internal/XFSPAccount.py +++ b/module/plugins/internal/XFSPAccount.py @@ -13,7 +13,7 @@ from module.utils import parseFileSize class XFSPAccount(Account): __name__ = "XFSPAccount" __type__ = "account" - __version__ = "0.13" + __version__ = "0.14" __description__ = """XFileSharingPro account plugin""" __license__ = "GPLv3" @@ -43,6 +43,11 @@ class XFSPAccount(Account): LOGIN_FAIL_PATTERN = r'>(Incorrect Login or Password|Error<)' + def __init__(self, manager, accounts): #@TODO: remove in 0.4.10 + self.init() + return super(XFSPAccount, self).__init__(manager, accounts) + + def init(self): if not hasattr(self, "HOSTER_URL"): self.HOSTER_URL = "http://%s/" % self.HOSTER_NAME |