Esempio n. 1
0
def callback():
    code = request.args.get("code")
    google_provider_cfg = get_google_provider_cfg()
    token_endpoint = google_provider_cfg["token_endpoint"]
    token_url, headers, body = client.prepare_token_request(
        token_endpoint,
        authorization_response=request.url,
        redirect_url=request.base_url,
        code=code,
    )
    token_response = requests.post(
        token_url,
        headers=headers,
        data=body,
        auth=(GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET),
    )
    client.parse_request_body_response(json.dumps(token_response.json()))
    userinfo_endpoint = google_provider_cfg["userinfo_endpoint"]
    uri, headers, body = client.add_token(userinfo_endpoint)
    userinfo_response = requests.get(uri, headers=headers, data=body)
    if userinfo_response.json().get("email_verified"):
        unique_id = userinfo_response.json()["sub"]
        users_email = userinfo_response.json()["email"]
        picture = userinfo_response.json()["picture"]
        users_name = userinfo_response.json()["given_name"]
    else:
        return "User email not available or not verified by Google.", 400
    user = User(id_=unique_id, name=users_name, email=users_email, profile_pic=picture)
    if not User.get(unique_id):
        User.create(unique_id, users_name, users_email, picture)
    login_user(user)
    return redirect('/')
def warmup(environ, start_response):
    try:
        User.create(email="*****@*****.**", password="******")
    except EmailTaken:
        # Test user already in the database. No action needed
        pass
    start_response('200 OK', [])
    return ['']
Esempio n. 3
0
def warmups(environ, start_response):
    try:
        User.create(
            email="*****@*****.**",
            password="******"
        )
    except EmailTaken:
        # Test user already in the database. No action needed
        pass
    start_response('200 OK', [])
    logging.info('Starting actions')
    if not Movies.query_movies():
        logging.info('Populating database')
        for page in range(1,11):
            movies = get_OMDB_movies(page_number=page)
            populate_database(movies)
        logging.info('Database was populated')
    else:
        logging.info('Database doesn\'t need to be populated')

    return ['']