Exemplo n.º 1
0
def handler(req):
    req.send_http_header()
    req.content_type = 'text/html;charset=UTF-8'
    session = Session.Session(req, timeout=3600)
    session.load()
    session = session_init(session)
    oauth_manager = oauthmanager.OAuth_manager(session)
    calender_api = calenderapi.Calender_api(oauth_manager)
    #URL에서 파일명 추출
    real_file_name = req.filename[req.filename.rfind('/') + 1:]
    if real_file_name == 'index.html':
        #등록된 accessToken이 있는지 판단
        if oauth_manager.check_access_token():
            util.redirect(req, 'access_resource.py')
        else:
            #등록된 accessToken이 없다면 인증페이지로
            util.redirect(req, 'oauth.py')
    elif real_file_name == 'oauth.py':
        oauth_template = file(config.oauth_file).read()
        req.write(oauth_template)
    elif real_file_name == 'request_token.py':
        #request_token 생성 및 사용자 인증 URL redirect
        util.redirect(req, oauth_manager.create_reqeust_token())
    elif real_file_name == 'callback.py':
        #callback_url 처리
        oauth_manager.create_access_token(req)
        util.redirect(req, 'index.html')
    elif real_file_name == 'access_resource.py':
        for title in calender_api.load_event_by_all('2011-5-1', '2011-5-31'):
            req.write('일정 제목 -> %s<br>' % (title.encode('utf-8')))

    return apache.OK
Exemplo n.º 2
0
Arquivo: views.py Projeto: tadoli/apis
def access_resource(request):
    oauth_manager = oauthmanager.OAuth_manager(request.session)
    calender_api = calenderapi.Calender_api(oauth_manager)
    result = 'Daum Calender API - 일정가져오기<br>'
    for title in calender_api.load_event_by_all('2011-5-1', '2011-6-30'):
        result += ('일정제목 -> %s<br>' % (title.encode('utf-8')))
    return HttpResponse(result)
Exemplo n.º 3
0
def handler(req):
    req.send_http_header()
    req.content_type = 'text/html;charset=UTF-8'
    session = Session.Session(req, timeout=3600)
    session.load()
    session = session_init(session)
    oauth_manager = oauthmanager.OAuth_manager(session)
    calender_api = calenderapi.Calender_api(oauth_manager)
    #request parameter
    formValueList = util.FieldStorage(req)
    #URL에서 파일명 추출
    real_file_name = req.filename[req.filename.rfind('/') + 1:]
    if real_file_name == 'index.html':
        #등록된 accessToken이 있는지 판단
        if oauth_manager.check_access_token():
            template = file(config.index_file).read()
            search_date = formValueList.get(
                'date',
                '%s-%s' % (time.localtime().tm_year, time.localtime().tm_mon))
            try:
                content = createcalender.Create_calender(
                    int(search_date.split('-')[0]),
                    int(search_date.split('-')[1]), calender_api)
            except ValueError, error:
                #data 형식이 잘못 되었을 경우
                req.write("ValueError -> %s" % error)
            else:
                req.write(template % content)
        else:
            #등록된 accessToken이 없다면 인증페이지로
            util.redirect(req, 'oauth.py')
Exemplo n.º 4
0
Arquivo: views.py Projeto: tadoli/apis
def index(request):
    oauth_template = file(config.oauth_file).read()
    oauth_manager = oauthmanager.OAuth_manager(request.session)
    #세션에 등록된 accessToken이 있는지 판단
    if oauth_manager.check_access_token():
        return HttpResponseRedirect('access_resource')
    else:
        return HttpResponse(oauth_template)
Exemplo n.º 5
0
Arquivo: views.py Projeto: tadoli/apis
def index(request):
    oauth_template = file(config.oauth_file).read()
    oauth_manager = oauthmanager.OAuth_manager(request.session)
    #등록된 accessToken이 있는지 판단
    if oauth_manager.check_access_token():
        return HttpResponseRedirect(
            '/tutorial_python/calender/django/calender/main')
    else:
        return HttpResponse(oauth_template)
Exemplo n.º 6
0
Arquivo: views.py Projeto: tadoli/apis
def callback(request):
    oauth_manager = oauthmanager.OAuth_manager(request.session)
    verifier_code = request.GET['oauth_verifier']
    oauth_manager.create_access_token(verifier_code)
    return HttpResponseRedirect('/tutorial_python/calender/django/oauth/main')
Exemplo n.º 7
0
Arquivo: views.py Projeto: tadoli/apis
def request_token(request):
    oauth_manager = oauthmanager.OAuth_manager(request.session)
    return HttpResponseRedirect(oauth_manager.create_reqeust_token())
Exemplo n.º 8
0
Arquivo: views.py Projeto: tadoli/apis
def callback(request):
    oauth_manager = oauthmanager.OAuth_manager(request.session)
    verifier_code = request.GET['oauth_verifier']
    oauth_manager.create_access_token(verifier_code)
    return HttpResponseRedirect('main')