def login(): profile = request.get_json(force=True)['profile'] unique_id = profile['googleId'] users_email = profile['email'] picture = profile['imageUrl'] users_name = profile['name'] current_app.user_uid = unique_id session['user_uid'] = unique_id # Create a user in your db with the information provided # by Google user = User(id_=unique_id, name=users_name, email=users_email, avatar=picture) new_user = False # Remember to change back! # Doesn't exist? Add it to the database. if not User.get(unique_id): new_user = True print("User doesn't exist, creating new User") User.create(unique_id, users_name, users_email, picture) # Begin user session by logging the user in (using Flask Log-in) login_user(user) return jsonify(message=current_user.is_authenticated, new_user=new_user), 200
def load_user(user_id): return User.get(user_id)