From b936576d6d2f2ff164f372b94d20eb9557ded6b9 Mon Sep 17 00:00:00 2001 From: Ruud Date: Wed, 25 Apr 2012 22:31:22 +0200 Subject: [PATCH] Get apikey with username and password. closes #142 --- couchpotato/__init__.py | 18 ++++++++++++++++++ couchpotato/templates/api.html | 6 ++++++ 2 files changed, 24 insertions(+) diff --git a/couchpotato/__init__.py b/couchpotato/__init__.py index 799a2984..8386ed9f 100644 --- a/couchpotato/__init__.py +++ b/couchpotato/__init__.py @@ -1,6 +1,8 @@ from couchpotato.api import api_docs, api_docs_missing from couchpotato.core.auth import requires_auth from couchpotato.core.event import fireEvent +from couchpotato.core.helpers.request import getParams, jsonified +from couchpotato.core.helpers.variable import md5 from couchpotato.core.logger import CPLog from couchpotato.environment import Env from flask.app import Flask @@ -51,6 +53,22 @@ def apiDocs(): del api_docs_missing[''] return render_template('api.html', fireEvent = fireEvent, routes = sorted(routes), api_docs = api_docs, api_docs_missing = sorted(api_docs_missing)) +@web.route('getkey/') +def getApiKey(): + + api = None + params = getParams() + username = Env.setting('username') + password = Env.setting('password') + + if (params.get('u') == md5(username) or not username) and (params.get('p') == password or not password): + api = Env.setting('api_key') + + return jsonified({ + 'success': api is not None, + 'api_key': api + }) + @app.errorhandler(404) def page_not_found(error): index_url = url_for('web.index') diff --git a/couchpotato/templates/api.html b/couchpotato/templates/api.html index ec067f95..f0e76e36 100644 --- a/couchpotato/templates/api.html +++ b/couchpotato/templates/api.html @@ -18,6 +18,12 @@
You can also use the API over another domain using JSONP, the callback function should be in 'callback_func'
{{ fireEvent('app.api_url', single = True)|safe }}/updater.info/?callback_func=myfunction
+
+
+ Get the API key: +
/getkey/?p=md5(password)&u=md5(username)
+ Will return {"api_key": "XXXXXXXXXX", "success": true}. When username or password is empty you don't need to md5 it. +
{% for route in routes %}