def get(self): current_session = get_current_session() if current_session.get(SessionKind.SESSION_ID_KEY) is None: current_session[SessionKind.SESSION_ID_KEY] = uuid.uuid1().get_hex() session_id = current_session.get(SessionKind.SESSION_ID_KEY) session_kind_gql = SessionKind.SessionKind.gql("WHERE sessionId = :1", [session_id]) session_entity = session_kind_gql.get() if session_entity is not None: session_entity = SessionKind() session_entity.sessionId = session_id session_entity.put() current_user = users.get_current_user() if current_user is not None: google_user_identifier = current_user.user_id() google_user_nickname = current_user.nickname() google_user_email = current_user.email() obomb_user_kind_gql = ObombUserKind.gql("WHERE googleUserIdentifier = :1", [current_user.user_id()]) obomb_user_entities = obomb_user_kind_gql.fetch(1000) number_of_obomb_user_entities = len(obomb_user_entities) if number_of_obomb_user_entities == 0: obomb_user_entity = ObombUserKind() obomb_user_entity.googleUserIdentifier = current_user.user_id() obomb_user_entity.put() obomb_user_entities = [obomb_user_entity] else: number_of_obomb_user_entities = 0 google_user_identifier = None google_user_nickname = None google_user_email = None template_values = { 'session_id' : current_session.get(SessionKind.SESSION_ID_KEY), 'google_login_url' : users.create_login_url("/login/google"), 'google_logout_url' : users.create_logout_url("/login/google"), 'google_user_nickname' : google_user_nickname, 'google_user_email' : google_user_email, 'google_user_identifier': google_user_identifier, 'number_of_obomb_user_entities': number_of_obomb_user_entities } path = os.path.join(os.path.dirname(__file__), 'google.djhtml') self.response.out.write(template.render(path, template_values))
def get(self): current_session = get_current_session() if current_session.get(SessionKind.SESSION_ID_KEY) is None: current_session[SessionKind.SESSION_ID_KEY] = uuid.uuid1().get_hex() session_id = current_session.get(SessionKind.SESSION_ID_KEY) session_kind_gql = SessionKind.SessionKind.gql("WHERE sessionId = :1", [session_id]) session_entity = session_kind_gql.get() if session_entity is None: session_entity = SessionKind.SessionKind() session_entity.sessionId = session_id session_entity.put() assert session_entity is not None obomb_user_entity = session_entity.obombUserEntity if obomb_user_entity is None: obomb_user_entity = ObombUserKind() twitter_user_entity = obomb_user_entity.twitterUserEntity if twitter_user_entity is None: twitter_user_entity = TwitterUserKind() else: template_values = { 'session_id' : current_session.get(SessionKind.SESSION_ID_KEY), 'access_token' : twitter_user_entity.accessToken, 'screen_name' : twitter_user_entity.screenName, 'integer_id' : twitter_user_entity.integerId, 'verification_error': None } path = os.path.join(os.path.dirname(__file__), 'twitter.djhtml') self.response.out.write(template.render(path, template_values)) return if current_session.get("twitter_authorizing") is True: access_token = self.request.get("oauth_access_token") current_session["twitter_authorizing"] = False verification_result = urlfetch.fetch("https://api.twitter.com/1/account/verify_credentials.json?oauth_access_token=" + access_token) if verification_result.status_code != 200: template_values = { 'session_id' : current_session.get(SessionKind.SESSION_ID_KEY), 'access_token' : access_token, 'screen_name' : None, 'integer_id' : None, 'verification_error': True } path = os.path.join(os.path.dirname(__file__), 'twitter.djhtml') self.response.out.write(template.render(path, template_values)) return verify_credentials = json.loads(verification_result.content) logging.debug(verify_credentials) integer_id = verify_credentials["id"] screen_name = verify_credentials["screen_name"] if integer_id is None or screen_name is None: template_values = { 'session_id' : current_session.get(SessionKind.SESSION_ID_KEY), 'access_token' : access_token, 'screen_name' : None, 'integer_id' : None, 'verification_error': True } path = os.path.join(os.path.dirname(__file__), 'twitter.djhtml') self.response.out.write(template.render(path, template_values)) return twitter_user_entity.integerId = integer_id twitter_user_entity.screenName = screen_name twitter_user_entity.accessToken = access_token twitter_user_entity.put() obomb_user_entity.twitterUserEntity = twitter_user_entity obomb_user_entity.put() template_values = { 'session_id' : current_session.get(SessionKind.SESSION_ID_KEY), 'access_token' : access_token, 'screen_name' : screen_name, 'integer_id' : integer_id, 'verification_error' : False } path = os.path.join(os.path.dirname(__file__), 'twitter.djhtml') self.response.out.write(template.render(path, template_values)) return current_session["twitter_authorizing"] = True self.redirect("https://oauth.twitter.com/2/authorize?" + urlencode([("oauth_callback_url", "https://obomb-web.appspot.com/login/twitter"), ("oauth_mode", "flow_web_client"), ("oauth_client_identifier", login.credentials.TWITTER_CONSUMER_KEY)])) return
def get(self): current_session = get_current_session() if current_session.get(SessionKind.SESSION_ID_KEY) is None: current_session[ SessionKind.SESSION_ID_KEY] = uuid.uuid1().get_hex() session_id = current_session.get(SessionKind.SESSION_ID_KEY) session_kind_gql = SessionKind.SessionKind.gql("WHERE sessionId = :1", [session_id]) session_entity = session_kind_gql.get() if session_entity is None: session_entity = SessionKind.SessionKind() session_entity.sessionId = session_id session_entity.put() assert session_entity is not None obomb_user_entity = session_entity.obombUserEntity if obomb_user_entity is None: obomb_user_entity = ObombUserKind() twitter_user_entity = obomb_user_entity.twitterUserEntity if twitter_user_entity is None: twitter_user_entity = TwitterUserKind() else: template_values = { 'session_id': current_session.get(SessionKind.SESSION_ID_KEY), 'access_token': twitter_user_entity.accessToken, 'screen_name': twitter_user_entity.screenName, 'integer_id': twitter_user_entity.integerId, 'verification_error': None } path = os.path.join(os.path.dirname(__file__), 'twitter.djhtml') self.response.out.write(template.render(path, template_values)) return if current_session.get("twitter_authorizing") is True: access_token = self.request.get("oauth_access_token") current_session["twitter_authorizing"] = False verification_result = urlfetch.fetch( "https://api.twitter.com/1/account/verify_credentials.json?oauth_access_token=" + access_token) if verification_result.status_code != 200: template_values = { 'session_id': current_session.get(SessionKind.SESSION_ID_KEY), 'access_token': access_token, 'screen_name': None, 'integer_id': None, 'verification_error': True } path = os.path.join(os.path.dirname(__file__), 'twitter.djhtml') self.response.out.write(template.render(path, template_values)) return verify_credentials = json.loads(verification_result.content) logging.debug(verify_credentials) integer_id = verify_credentials["id"] screen_name = verify_credentials["screen_name"] if integer_id is None or screen_name is None: template_values = { 'session_id': current_session.get(SessionKind.SESSION_ID_KEY), 'access_token': access_token, 'screen_name': None, 'integer_id': None, 'verification_error': True } path = os.path.join(os.path.dirname(__file__), 'twitter.djhtml') self.response.out.write(template.render(path, template_values)) return twitter_user_entity.integerId = integer_id twitter_user_entity.screenName = screen_name twitter_user_entity.accessToken = access_token twitter_user_entity.put() obomb_user_entity.twitterUserEntity = twitter_user_entity obomb_user_entity.put() template_values = { 'session_id': current_session.get(SessionKind.SESSION_ID_KEY), 'access_token': access_token, 'screen_name': screen_name, 'integer_id': integer_id, 'verification_error': False } path = os.path.join(os.path.dirname(__file__), 'twitter.djhtml') self.response.out.write(template.render(path, template_values)) return current_session["twitter_authorizing"] = True self.redirect("https://oauth.twitter.com/2/authorize?" + urlencode([("oauth_callback_url", "https://obomb-web.appspot.com/login/twitter" ), ("oauth_mode", "flow_web_client"), ("oauth_client_identifier", login.credentials.TWITTER_CONSUMER_KEY)])) return