aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'grumpy/webapp.py')
-rw-r--r--grumpy/webapp.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/grumpy/webapp.py b/grumpy/webapp.py
index dfb7972..b430301 100644
--- a/grumpy/webapp.py
+++ b/grumpy/webapp.py
@@ -8,14 +8,16 @@
:copyright: (c) by 2010 Priit Laes.
:license: BSD, see LICENSE for details.
"""
-from . import app
-from .models import db, Category, Developer, Package, User
-from .utils import requires_auth_basic, send_email
+import hashlib, random
from flask import (flash, g, jsonify, redirect, render_template, request, \
session, url_for)
from flaskext.openid import OpenID
+from . import app
+from .models import db, Category, Developer, Package, User
+from .utils import requires_auth, requires_auth_basic, send_email
+
# OpenID support
oid = OpenID(app)
@@ -42,6 +44,10 @@ def index():
cats = Category.query.order_by(Category.name.asc()).all()
return render_template('index.html', cats=cats)
+@app.route('/account/')
+def account():
+ return render_template('account.html')
+
@app.route('/browse/<cat>/')
def browse_cat(cat):
if cat:
@@ -132,6 +138,14 @@ def confirm_account(email):
db.session.commit()
return render_template('confirm_account.html', success=True)
+@app.route('/_api/1.0/account/generate_api_key', methods=['POST'])
+@requires_auth
+def api_generate_api_key():
+ salt = random.randrange(1000, 10000)
+ g.user.apitoken = hashlib.md5("%s$%d" % (g.user.email, salt)).hexdigest()
+ db.session.commit()
+ return jsonify(dict(apikey=g.user.apitoken))
+
@app.route('/_api/1.0/tinderbox/')
@requires_auth_basic
def tinderbox_api():