def find_or_create_google_user(google_user_id, openid=None): user = db.session.query(Account).join(AccountGoogle).\ filter(AccountGoogle.google_user_id == google_user_id).first() if user is not None: return user if openid is not None: user = db.session.query(Account).join(AccountOpenID).\ filter(AccountOpenID.openid == openid).first() if user is not None: db.session.query(AccountOpenID).\ filter(AccountOpenID.openid == openid).delete() logger.info("Migrated OpenID user %s to Google user %s", openid, google_user_id) if user is None: user = Account() user.name = 'Google Account' user.apikey = generate_api_key() user.submission_count = 0 db.session.add(user) db.session.flush() logger.info("Created user %s (%s)", user.id, user.name) google_user = AccountGoogle() google_user.account = user google_user.google_user_id = google_user_id db.session.add(google_user) logger.info("Associated user %s (%s) with Google user %s", user.id, user.name, google_user_id) return user
def find_or_create_musicbrainz_user(mb_user_name): user = db.session.query(Account).filter_by(mbuser=mb_user_name).first() if user is not None: return user user = Account() user.name = mb_user_name user.mbuser = mb_user_name user.apikey = generate_api_key() user.submission_count = 0 db.session.add(user) db.session.flush() return user