def facebookLogin(request): """ :param request: :return: """ response = dict() device = request.REQUEST['device'] facebookAuthKey = request.REQUEST['fbauthkey'] lat = request.REQUEST.get('lat', None) lng = request.REQUEST.get('lng', None) if device != 'ios' and device != 'android': return errorResponse('Invalid device: ' + device) try: facebookProfile, newUser = FacebookProfile.getFacebookUserFromAuthKey(facebookAuthKey, device) userProfile = facebookProfile.userProfile except facebook.GraphAPIError: return errorResponse("Invalid Facebook AUTH Key") response['friends'] = [] facebookFriends = facebookProfile.getFacebookFriends() blockedFriends = userProfile.blockedFriends.all() for friend in facebookFriends: blocked = False if friend in blockedFriends: blocked = True friendData = getUserProfileDetailsJson(friend) response['friends'].append(friendData) # Check all buddyup friends and add them if they weren't already included in facebook friends check friends = userProfile.friends.all() for friend in friends: if friend not in facebookFriends: blocked = False if friend in blockedFriends: blocked = True friendData = getUserProfileDetailsJson(friend) response['friends'].append(friendData) statusesResponse, newSince = getNewStatusesJsonResponse(userProfile, None, lat, lng) myStatusesResponse = getMyStatusesJsonResponse(userProfile) settings = getSettingsData(userProfile) newSince = datetime.now().strftime(MICROSECOND_DATETIME_FORMAT) notifications = getNotificationsJson(userProfile) chatData = getNewChatsData(userProfile) if newUser: createFriendJoinedNotification(userProfile) Group.objects.create(name="Favorites", user=userProfile) groupsData = getMyGroupsJsonResponse(userProfile) response['success'] = True response['firstname'] = userProfile.user.first_name response['lastname'] = userProfile.user.last_name response['userid'] = userProfile.id response['facebookid'] = userProfile.facebookUID response['statuses'] = statusesResponse response['groups'] = groupsData response['mystatuses'] = myStatusesResponse response['chats'] = chatData response['newsince'] = newSince response['settings'] = settings response['notifications'] = notifications response['favoritesnotifications'] = userProfile.favoritesNotifications return HttpResponse(json.dumps(response))