Exemple #1
0
def logout(request):
    """用户登出,直接删除access_token"""
    del request.session['oauth_access_token']
    del request.session['oauth_request_expires']
    del request.session['oauth_uid']
    back_to_url = request_helper.get_referer_url(request)
    return HttpResponseRedirect(back_to_url)
Exemple #2
0
def guestbook(request):
    content = request.POST.get('comment', '')
    models.Idea.add_idea(request.user, content)

    url = request_helper.get_referer_url(request)

    return HttpResponseRedirect(url)
Exemple #3
0
def share(request):
    """分享"""
    host = 'http://' + request.META['HTTP_HOST']
    content = u'爱颜色,一个新浪微博应用,推荐大家来看看' + host

    filename = os.path.join(os.path.dirname(__file__), "images/aicolor.png")
    request.auth_client.upload(filename, content)

    url = request_helper.get_referer_url(request)
    return HttpResponseRedirect(url)
Exemple #4
0
def login(request):
    back_to_url = request_helper.get_referer_url(request)
    login_backurl = request.build_absolute_uri('/login_check')
    logging.debug(login_backurl)
    client = sinat_helper.get_oauth(login_backurl)
    if 'oauth_request_expires' not in request.session:
        request.session['login_back_to_url'] = back_to_url
        return HttpResponseRedirect('/weibo_login')
    else:
        access_token = request.session['oauth_access_token']
        expires_in = request.session['oauth_request_expires']
        client.client.set_access_token(access_token, expires_in)
        return HttpResponseRedirect(back_to_url)
Exemple #5
0
def like(request, color_id):
    url = request_helper.get_referer_url(request)
    if color_id is not None:
        auth_client = request.auth_client
        color = models.Color.objects.get(id=int(color_id))
        models.UserLikeColor.like(request.user, color)

        host = 'http://' + request.META['HTTP_HOST']
        color_url = host + ('/detail/%s' % str(color_id))

        message = u'我喜欢了颜色:[%s],%s这里支持或者评论我喜欢的颜色' % (color.value, color_url)
        auth_client.upload_color(message, color.value)

    return HttpResponseRedirect(url)