def handle_facebook_login(self): access_token = self.request.get('access_token') user_id = self.request.get('user_id') profile_url = 'https://graph.facebook.com/me?access_token=%s' profile = json.loads(urlfetch.fetch(profile_url%access_token).content) logging.info('Facebook Login:: ') logging.info(profile) id = profile['id'] if not id == user_id: response = {"success": False, "error": "Facebook ids don't match."} else: if 'email' in profile: email = profile['email'] else: email = id user = User.get_by_key_name(email) device_token = self.request.get('token_hex') if not user: user = User.create(email, profile['first_name'], profile['last_name'], device_token) ThirdPartyUser.create('FB', user, access_token, id) profile_picture = self.get_profile_picture(id) User.update(email, profile_picture=profile_picture, device_token=device_token) else: User.update(email, device_token=device_token) util.set_session(email) response = {"success": True, "email": email, "first_name": user.first_name, "last_name": user.last_name} return response
def save_user(self, access_token, company_id, user_id): key_name = self.network + util.separator + str( company_id) + util.separator + str(user_id) tp_user = ThirdPartyUser(key_name=key_name, access_token=access_token[0], access_token_secret=access_token[1]) tp_user.put() return tp_user
def pull_data_for(member): for network, handler in networks.iteritems(): key_name = network + separator + str( member.parent().key().id()) + separator + str(member.user_id) third_party_user = ThirdPartyUser.get_by_key_name(key_name) if third_party_user: handler.pull_data(member, third_party_user)
def fetch_and_save_github_user(access_token): email = users.get_current_user().email() user = User.get_by_key_name(email) response = json.loads( urlfetch.fetch(github.USER_URL % access_token).content) id, followers = response['login'], response['followers'] ThirdPartyUser(key_name=GITHUB, parent=user, access_token=access_token, id=id, followers=followers).put()
def fetch_and_save_github_user(access_token): response = json.loads(urlfetch.fetch(github.USER_EMAILS_URL%access_token).content) for email in response: if email['primary']: logging.info(email['email']) user = User.get_by_key_name(email['email']) if not user: user = User(key_name=email['email']) user.put() response = json.loads(urlfetch.fetch(github.USER_URL%access_token).content) id, followers = response['login'], response['followers'] ThirdPartyUser(key_name=GITHUB, parent=user, access_token=access_token, id=id, followers=followers).put()
def handle_custom_login(self): email = self.request.get('email') password = self.request.get('password') logging.info('Custom Login:: ') logging.info(email) user = User.get_by_key_name(email) if user and ThirdPartyUser.for_user(user).count() > 0: response = {"success": False, "error": "You have previously logged in with Facebook. Please log in using Facebook."} return response device_token = self.request.get('token_hex') if user and self.check_password(email, password): User.update(email, device_token=device_token) util.set_session(email) response = {"success": True, "email": email, "first_name": user.first_name, "last_name": user.last_name} else: response = {"success": False, "error": "The email or password you entered is incorrect."} return response
def setup(): user_1 = User.create('email1', 'firstname1', 'lastname1', 'password1') tp_user_1 = ThirdPartyUser(key_name='FB', parent=user_1) tp_user_1.network_id = '359059317608175' tp_user_1.put() user_2 = User.create('email2', 'firstname2', 'lasstname2', 'password2') tp_user_2 = ThirdPartyUser(key_name='FB', parent=user_2) tp_user_2.network_id = '359059317608175' tp_user_2.put() bout_1 = Bout.create(user_1, 'bout1', 'desc1', 1, 1) util.schedule_end(bout_1) photo_1 = Photo.create(bout_1, user_1, 'image_blob_key_1') photo_2 = Photo.create(bout_1, user_2, 'image_blob_key_2') bout_2 = Bout.create(user_2, 'bout2', 'desc2', 1, 2) util.schedule_end(bout_2) Vote.create('email1', photo_1) Vote.create('email2', photo_1) Vote.create('email2', photo_2) #photo_add, photo_vote, comment_add, winner, invited Notification.create('photo_add', bout_1.owner, user_2.email, bout_1) Notification.create('photo_vote', bout_1.owner, user_2.email, bout_1) Notification.create('comment_add', bout_1.owner, user_2.email, bout_1) Notification.create('winner', user_1, user_2.email, bout_1) Notification.create('invited', user_1, user_2.email, bout_1) #Winner.create(user_1, bout_1) Comment(parent=photo_1, user=user_1, message='message1', timestamp=datetime.datetime.now()).put() Comment(parent=photo_1, user=user_2, message='message2', timestamp=datetime.datetime.now()).put() Comment(parent=photo_2, user=user_1, message='message3', timestamp=datetime.datetime.now()).put() Comment(parent=photo_2, user=user_1, message='message4', timestamp=datetime.datetime.now()).put() Comment(parent=photo_2, user=user_2, message='message5', timestamp=datetime.datetime.now()).put() Comment(parent=photo_2, user=user_1, message='message6', timestamp=datetime.datetime.now()).put() Comment(parent=photo_2, user=user_2, message='message7', timestamp=datetime.datetime.now()).put() Comment(parent=photo_2, user=user_2, message='message8', timestamp=datetime.datetime.now()).put() Comment(parent=photo_2, user=user_2, message='message9', timestamp=datetime.datetime.now()).put() Follower.create('email1', user_2) Following.create(user_1, 'email2')
def fetch_and_save_linkedin_user(access_token): email = users.get_current_user().email() user = User.get_by_key_name(email) ThirdPartyUser(key_name=LINKEDIN, parent=user, access_token=access_token).put()
def fetch_and_save_dribbble_user(access_token): email = users.get_current_user().email() user = User.get_by_key_name(email) ThirdPartyUser(key_name=DRIBBBLE, parent=user, access_token=access_token).put()
def save_user(self, access_token, company_id, user_id): key_name = self.network + util.separator + str(company_id) + util.separator + str(user_id) tp_user = ThirdPartyUser(key_name=key_name, access_token=access_token[0], access_token_secret=access_token[1]) tp_user.put() return tp_user
def get(self): network = self.request.get('network') email = self.request.get('email') user = User.get_by_key_name(email) third_party_user = ThirdPartyUser.get_by_key_name(network, parent=user) networks[network].pull_data(user, third_party_user)
def create_user_search_document(user, save = True): other_names = _get_third_party_names(user) facebook_user = ThirdPartyUser.for_(user, 'FB') facebook_id = facebook_user.network_id if facebook_user else None return _create(user.email, user.name, facebook_id, other_names, should_save = save)
def _get_third_party_names(user): other_names = [] for third_party_user in ThirdPartyUser.for_user(user): if third_party_user.id != user.name: other_names.append(third_party_user.id) return other_names
def get(self): email = self.request.get('email') user = User.get_by_key_name(email) third_party_user = ThirdPartyUser.get_by_key_name(GITHUB, parent=user) github.pull_data(user, third_party_user)
def pull_data_for(member): for network, handler in networks.iteritems(): key_name = network + separator + str(member.parent().key().id()) + separator + str(member.user_id) third_party_user = ThirdPartyUser.get_by_key_name(key_name) if third_party_user: handler.pull_data(member, third_party_user)