Beispiel #1
0
def log_in_event(blueprint, token):
    set_user_session()  # Clear previous session

    if not token:
        return login_fail("Failed to log in")

    resp = blueprint.session.get("/oauth2/v1/userinfo")
    if not resp.ok:
        return login_fail("Failed to login user!")

    data = resp.json()

    email = data.get('email', '')
    if not email:
        return login_fail("Google failed to supply an email address")

    users = User.find_by_index('idx_email', email)
    if users:
        user = users[0]
    else:
        user = User(email=email)

    # Update the user info and save the session info
    user.name = data.get('name', email)
    user.photo = data.get('picture', '/static/anonymous_person.png')
    user.logins.append(now_field())
    user.save()

    set_user_session(user.id)
    app_logger().info("Logged in user id %s, email %s" % (user.id, user.email))
Beispiel #2
0
    def test_now(self):
        # First just make sure that we can accurately create parse date time
        # strings. We just create a low N amount for testing
        COUNT = 100
        for _ in range(COUNT):
            s = now_field()
            d = parse_now_field(s)
            # We assume that we got a parseable date string - we confirm that
            # we got this back by subtracting from a known datetime and then
            # making sure that the difference is sane
            self.assertCloseTimes(d, datetime.datetime.utcnow())

        # Make sure that we work with and without microseconds
        ref = datetime.datetime(2050, 12, 1, 14, 45, 55, 123)

        # with microseconds
        self.assertCloseTimes(
            ref, parse_now_field('UTC:' + '2050-12-01T14:45:55.000123'))

        # withOUT microseconds
        self.assertCloseTimes(ref,
                              parse_now_field('UTC:' + '2050-12-01T14:45:55'))