def create_account(db_session, email_address, response): try: account = db_session.query(ImapAccount).filter_by( email_address=email_address).one() except sqlalchemy.orm.exc.NoResultFound: user = User() namespace = Namespace() account = ImapAccount(user=user, namespace=namespace) account.provider = 'Gmail' account.imap_host = IMAP_HOST account.email_address = response['email'] account.o_token_issued_to = response['issued_to'] account.o_user_id = response['user_id'] account.o_access_token = response['access_token'] account.o_id_token = response['id_token'] account.o_expires_in = response['expires_in'] account.o_access_type = response['access_type'] account.o_token_type = response['token_type'] account.o_audience = response['audience'] account.o_scope = response['scope'] account.o_email = response['email'] account.o_refresh_token = response['refresh_token'] account.o_verified_email = response['verified_email'] account.date = datetime.datetime.utcnow() if 'given_name' in response: account.given_name = response['given_name'] if 'family_name' in response: account.family_name = response['family_name'] if 'locale' in response: account.g_locale = response['locale'] if 'locale' in response: account.picture = response['picture'] if 'gender' in response: account.g_gender = response['gender'] if 'link' in response: account.g_plus_url = response['link'] if 'id' in response: account.google_id = response['id'] return account
def create_account(db_session, email_address, response): try: account = db_session.query(ImapAccount).filter_by( email_address=email_address).one() except sqlalchemy.orm.exc.NoResultFound: namespace = Namespace() account = ImapAccount(namespace=namespace) account.provider = 'Gmail' account.provider_prefix = PROVIDER_PREFIX account.imap_host = IMAP_HOST account.email_address = response['email'] account.o_token_issued_to = response['issued_to'] account.o_user_id = response['user_id'] account.o_access_token = response['access_token'] account.o_id_token = response['id_token'] account.o_expires_in = response['expires_in'] account.o_access_type = response['access_type'] account.o_token_type = response['token_type'] account.o_audience = response['audience'] account.o_scope = response['scope'] account.o_email = response['email'] account.o_refresh_token = response['refresh_token'] account.o_verified_email = response['verified_email'] account.date = datetime.datetime.utcnow() if 'given_name' in response: account.given_name = response['given_name'] if 'family_name' in response: account.family_name = response['family_name'] if 'locale' in response: account.g_locale = response['locale'] if 'locale' in response: account.picture = response['picture'] if 'gender' in response: account.g_gender = response['gender'] if 'link' in response: account.g_plus_url = response['link'] if 'id' in response: account.google_id = response['id'] return account