예제 #1
0
파일: auth.py 프로젝트: haohcraft/huixiang
    def GET(self, name):
        input = web.input()
        new_user = None
        cur_user = login.logged()
        try:
            client = oauth.createClientWithName(name)
            access_token = client.get_access_token(input["code"])
            user_info = client.get_current_user_info(access_token)

            user_info["access_token"] = access_token

            if cur_user:
                user.update_oauth_userid(name, cur_user["id"], user_info["id"])
                user.update_access_token(name, user_info["id"], access_token)
            if not cur_user:
                oauth_user = user.exist_oauth_user(name, user_info)
                if not oauth_user:
                    new_user = user.new_oauth_user(name, user_info)
                else:
                    user.update_access_token(name, oauth_user[name + "_id"],
                                             access_token)
                user.login_oauth_user(name, user_info)

            return blankrender.logged(True, new_user)
        except Exception:
            return blankrender.logged(True, None)
예제 #2
0
    def POST(self, ctx):
        name = ctx["post"]["name"]
        access_token = ctx["post"]["access_token"]

        ret_user = None
        client_token = None
        cur_user = login.logged()

        client = oauth.createClientWithName(name)
        user_info = client.get_current_user_info(access_token)

        user_info["access_token"] = access_token

        if cur_user:
            print cur_user
            user.update_oauth_userid(name, cur_user["id"], user_info["id"])
            user.update_access_token(name, user_info["id"], access_token)
        if not cur_user:
            print "not cur_user"
            oauth_user = user.exist_oauth_user(name, user_info)
            if not oauth_user:
                ret_user = user.new_oauth_user(name, user_info)
            else:
                ret_user = oauth_user
                user.update_access_token(name, oauth_user[name + "_id"],
                                         access_token)
            client_token = user.login_oauth_user(name, user_info)

        ret_user["client_hash"] = client_token
        return ret_user