diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-02-13 23:17:19 +0100 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-02-13 23:17:19 +0100 |
commit | 57d2b45d6df52c82e3daabfd43e3c49e9a511ce9 (patch) | |
tree | c1d7d555069363aeb6d06064bbb21f098527fc74 /module/plugins/accounts/ReloadCc.py | |
parent | closed #760 (diff) | |
parent | Change exception handling to Python 2.5 compatible syntax. Increase version n... (diff) | |
download | pyload-57d2b45d6df52c82e3daabfd43e3c49e9a511ce9.tar.xz |
Merge pull request #3 from irrenhaus/stable
Some work on the Reload.cc plugin
Diffstat (limited to 'module/plugins/accounts/ReloadCc.py')
-rw-r--r-- | module/plugins/accounts/ReloadCc.py | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/module/plugins/accounts/ReloadCc.py b/module/plugins/accounts/ReloadCc.py index e0eb5df6e..e4cb32c42 100644 --- a/module/plugins/accounts/ReloadCc.py +++ b/module/plugins/accounts/ReloadCc.py @@ -2,20 +2,22 @@ from module.plugins.Account import Account from module.common.json_layer import json_loads +from module.network.HTTPRequest import BadHeader + class ReloadCc(Account): __name__ = "ReloadCc" - __version__ = "0.2" + __version__ = "0.3" __type__ = "account" __description__ = """Reload.Cc account plugin""" - + __author_name__ = ("Reload Team") __author_mail__ = ("hello@reload.cc") def loadAccountInfo(self, user, req): - + # Get user data from reload.cc status = self.getAccountStatus(user, req) - + # Parse account info account_info = {"validuntil": float(status['msg']['expires']), "pwdhash": status['msg']['hash'], @@ -24,15 +26,18 @@ class ReloadCc(Account): return account_info def login(self, user, data, req): - + # Get user data from reload.cc status = self.getAccountStatus(user, req) - + + if not status: + raise Exception("There was an error upon logging in to Reload.cc!") + # Check if user and password are valid if status['status'] != "ok": self.wrongPassword() - + def getAccountStatus(self, user, req): # Use reload.cc API v1 to retrieve account info and return the parsed json answer query_params = dict( @@ -47,5 +52,22 @@ class ReloadCc(Account): except Exception: query_params.update(dict(pwd=self.accounts[user]['password'])) - answer = req.load("https://api.reload.cc/login", get=query_params) - return json_loads(answer)
\ No newline at end of file + try: + answer = req.load("http://api.reload.cc/login", get=query_params) + except BadHeader, e: + if e.code == 400: + raise Exception("There was an unknown error within the Reload.cc plugin.") + elif e.code == 401: + self.wrongPassword() + elif e.code == 402: + self.expired(user) + elif e.code == 403: + raise Exception("Your account is disabled. Please contact the Reload.cc support!") + elif e.code == 409: + self.empty(user) + elif e.code == 503: + self.logInfo("Reload.cc is currently in maintenance mode! Please check again later.") + self.wrongPassword() + return None + + return json_loads(answer) |