f867edb by Anon Ray at 2014-04-10 |
1 |
# -*- coding utf-8 -*- |
|
2 |
# classes/views/oauth.py |
|
3 |
|
|
4 |
from flask import Module, jsonify, request, render_template, redirect, url_for |
|
5 |
import json |
|
6 |
|
|
7 |
from swtstore.classes import oauth |
|
8 |
from swtstore.classes.models.um import User |
|
9 |
from swtstore.classes.models import Client |
|
10 |
|
|
11 |
|
|
12 |
Oauth = Module(__name__) |
|
13 |
|
|
14 |
@Oauth.route('/authorize', methods=['GET', 'POST']) |
|
15 |
@oauth.authorize_handler |
|
16 |
def authorize(*args, **kwargs): |
|
17 |
current_user = User.getCurrentUser() |
|
18 |
if current_user is None: |
|
19 |
return render_template('oauth_login.html') |
|
20 |
|
|
21 |
if request.method == 'GET': |
|
22 |
client_id = kwargs.get('client_id') |
|
23 |
client = Client.query.get(client_id) |
|
24 |
print '/authorize: ' |
|
25 |
print client |
|
26 |
kwargs['client'] = client |
|
27 |
kwargs['user'] = current_user |
|
28 |
print kwargs |
|
29 |
return render_template('authorize.html', **kwargs) |
|
30 |
|
|
31 |
confirm = request.form.get('confirm', 'no') |
|
32 |
print confirm |
|
33 |
return confirm == 'yes' |
|
34 |
|
|
35 |
@Oauth.route('/token', methods=['GET', 'POST']) |
|
36 |
@oauth.token_handler |
|
37 |
def access_token(): |
|
38 |
#print request.form |
|
39 |
print 'access token touched..' |
|
40 |
return None |
|
41 |
|
|
42 |
@Oauth.route('/errors') |
|
43 |
def error(): |
|
44 |
return jsonify(error=request.args.get('error')) |