コード例 #1
0
ファイル: handler.py プロジェクト: veonua/notiflask
def oauth2callback(code, include_redirect):
    if not code:
        abort(400)

    oauth_flow = create_oauth_flow(include_redirect)
    # Perform the exchange of the code. If there is a failure with exchanging
    # the code, return None.
    try:
        creds = oauth_flow.step2_exchange(code)
        if creds.refresh_token is None:
            abort(400)
    except FlowExchangeError:
        abort(400)

    users_service = util.create_service('oauth2', 'v2', creds)
    # TODO: Check for errors.
    guser = users_service.userinfo().get().execute()

    user, created = User.objects.get_or_create(googleId=guser.get('id'))
    storage = MongoStorage(user)
    creds.set_store(storage)

    if created:
        user.email = guser.get('email')
        user.gender = guser.get('gender') == 'male'
    user.locale = guser.get('locale')
    user.name = guser.get('name')

    try:
        storage.put(creds)
    except DuplicateKeyError as e:
        return "Duplicate " + str(e)

    session['userId'] = str(user.pk)
    session['user'] = {'name': user.name, 'email': user.email}
コード例 #2
0
ファイル: glass_utils.py プロジェクト: veonua/notiflask
    def send_mirror(user, data):
        if not Glass.has_glass_connected(user):
            return

        try:
            creds = MongoStorage(user).get()

            body = data
            body['notification'] = {'level': 'DEFAULT'}

            mirror_service = create_service('mirror', 'v1', creds)
            return mirror_service.timeline().insert(body=body).execute()

        except Exception, e:
            print "Error sending mirror: %s" % e.message