示例#1
0
def UserLogin(request, facebook_token):
    """
    :param request: request object
    :param facebook_token: user facebook token
    :return: json with user data
    """
    # Get and save user data
    url = 'https://graph.facebook.com/me?access_token={0}'.format(facebook_token)
    profile_json = requests.get(url + '&fields=email,first_name,last_name').json()
    # Is user already logged in?
    if not 'facebook_id' in request.session:
        user = User.all().filter('email', profile_json['email'])
        if not user.count() > 0:
            user = User(
                first_name=profile_json['first_name'],
                last_name=profile_json['last_name'],
                email=profile_json['email'],
                facebook_token=facebook_token,
                facebook_id=profile_json['id']
            )
            user.put()
            logging.info('New user with facebook id: {0}'.format(user.facebook_id))
        else:
            user = user.get()
            logging.info('User logged in with facebook id: {0}'.format(user.facebook_id))
        request.session['facebook_id'] = user.facebook_id
    else:
        logging.info('User already logged in with facebook id: {0}'.format(request.session['facebook_id']))
    return HttpResponse(json.dumps(request.session['facebook_id']))
示例#2
0
 def get(self, request, *args, **kwargs):
     """
     :return: json
     """
     user = User.all().filter('facebook_id', request.session['facebook_id']).get()
     url = 'https://graph.facebook.com/me/friends?access_token={0}'.format(user.facebook_token)
     friends_json = requests.get(url + '&fields=first_name,last_name').json()['data']
     friends = []
     for friend in friends_json:
         if User.all().filter('facebook_id', friend['id']).count() > 0:
             # Create user json and save friend to list
             friend = User.all().filter('facebook_id', friend['id']).get()
             friend = create_user_json(friend)
             friends.append(friend)
     return HttpResponse(json.dumps(friends), content_type="application/json")
示例#3
0
 def get(self, request, *args, **kwargs):
     """
     :return: json
     """
     user = User.all().filter('facebook_id',
                              request.session['facebook_id']).get()
     url = 'https://graph.facebook.com/me/friends?access_token={0}'.format(
         user.facebook_token)
     friends_json = requests.get(
         url + '&fields=first_name,last_name').json()['data']
     friends = []
     for friend in friends_json:
         if User.all().filter('facebook_id', friend['id']).count() > 0:
             # Create user json and save friend to list
             friend = User.all().filter('facebook_id', friend['id']).get()
             friend = create_user_json(friend)
             friends.append(friend)
     return HttpResponse(json.dumps(friends),
                         content_type="application/json")
示例#4
0
 def get(self, request, *args, **kwargs):
     """
     :return: json
     """
     # for point in Point.all():
     #     db.delete(point.key())
     # for journey in Journey.all():
     #     db.delete(journey.key())
     # del request.session['facebook_id']
     user = User.all().filter('facebook_id', request.session['facebook_id']).get()
     user_json = create_user_json(user)
     return HttpResponse(json.dumps(user_json), content_type="application/json")
示例#5
0
def UserLogin(request, facebook_token):
    """
    :param request: request object
    :param facebook_token: user facebook token
    :return: json with user data
    """
    # Get and save user data
    url = 'https://graph.facebook.com/me?access_token={0}'.format(
        facebook_token)
    profile_json = requests.get(url +
                                '&fields=email,first_name,last_name').json()
    # Is user already logged in?
    if not 'facebook_id' in request.session:
        user = User.all().filter('email', profile_json['email'])
        if not user.count() > 0:
            user = User(first_name=profile_json['first_name'],
                        last_name=profile_json['last_name'],
                        email=profile_json['email'],
                        facebook_token=facebook_token,
                        facebook_id=profile_json['id'])
            user.put()
            logging.info('New user with facebook id: {0}'.format(
                user.facebook_id))
        else:
            user = user.get()
            logging.info('User logged in with facebook id: {0}'.format(
                user.facebook_id))
        request.session['facebook_id'] = user.facebook_id
    else:
        logging.info('User already logged in with facebook id: {0}'.format(
            request.session['facebook_id']))
    return HttpResponse(json.dumps(request.session['facebook_id']))
示例#6
0
 def get(self, request, *args, **kwargs):
     """
     :return: json
     """
     # for point in Point.all():
     #     db.delete(point.key())
     # for journey in Journey.all():
     #     db.delete(journey.key())
     # del request.session['facebook_id']
     user = User.all().filter('facebook_id',
                              request.session['facebook_id']).get()
     user_json = create_user_json(user)
     return HttpResponse(json.dumps(user_json),
                         content_type="application/json")