1
# -*- coding utf-8 -*-
2
# classes/views/oauth.py
3
4
from flask import Module, jsonify, request, render_template, redirect,\
5
                    url_for, current_app
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
        current_app.logger.debug('In /authorize: client: %s', client)
25
        kwargs['client'] = client
26
        kwargs['user'] = current_user
27
        current_app.logger.debug('kwargs %s', kwargs)
28
        return render_template('authorize.html', **kwargs)
29
30
    confirm = request.form.get('confirm', 'no')
31
    current_app.logger.debug('confirm authorize from user: %s', confirm)
32
    return confirm == 'yes'
33
34
@Oauth.route('/token', methods=['GET', 'POST'])
35
@oauth.token_handler
36
def access_token():
37
    #print request.form
38
    current_app.logger.debug('access token touched..')
39
    return None
40
41
@Oauth.route('/errors')
42
def error():
43
    return jsonify(error=request.args.get('error'))