def db_update_user(db_session, login_session): user_id = login_session['id'] user = db_session.query(User).filter_by(id=user_id).all() if not user: user = User() user.id = user_id db_session.add(user) db_session.commit()
def db_update_user(db_session, login_session): # if user is not already in db: # insert into db user_id = login_session['id'] user = db_session.query(User).filter_by(id=user_id).all() if not user: user = User() user.id = user_id db_session.add(user) db_session.commit()
def googlesignin(): print 'step: googlesignin' token = request.form['idtoken'] if token == None: print 'token is none.' return 'False' else: print 'token is available.' session['signin_party'] = 'google' result, idinfo = get_info_from_google(token) if result == False: print 'googlesignin: failed to get info from google.' session.pop('signin_party', None) return 'False' user = User.get_by_id(idinfo['email']) if user == None: print 'googlesingin: It is new user.' user = User() user.id = idinfo['email'] user.first_name = idinfo['given_name'] user.last_name = idinfo['family_name'] user.add() else: print 'googlesingin: It is NOT new user.' user.id = idinfo['email'] user.first_name = idinfo['given_name'] user.last_name = idinfo['family_name'] user.merge() print user.commit() session['user_id'] = user.id session['token'] = token session['signin_party'] = 'google' return 'True'
def load_user(userid): user = User() user.id = userid return user