def facebook_authorized(resp): next_url = request.args.get('next') or url_for('index') if resp is None or 'access_token' not in resp: return redirect(next_url) session['logged_in'] = True session['facebook_token'] = (resp['access_token'], '') # Make use of the connection to retrieves the user's info profile = facebook.get('/me').data profile_id = profile['id'].decode('utf-8') user_entry = ndb.Key('User', profile_id).get() if not user_entry: friends = facebook.get('/me/friends').data add_user(profile, friends) # Add new token to the user entry user = User.get_by_id(profile_id) user.token = resp['access_token'] user.put() session['profile_id'] = profile['id'].decode('utf-8') return redirect('/#/friends')
def post(self): new_email = self.request.get('email') new_account_enabled = True if self.request.get( 'accountEnabled') == 'on' else False new_report_enabled = True if self.request.get( 'reportEnabled') == 'on' else False new_is_admin = True if self.request.get('isAdmin') == 'on' else False new_description = self.request.get('description') auth_id = 'google:%s' % new_email data_user = User.get_by_id(auth_id) if data_user: params = {} params.update(ndb_user=data_user, error_message='account exist') self.render('account/account_management_new.html', **params) return else: user = User.get_or_insert(auth_id) if user: user.email = new_email user.account_enabled = new_account_enabled user.report_enabled = new_report_enabled user.is_admin = new_is_admin user.description = new_description user.put() self.redirect('/account_management')
def test_friends_updated(self, mocked_graph): mocked_graph.return_value.get_object.return_value = {'id': '42'} mocked_graph.return_value.get_connections.return_value = {'data': []} user = User(id='42', name='Foo Bar', token='101010') user.put() User(id='43', name='Knuth Donald', token='101010').put() update_friendlists(user) knuth = User.get_by_id('43') self.assertEqual(len(knuth.friends), 0) mocked_graph.return_value.get_connections.return_value = {'data': [{ 'id': '43', 'name': 'Knuth Donald' }]} update_friendlists(user) knuth = User.get_by_id('43') self.assertEqual(len(knuth.friends), 1) self.assertEqual(knuth.friends[0], user.key)
def get(self): profile_id = request.args.get("profile_id") if not profile_id and not session.get("profile_id"): return Response("No profile specified. Please specify profile_id", status=400) profile_id = profile_id or session.get("profile_id") user = User.get_by_id(profile_id) if not user: return Response("No profile '{}' found. Please specify profile_id".format(profile_id), status=400) data = {"friends": [{"name": f.name} for f in ndb.get_multi(user.friends)]} data["count"] = len(data["friends"]) return Response(json.dumps(data), status=200)
def post(self): data = request.get_json(silent=True, force=True) if not data: return Response(status=400) # Only one permission is hooked entry = data['entry'][0] profile_id = entry['uid'] new_friend = User.get_by_id(profile_id) if entry['changed_fields'][0] == 'user_friends': # Add current user to his friends friend lists update_friendlists(new_friend) return Response(status=200)
def post(self): data = request.get_json(silent=True, force=True) if not data: return Response(status=400) # Only one permission is hooked entry = data["entry"][0] profile_id = entry["uid"] new_friend = User.get_by_id(profile_id) if entry["changed_fields"][0] == "user_friends": # Add current user to his friends friend lists update_friendlists(new_friend) return Response(status=200)
def get(self): profile_id = request.args.get('profile_id') if not profile_id and not session.get('profile_id'): return Response('No profile specified. Please specify profile_id', status=400) profile_id = profile_id or session.get('profile_id') user = User.get_by_id(profile_id) if not user: return Response( 'No profile \'{}\' found. Please specify profile_id'.format( profile_id), status=400) data = { 'friends': [{ 'name': f.name } for f in ndb.get_multi(user.friends)] } data['count'] = len(data['friends']) return Response(json.dumps(data), status=200)