예제 #1
0
def main_handler():
    response.content_type = 'application/json'
    return {
        'status': 'OK',
        'detail': 'Nothing to show on this page, try http://%s:%s/login'
                      % (Utility.ins().hostname(), Utility.ins().port())
    }
예제 #2
0
def event_list_handler():
    user_id = request.query.user
    credentials = OAuthHandler.ins().get_credentials(user_id)
    if credentials is None or credentials.invalid:
        return {
            'status': 'ERROR',
            'detail': 'User id not exist, URL should look like: http://%s:%s/event/list?user=123'
                      % (Utility.ins().hostname(), Utility.ins().port())
        }
    try:
        calendar_output = get_calendar_data(credentials)
        response.set_header('Cache-Control', 'no-cache')
        response.set_header('Content-type', 'application/json')
        return calendar_output
    except AccessTokenRefreshError:
        response.content_type = 'application/json'
        return {
            'status': 'ERROR',
            'detail': 'Credential expired, please re-login'
        }
예제 #3
0
def login_handler():
    user_id = request.query.user
    print('>> Login using: ' + user_id)
    if user_id:
        credentials = OAuthHandler.ins().get_credentials(user_id)
        if credentials is None or credentials.invalid:
            OAuthHandler.ins().respond_redirect_to_auth_server(response, user_id)
        else:
            response.content_type = 'application/json'
            return {
                'status': 'OK',
                'detail': 'Already logined'
            }
    else:
        response.content_type = 'application/json'
        return {
            'status': 'ERROR',
            'detail': 'Missing user id, URL should look like: http://%s:%s/login?user=123'
                      % (Utility.ins().hostname(), Utility.ins().port())
        }
예제 #4
0
#!/usr/bin/env python

import sys, os
from bottle import run
from utility import Utility

sys.path.append(os.sep.join((os.getcwd(),'handler')))
import root
import login
import event
import gettime

hostname = Utility.ins().hostname()
if hostname != '':
    run(host=hostname, port=9999, debug=True)
else:
    print(">> ERROR: client_secrets.json file incorrect!")