d120774 by Anon Ray at 2014-03-08 |
1 |
|
|
2 |
# -*- coding utf-8 -*- |
|
3 |
# classes/views/apps.py |
|
4 |
|
|
5 |
|
|
6 |
from flask import Module, jsonify, request, render_template, redirect, url_for |
|
7 |
from hashlib import md5 |
|
8 |
from werkzeug.security import gen_salt |
|
9 |
|
|
10 |
from swtstore.classes.models import Client |
|
11 |
from swtstore.classes.models.um import User |
|
12 |
|
|
13 |
|
|
14 |
app = Module(__name__) |
|
15 |
|
|
16 |
@app.route('/', methods=['GET']) |
|
17 |
# list apps owned by current user |
|
18 |
def list(): |
|
19 |
current_user = User.getCurrentUser() |
|
20 |
if current_user is None: |
|
21 |
return redirect(url_for('index')) |
|
22 |
|
|
23 |
her_apps = Client.getClientsByCreator(current_user.id) |
|
24 |
print 'her_apps' |
|
25 |
print her_apps |
|
26 |
return render_template('list_apps.html', apps=her_apps, |
|
27 |
user=current_user.to_dict()) |
|
28 |
|
|
29 |
|
|
30 |
@app.route('/register', methods=['GET', 'POST']) |
|
31 |
def register(): |
|
32 |
current_user = User.getCurrentUser() |
|
33 |
if current_user is None: |
|
34 |
return redirect(url_for('index')) |
|
35 |
|
|
36 |
user = current_user.to_dict() |
|
37 |
|
|
38 |
if request.method == 'GET': |
|
39 |
return render_template('register_app.html', user=user) |
|
40 |
|
|
41 |
elif request.method == 'POST': |
|
42 |
if not request.form.get('name'): |
|
43 |
abort(400) |
|
44 |
|
|
45 |
new_app = Client( |
|
46 |
id = gen_salt(40), |
|
47 |
client_secret = gen_salt(50), |
|
48 |
name = request.form.get('name'), |
|
49 |
description = request.form.get('desc'), |
|
50 |
user_id = current_user.id, |
|
51 |
_redirect_uris = request.form.get('redirect_uris'), |
|
52 |
_default_scopes = request.form.get('scopes'), |
|
53 |
_is_private = False |
|
54 |
) |
|
55 |
new_app.persist() |
|
56 |
|
|
57 |
return redirect(url_for('list')) |
|
58 |
|