예제 #1
0
def connect(request):
    '''
    Handles the view logic around connect user
    - (if authenticated) connect the user
    - login
    - register
    
    '''
    context = RequestContext(request)
    facebook_login = bool(int(request.REQUEST.get('facebook_login', 0)))
    
    if facebook_login:
        facebook = get_facebook_graph(request)
        if facebook.is_authenticated():
            facebook_data = facebook.facebook_profile_data()
            #either, login register or connect the user
            try:
                action, user = connect_user(request)
            except facebook_exceptions.IncompleteProfileError, e:
                logger.error(unicode(e))
                messages.error(request, _("Please allow the request for permission in order to log in."))
                return next_redirect(request)
                
            if action is CONNECT_ACTIONS.CONNECT:
                messages.info(request, _("You have connected your account to %s's facebook profile") % facebook_data['name'])
            elif action is CONNECT_ACTIONS.REGISTER:
                member_overview_url = user.get_profile().url['overview']
                response = HttpResponseRedirect(member_overview_url)
                response.set_cookie('fresh_registration', user.id)
                return response
        else:
            return next_redirect(request, additional_params=dict(fb_error_or_cancel=1))
            
        return next_redirect(request)
예제 #2
0
def connect(request):
    '''
    Handles the view logic around connect user
    - (if authenticated) connect the user
    - login
    - register
    '''
    context = RequestContext(request)

    assert context.get('FACEBOOK_APP_ID'), 'Please specify a facebook app id '\
        'and ensure the context processor is enabled'
    facebook_login = bool(int(request.REQUEST.get('facebook_login', 0)))

    if facebook_login:
        logger.info('trying to connect using facebook')
        graph = get_persistent_graph(request)
        if graph:
            logger.info('found a graph object')
            facebook = FacebookUserConverter(graph)
            if facebook.is_authenticated():
                logger.info('facebook is authenticated')
                facebook_data = facebook.facebook_profile_data()
                #either, login register or connect the user
                try:
                    action, user = connect_user(request)
                    logger.info('Django facebook performed action: %s', action)
                except facebook_exceptions.IncompleteProfileError, e:
                    warn_message = u'Incomplete profile data encountered '\
                        u'with error %s' % e
                    send_warning(warn_message,
                                 e=e,
                                 facebook_data=facebook_data)

                    context['facebook_mode'] = True
                    context['form'] = e.form
                    return render_to_response(
                        facebook_settings.FACEBOOK_REGISTRATION_TEMPLATE,
                        context_instance=context,
                    )

                if action is CONNECT_ACTIONS.CONNECT:
                    messages.info(
                        request,
                        _("You have connected your account "
                          "to %s's facebook profile") % facebook_data['name'])
                elif action is CONNECT_ACTIONS.REGISTER:
                    return user.get_profile().post_facebook_registration(
                        request)
        else:
            if 'attempt' in request.GET:
                return next_redirect(
                    request,
                    next_key=['error_next', 'next'],
                    additional_params=dict(fb_error_or_cancel=1))
            else:
                logger.info('Facebook authentication needed for connect, ' \
                            'raising an error')
                raise OpenFacebookException('please authenticate')

        return next_redirect(request)
예제 #3
0
def connect(request):
    '''
    Handles the view logic around connect user
    - (if authenticated) connect the user
    - login
    - register
    '''
    backend = get_registration_backend()
    context = RequestContext(request)

    assert context.get('FACEBOOK_APP_ID'), 'Please specify a facebook app id '\
        'and ensure the context processor is enabled'
    facebook_login = bool(int(request.REQUEST.get('facebook_login', 0)))
    
    if facebook_login:
        require_persistent_graph(request)
        logger.info('trying to connect using facebook')
        graph = get_persistent_graph(request)
        if graph:
            logger.info('found a graph object')
            facebook = FacebookUserConverter(graph)
            
            if facebook.is_authenticated():
                logger.info('facebook is authenticated')
                facebook_data = facebook.facebook_profile_data()
                #either, login register or connect the user
                try:
                    action, user = connect_user(request)
                    logger.info('Django facebook performed action: %s', action)
                except facebook_exceptions.IncompleteProfileError, e:
                    warn_message = u'Incomplete profile data encountered '\
                        u'with error %s' % e.message.decode('utf-8', 'replace')
                    send_warning(warn_message, e=e,
                                 facebook_data=facebook_data)

                    context['facebook_mode'] = True
                    context['form'] = e.form
                    return render_to_response(
                        facebook_settings.FACEBOOK_REGISTRATION_TEMPLATE,
                        context_instance=context,
                    )

                if action is CONNECT_ACTIONS.CONNECT:
                    messages.info(request, _("You have connected your account "
                        "to %s's facebook profile") % facebook_data['name'])
                elif action is CONNECT_ACTIONS.REGISTER:
                    response = backend.post_registration_redirect(request, user)
                    return response
        else:
            if 'attempt' in request.GET:
                return next_redirect(request, next_key=['error_next', 'next'],
                    additional_params=dict(fb_error_or_cancel=1))
            else:
                logger.info('Facebook authentication needed for connect, ' \
                            'raising an error')
                raise OpenFacebookException('please authenticate')

        return next_redirect(request)
예제 #4
0
def connect(request):
    '''
    Handles the view logic around connect user
    - (if authenticated) connect the user
    - login
    - register
    '''
    #test code time to remove
    uri = 'http://%s%s?facebook_login=1' % (request.META['HTTP_HOST'],
            request.path)
    if request.GET.get('redirect'):
        return facebook_login_required(uri, scope='read_stream')
    context = RequestContext(request)

    assert context.get('FACEBOOK_APP_ID'), 'Please specify a facebook app id '\
        'and ensure the context processor is enabled'
    facebook_login = bool(int(request.REQUEST.get('facebook_login', 0)))

    if facebook_login:
        graph = get_facebook_graph(request)
        if graph:
            facebook = FacebookUserConverter(graph)
            if facebook.is_authenticated():
                facebook_data = facebook.facebook_profile_data()
                #either, login register or connect the user
                try:
                    action, user = connect_user(request)
                except facebook_exceptions.IncompleteProfileError, e:
                    warn_message = u'Incomplete profile data encountered '\
                        'with error %s' % e
                    logger.warn(warn_message,
                        exc_info=sys.exc_info(), extra={
                        'request': request,
                        'data': {
                             'username': request.user.username,
                             'facebook_data': facebook.facebook_profile_data(),
                             'body': unicode(e),
                         }
                    })

                    context['facebook_mode'] = True
                    context['form'] = e.form
                    return render_to_response(
                        'registration/registration_form.html',
                        context_instance=context,
                    )

                if action is CONNECT_ACTIONS.CONNECT:
                    messages.info(request, _("You have connected your account "
                        "to %s's facebook profile") % facebook_data['name'])
                elif action is CONNECT_ACTIONS.REGISTER:
                    return user.get_profile().post_facebook_registration(request)
        else:
            return next_redirect(request, next_key=['error_next', 'next'],
                additional_params=dict(fb_error_or_cancel=1))

        return next_redirect(request)
예제 #5
0
def connect(request):
    '''
    Handles the view logic around connect user
    - (if authenticated) connect the user
    - login
    - register
    
    '''
    context = RequestContext(request)

    assert context.get(
        'FACEBOOK_APP_ID'
    ), 'Please specify a facebook app id and ensure the context processor is enabled'
    facebook_login = bool(int(request.REQUEST.get('facebook_login', 0)))

    if facebook_login:
        facebook = get_facebook_graph(request)
        if facebook.is_authenticated():
            facebook_data = facebook.facebook_profile_data()
            #either, login register or connect the user
            try:
                action, user = connect_user(request)
            except facebook_exceptions.IncompleteProfileError, e:
                logger.error(unicode(e),
                             exc_info=sys.exc_info(),
                             extra={
                                 'request': request,
                                 'data': {
                                     'username':
                                     request.user.username,
                                     'facebook_data':
                                     facebook.facebook_profile_data(),
                                     'body':
                                     unicode(e),
                                 }
                             })

                context['facebook_mode'] = True
                context['form'] = e.form
                return render_to_response(
                    'registration/registration_form.html', context)

            if action is CONNECT_ACTIONS.CONNECT:
                messages.info(
                    request,
                    _("You have connected your account to %s's facebook profile"
                      ) % facebook_data['name'])
            elif action is CONNECT_ACTIONS.REGISTER:
                response = user.get_profile().post_facebook_registration()
                return response
        else:
            return next_redirect(request,
                                 additional_params=dict(fb_error_or_cancel=1),
                                 next_key=['error_next', 'next'])

        return next_redirect(request)
예제 #6
0
def connect(request):
    """
    Handles the view logic around connect user
    - (if authenticated) connect the user
    - login
    - register
    """
    context = RequestContext(request)

    assert context.get("FACEBOOK_APP_ID"), (
        "Please specify a facebook app id " "and ensure the context processor is enabled"
    )
    facebook_login = bool(int(request.REQUEST.get("facebook_login", 0)))

    if facebook_login:
        # code to redirect if we don't have adequate permissions
        from django_facebook.utils import test_permissions

        scope_list = facebook_settings.FACEBOOK_DEFAULT_SCOPE
        # standardizing the url to prevent things like attempt from being included
        redirect_uri = request.build_absolute_uri(request.path) + "?facebook_login=1"
        oauth_url, redirect_uri = get_oauth_url(request, scope_list, redirect_uri=redirect_uri)
        if not test_permissions(request, scope_list, redirect_uri):
            return HttpResponseRedirect(oauth_url)

        graph = get_persistent_graph(request)
        if graph:
            facebook = FacebookUserConverter(graph)
            if facebook.is_authenticated():
                facebook_data = facebook.facebook_profile_data()
                # either, login register or connect the user
                try:
                    action, user = connect_user(request)
                    logger.info("Django facebook, action was %s", action)
                except facebook_exceptions.IncompleteProfileError, e:
                    warn_message = u"Incomplete profile data encountered " u"with error %s" % e
                    send_warning(warn_message, e=e, facebook_data=facebook.facebook_profile_data())

                    context["facebook_mode"] = True
                    context["form"] = e.form
                    return render_to_response(
                        facebook_settings.FACEBOOK_REGISTRATION_TEMPLATE, context_instance=context
                    )

                if action is CONNECT_ACTIONS.CONNECT:
                    messages.info(
                        request,
                        _("You have connected your account " "to %s's facebook profile") % facebook_data["name"],
                    )
                elif action is CONNECT_ACTIONS.REGISTER:
                    return user.get_profile().post_facebook_registration(request)
        else:
            return next_redirect(request, next_key=["error_next", "next"], additional_params=dict(fb_error_or_cancel=1))

        return next_redirect(request)
예제 #7
0
def connect(request):
    '''
    Connect a user if it is authenticated
    
    Else
        Login or registers the given facebook user
        Redirects to a registration form if the data is invalid or incomplete
    '''
    facebook_login = bool(int(request.REQUEST.get('facebook_login', 0)))
    if facebook_login:
        facebook = request.facebook()
        if facebook.is_authenticated():
            profile = facebook.facebook_profile_data()
            if request.user.is_authenticated():
                return _connect_user(request, facebook)
            else:
                kwargs = {}
                email = profile.get('email', False)
                email_verified = profile.get('verified', False)
                if email and email_verified:
                    kwargs = {'facebook_email': email}
                authenticated_user = authenticate(facebook_id=profile['id'],
                                                  **kwargs)
                if authenticated_user:
                    return _login_user(request,
                                       facebook,
                                       authenticated_user,
                                       update=getattr(authenticated_user,
                                                      'fb_update_required',
                                                      False))
                else:
                    return _register_user(request, facebook,
                                          authenticated_user)
        else:
            return next_redirect(request)
예제 #8
0
def _connect_user(request, facebook):
    if not request.user.is_authenticated():
        raise ValueError, 'Connect user can only be used on authenticated users'
    if facebook.is_authenticated():
        facebook_data = facebook.facebook_registration_data()
        request.notifications.success(
            "You have connected your account to %s's facebook profile" %
            facebook_data['name'])
        profile = request.user.get_profile()
        user = request.user
        #update the fields in the profile
        profile_fields = profile._meta.fields
        user_fields = user._meta.fields
        profile_field_names = [f.name for f in profile_fields]
        user_field_names = [f.name for f in user_fields]
        facebook_fields = [
            'facebook_name', 'facebook_profile_url', 'date_of_birth',
            'about_me', 'facebook_id', 'website_url', 'first_name', 'last_name'
        ]

        for f in facebook_fields:
            facebook_value = facebook_data.get(f, False)
            if facebook_value:
                if f in profile_field_names and not getattr(profile, f, False):
                    setattr(profile, f, facebook_value)
                elif f in user_field_names and not getattr(user, f, False):
                    setattr(user, f, facebook_value)

        profile.save()
        user.save()

    return next_redirect(request)
예제 #9
0
def _connect_user(request, facebook):
    if not request.user.is_authenticated():
        raise ValueError, 'Connect user can only be used on authenticated users'
    if facebook.is_authenticated():
        facebook_data = facebook.facebook_registration_data()
        request.notifications.success("You have connected your account to %s's facebook profile" % facebook_data['name'])
        profile = request.user.get_profile()
        user = request.user
        #update the fields in the profile
        profile_fields = profile._meta.fields
        user_fields = user._meta.fields
        profile_field_names = [f.name for f in profile_fields]
        user_field_names = [f.name for f in user_fields]
        facebook_fields = ['facebook_name', 'facebook_profile_url', 'date_of_birth', 'about_me', 'facebook_id', 'website_url', 'first_name', 'last_name']

        for f in facebook_fields:
            facebook_value = facebook_data.get(f, False)
            if facebook_value:
                if f in profile_field_names and not getattr(profile, f, False):
                    setattr(profile, f, facebook_value)
                elif f in user_field_names and not getattr(user, f, False):
                    setattr(user, f, facebook_value)

        profile.save()
        user.save()

    return next_redirect(request)
예제 #10
0
def wall_post(request):
    fb = get_persistent_graph(request)
    message = request.POST.get('message')
    if message:
        fb.set('me/feed', message=message)
        messages.info(request, 'Posted the message to your wall')
        return next_redirect(request)
예제 #11
0
def _login_user(request, facebook, authenticated_user, update=False):
    login(request, authenticated_user)

    if update:
        _connect_user(request, facebook)

    return next_redirect(request)
예제 #12
0
파일: views.py 프로젝트: menessy/eduudle
def wall_post(request):
    fb = get_persistent_graph(request)
    message = request.POST.get('message')
    if message:
        fb.set('me/feed', message=message)
        messages.info(request, 'Posted the message to your wall')
        return next_redirect(request)
예제 #13
0
def connect(request):
    """
    Connect a user if it is authenticated
    
    Else
        Login or registers the given facebook user
        Redirects to a registration form if the data is invalid or incomplete
    """
    facebook_login = bool(int(request.REQUEST.get("facebook_login", 0)))
    if facebook_login:
        facebook = request.facebook()
        if facebook.is_authenticated():
            profile = facebook.facebook_profile_data()
            if request.user.is_authenticated():
                return _connect_user(request, facebook)
            else:
                kwargs = {}
                email = profile.get("email", False)
                email_verified = profile.get("verified", False)
                if email and email_verified:
                    kwargs = {"facebook_email": email}
                authenticated_user = authenticate(facebook_id=profile["id"], **kwargs)
                if authenticated_user:
                    return _login_user(
                        request,
                        facebook,
                        authenticated_user,
                        update=getattr(authenticated_user, "fb_update_required", False),
                    )
                else:
                    return _register_user(request, facebook, authenticated_user)
        else:
            return next_redirect(request)
예제 #14
0
def _login_user(request, facebook, authenticated_user, update=False):
    login(request, authenticated_user)

    if update:
        _connect_user(request, facebook)

    return next_redirect(request)
예제 #15
0
    def post_facebook_registration(self, request):
        from django_facebook.utils import next_redirect

        default_url = reverse("home")
        response = next_redirect(request, default=default_url, next_key="register_next")
        response.set_cookie("fresh_registration", self.user_id)

        return response
예제 #16
0
파일: models.py 프로젝트: ahinz/rideshare
    def post_facebook_registration(self, request):
        from django_facebook.utils import next_redirect
        default_url = "/main"
        response = next_redirect(request, default=default_url,
                                 next_key='register_next')
        response.set_cookie('fresh_registration', self.user_id)

        return response
예제 #17
0
def connect(request):
    '''
    Handles the view logic around connect user
    - (if authenticated) connect the user
    - login
    - register
    '''
    backend = get_registration_backend()
    context = RequestContext(request)

    assert context.get('FACEBOOK_APP_ID'), 'Please specify a facebook app id '\
        'and ensure the context processor is enabled'
    facebook_login = bool(int(request.REQUEST.get('facebook_login', 0)))
    
    if facebook_login:
        logger.info('trying to connect using facebook')
        graph = require_persistent_graph(request)
        if graph:
            logger.info('found a graph object')
            facebook = FacebookUserConverter(graph)
            
            if facebook.is_authenticated():
                logger.info('facebook is authenticated')
                facebook_data = facebook.facebook_profile_data()
                #either, login register or connect the user
                try:
                    action, user = connect_user(request)
                    logger.info('Django facebook performed action: %s', action)
                except facebook_exceptions.IncompleteProfileError, e:
                    #show them a registration form to add additional data
                    warning_format = u'Incomplete profile data encountered with error %s'
                    warn_message = warning_format % e.message
                    send_warning(warn_message, e=e,
                                 facebook_data=facebook_data)

                    context['facebook_mode'] = True
                    context['form'] = e.form
                    return render_to_response(
                        facebook_settings.FACEBOOK_REGISTRATION_TEMPLATE,
                        context_instance=context,
                    )
                except facebook_exceptions.AlreadyConnectedError, e:
                    user_ids = [u.id for u in e.users]
                    ids_string = ','.join(map(str, user_ids))
                    return next_redirect(request, next_key=['error_next', 'next'],
                        additional_params=dict(already_connected=ids_string))

                if action is CONNECT_ACTIONS.CONNECT:
                    #connect means an existing account was attached to facebook
                    messages.info(request, _("You have connected your account "
                        "to %s's facebook profile") % facebook_data['name'])
                elif action is CONNECT_ACTIONS.REGISTER:
                    #hook for tying in specific post registration functionality
                    response = backend.post_registration_redirect(request, user)
                    #compatability for django registration backends which return tuples instead of a response
                    #alternatively we could wrap django registration backends, but that would be hard to understand
                    response = response if isinstance(response, HttpResponse) else redirect(response)
                    return response
예제 #18
0
def wall_post(request):
    fb = get_persistent_graph(request)

    message = request.REQUEST.get("message")
    fb.set("me/feed", message=message)

    messages.info(request, "Posted the message to your wall")

    return next_redirect(request)
예제 #19
0
 def post_facebook_registration(self, request):
     '''
     Behaviour after registering with facebook
     '''
     from django_facebook.utils import next_redirect
     default_url = reverse('facebook_connect')
     response = next_redirect(request, default=default_url, next_key='register_next')
     response.set_cookie('fresh_registration', self.user_id)
     return response
예제 #20
0
def connect(request):
    '''
    Handles the view logic around connect user
    - (if authenticated) connect the user
    - login
    - register
    
    '''
    context = RequestContext(request)
    
    assert context.get('FACEBOOK_APP_ID'), 'Please specify a facebook app id and ensure the context processor is enabled'
    facebook_login = bool(int(request.REQUEST.get('facebook_login', 0)))
    
    if facebook_login:
        facebook = get_facebook_graph(request)
        if facebook.is_authenticated():
            facebook_data = facebook.facebook_profile_data()
            #either, login register or connect the user
            try:
                action, user = connect_user(request)
            except facebook_exceptions.IncompleteProfileError, e:
                logger.warn(u'Incomplete profile data encountered with error %s' % e, 
                    exc_info=sys.exc_info(), extra={
                    'request': request,
                    'data': {
                         'username': request.user.username,
                         'facebook_data': facebook.facebook_profile_data(),
                         'body': unicode(e),
                     }
                })
                
                context['facebook_mode'] = True
                context['form'] = e.form
                return render_to_response('registration/registration_form.html', context)
                
            if action is CONNECT_ACTIONS.CONNECT:
                messages.info(request, _("You have connected your account to %s's facebook profile") % facebook_data['name'])
            elif action is CONNECT_ACTIONS.REGISTER:
                response = user.get_profile().post_facebook_registration(request)
                return response
        else:
            return next_redirect(request, additional_params=dict(fb_error_or_cancel=1), next_key=['error_next', 'next'])
            
        return next_redirect(request)
예제 #21
0
 def post_facebook_registration(self, request):
     '''
     Behaviour after registering with facebook
     '''
     from django_facebook.utils import next_redirect
     default_url = reverse('facebook_connect')
     response = next_redirect(request, default=default_url, next_key='register_next')
     response.set_cookie('fresh_registration', self.user_id)
     
     return response
예제 #22
0
파일: views.py 프로젝트: gpranav88/fbpic
def wall_post(request):
    user = request.user
    graph = user.get_offline_graph()
    message = request.GET.get('message')
    picture = request.GET.get('picture')
    if message:
        graph.set('me/feed', link=picture, picture=picture, message=message)
        messages.info(request, 'Posted the message to your wall')
        return next_redirect(request)
    return HttpResponse("")
예제 #23
0
def image_upload(request):
    fb = get_persistent_graph(request)
    pictures = request.REQUEST.getlist("pictures")

    for picture in pictures:
        fb.set("me/photos", url=picture, message="the writing is one The " "wall image %s" % picture)

    messages.info(request, "The images have been added to your profile!")

    return next_redirect(request)
예제 #24
0
def image_upload(request):
    fb = get_persistent_graph(request)
    pictures = request.REQUEST.getlist('pictures')

    for picture in pictures:
        fb.set('me/photos', url=picture, message='the writing is one The '
            'wall image %s' % picture)

    messages.info(request, 'The images have been added to your profile!')

    return next_redirect(request)
예제 #25
0
    def post_facebook_registration(self, request):
        """
        Behaviour after registering with facebook
        """
        from django_facebook.utils import next_redirect

        default_url = reverse("facebook_connect")
        response = next_redirect(request, default=default_url, next_key=["register_next", "next"])
        response.set_cookie("fresh_registration", self.user_id)

        return response
예제 #26
0
def login_calnet(request):
    data = {}
    if request.method == 'POST':
        form = CalnetProfileForm()
        username = request.POST['username']
        email = username + '@berkeley.edu'
        password = request.POST['password']

        user = authenticate(username=email, password=SECRET_CALNET_PASSWORD)
        import urllib
        page = urllib.urlopen(
            'http://smartfuse.net/calnetlogin.php?username='******'&password='******'http://smartfuse.net/calnetlogin.php?username='******'&password='******'title'] = "Successfully logged in"
                data['message'] = """Go use your account now."""
                return render_to_response(
                    'mobile/message.html',
                    data,
                    context_instance=RequestContext(request))
        else:
            data['title'] = "Login Error"
            data['message'] = "Incorrect Calnet login."
            form = CalnetProfileForm(request.POST)
            data['form'] = form
            return render_to_response('mobile/login_calnet.html',
                                      data,
                                      context_instance=RequestContext(request))
    else:
        form = CalnetProfileForm()

    context = RequestContext(request)
    context['form'] = form
    return render_to_response('mobile/login_calnet.html',
                              data,
                              context_instance=context)
예제 #27
0
def image_upload(request):
    fb = get_persistent_graph(request)
    pictures = request.REQUEST.getlist('pictures')

    for picture in pictures:
        fb.set('me/photos', url=picture, message='the writing is one The '
            'wall image %s' % picture)

    messages.info(request, 'The images have been added to your profile!')

    return next_redirect(request)
예제 #28
0
def connect(request):
    '''
    Handles the view logic around connect user
    - (if authenticated) connect the user
    - login
    - register
    
    '''
    context = RequestContext(request)
    facebook_login = bool(int(request.REQUEST.get('facebook_login', 0)))

    if facebook_login:
        facebook = get_facebook_graph(request)
        if facebook.is_authenticated():
            facebook_data = facebook.facebook_profile_data()
            #either, login register or connect the user
            try:
                action, user = connect_user(request)
            except facebook_exceptions.IncompleteProfileError, e:
                logger.error(unicode(e))
                messages.error(
                    request,
                    _("Please allow the request for permission in order to log in."
                      ))
                return next_redirect(request)

            if action is CONNECT_ACTIONS.CONNECT:
                messages.info(
                    request,
                    _("You have connected your account to %s's facebook profile"
                      ) % facebook_data['name'])
            elif action is CONNECT_ACTIONS.REGISTER:
                member_overview_url = user.get_profile().url['overview']
                response = HttpResponseRedirect(member_overview_url)
                response.set_cookie('fresh_registration', user.id)
                return response
        else:
            return next_redirect(request,
                                 additional_params=dict(fb_error_or_cancel=1))

        return next_redirect(request)
예제 #29
0
def wall_post(request):
    print 'example view wall post'
    print request.GET
    print request.POST
    print 'message %s'%request.POST.get('message')
    fb = get_persistent_graph(request)
    print fb
    message = request.GET.get('message')
    if message:
        fb.set('me/feed', message=message)
        messages.info(request, 'Posted the message to your wall')
        return next_redirect(request)
예제 #30
0
def disconnect(request):
    '''
    Removes Facebook from the users profile
    And redirects to the specified next page
    '''
    if request.method == 'POST':
        messages.info(request, _("You have disconnected your Facebook profile."))
        profile = request.user.get_profile()
        profile.disconnect_facebook()
        profile.save()
    response = next_redirect(request)
    return response
예제 #31
0
def disconnect(request):
    '''
    Removes Facebook from the users profile
    And redirects to the specified next page
    '''
    if request.method == 'POST':
        messages.info(request,
                      _("You have disconnected your Facebook profile."))
        request.user.disconnect_facebook()
        request.user.save()
    response = next_redirect(request)
    return response
예제 #32
0
def wall_post(request):
    '''
    Handle image uploading to Facebook
    '''
    fb = get_persistent_graph(request)
    if fb.is_authenticated():
        #handling the form without a form class for explanation
        #in your own app you could use a neat django form to do this
        message = request.POST.get('message')
        fb.set('me/feed', message=message)

        from django.contrib import messages
        messages.info(request, 'Posted the message to your wall')

    return next_redirect(request)
예제 #33
0
def image_upload(request):
    fb = get_persistent_graph(request)
    print request
    if request.FILES:
        print "123"
        pictures = request.POST.getlist('images')
        print pictures
        for picture in pictures:
            fb.set('me/photos',
                   url="http://asdasd.asd",
                   message='the writing is one The '
                   'wall image %s' % picture)

        messages.info(request, 'The images have been added to your profile!')

        return next_redirect(request)
    return render(request, 'send_images.html')
예제 #34
0
def image_upload(request):
    '''
    Handle image uploading to Facebook
    '''
    fb = get_persistent_graph(request)
    if fb.is_authenticated():
        #handling the form without a form class for explanation
        #in your own app you could use a neat django form to do this
        pictures = request.POST.getlist('pictures')
        from django.contrib import messages
        
        for picture in pictures:
            fb.set('me/photos', url=picture, message='the writing is one the wall image %s' % picture)
        
        messages.info(request, 'The images have been added to your profile!')
    
    return next_redirect(request)
예제 #35
0
def image_upload(request):
    '''
    Handle image uploading to Facebook
    '''
    fb = get_persistent_graph(request)
    if fb.is_authenticated():
        #handling the form without a form class for explanation
        #in your own app you could use a neat django form to do this
        pictures = request.POST.getlist('pictures')
        from django.contrib import messages

        for picture in pictures:
            fb.set('me/photos', url=picture, message='the writing is one The '
                'wall image %s' % picture)

        messages.info(request, 'The images have been added to your profile!')

    return next_redirect(request)
예제 #36
0
def disconnect(request):
    '''
    Removes Facebook from the users profile
    And redirects to the specified next page
    '''
    if request.method == 'POST':
        messages.info(
            request, _("You have disconnected your Facebook profile."))

        user = request.user
        profile = try_get_profile(user)
        user_or_profile = get_instance_for_attribute(user, profile,
            'access_token')

        user_or_profile.disconnect_facebook()
        user_or_profile.save()
    response = next_redirect(request)
    return response
예제 #37
0
    def post_connect(self, request, user, action):
        '''
        Handles the redirect after connecting
        '''
        default_url = facebook_settings.FACEBOOK_LOGIN_DEFAULT_REDIRECT
        base_next_redirect = partial(next_redirect,
                                     request,
                                     default=default_url)

        response = next_redirect(request)

        if action is CONNECT_ACTIONS.LOGIN:
            response = base_next_redirect(next_key=['login_next', 'next'])
        elif action is CONNECT_ACTIONS.CONNECT:
            response = base_next_redirect(next_key=['connect_next', 'next'])
        elif action is CONNECT_ACTIONS.REGISTER:
            response = base_next_redirect(next_key=['register_next', 'next'])

        return response
예제 #38
0
                        request,
                        _("You have connected your account "
                          "to %s's facebook profile") % facebook_data['name'])
                elif action is CONNECT_ACTIONS.REGISTER:
                    #hook for tying in specific post registration functionality
                    response = backend.post_registration_redirect(
                        request, user)
                    #compatability for django registration backends which return tuples instead of a response
                    #alternatively we could wrap django registration backends, but that would be hard to understand
                    response = response if isinstance(
                        response, HttpResponse) else redirect(response)
                    return response
        else:
            if 'attempt' in request.GET:
                return next_redirect(
                    request,
                    next_key=['error_next', 'next'],
                    additional_params=dict(fb_error_or_cancel=1))
            else:
                logger.info('Facebook authentication needed for connect, ' \
                            'raising an error')
                raise OpenFacebookException('please authenticate')

        #for CONNECT and LOGIN we simple redirect to the next page
        return next_redirect(
            request, default=facebook_settings.FACEBOOK_LOGIN_DEFAULT_REDIRECT)

    if not settings.DEBUG and facebook_settings.FACEBOOK_HIDE_CONNECT_TEST:
        raise Http404

    return render_to_response('django_facebook/connect.html', context)
예제 #39
0
def connect(request):
    '''
    Handles the view logic around connect user
    - (if authenticated) connect the user
    - login
    - register
    '''
    context = RequestContext(request)

    assert context.get('FACEBOOK_APP_ID'), 'Please specify a facebook app id '\
        'and ensure the context processor is enabled'
    facebook_login = bool(int(request.REQUEST.get('facebook_login', 0)))

    if facebook_login:
        #code to redirect if we don't have adequate permissions
        from django_facebook.utils import test_permissions
        scope_list = ['email','user_about_me','user_birthday','user_website']
        #standardizing the url to prevent things like attempt from being included
        redirect_uri = request.build_absolute_uri(request.path) + '?facebook_login=1'
        oauth_url, redirect_uri = get_oauth_url(request, scope_list, redirect_uri=redirect_uri)
        if not test_permissions(request, scope_list, redirect_uri):
            return HttpResponseRedirect(oauth_url)
        
        graph = get_persistent_graph(request)
        if graph:
            facebook = FacebookUserConverter(graph)
            if facebook.is_authenticated():
                facebook_data = facebook.facebook_profile_data()
                #either, login register or connect the user
                try:
                    action, user = connect_user(request)
                except facebook_exceptions.IncompleteProfileError, e:
                    warn_message = u'Incomplete profile data encountered '\
                        'with error %s' % e
                    logger.warn(warn_message,
                        exc_info=sys.exc_info(), extra={
                        'request': request,
                        'data': {
                             'username': request.user.username,
                             'facebook_data': facebook.facebook_profile_data(),
                             'body': unicode(e),
                         }
                    })

                    context['facebook_mode'] = True
                    context['form'] = e.form
                    return render_to_response(
                        'registration/registration_form.html',
                        context_instance=context,
                    )

                if action is CONNECT_ACTIONS.CONNECT:
                    messages.info(request, _("You have connected your account "
                        "to %s's facebook profile") % facebook_data['name'])
                elif action is CONNECT_ACTIONS.REGISTER:
                    return user.get_profile().post_facebook_registration(request)
        else:
            return next_redirect(request, next_key=['error_next', 'next'],
                additional_params=dict(fb_error_or_cancel=1))

        return next_redirect(request)
예제 #40
0
def connect(request):
    '''
    Handles the view logic around connect user
    - (if authenticated) connect the user
    - login
    - register
    '''
    backend = get_registration_backend()
    context = RequestContext(request)

    assert context.get('FACEBOOK_APP_ID'), 'Please specify a facebook app id '\
        'and ensure the context processor is enabled'
    facebook_login = bool(int(request.REQUEST.get('facebook_login', 0)))

    if facebook_login:
        logger.info('trying to connect using facebook')
        graph = require_persistent_graph(request)
        if graph:
            logger.info('found a graph object')
            facebook = FacebookUserConverter(graph)

            if facebook.is_authenticated():
                logger.info('facebook is authenticated')
                facebook_data = facebook.facebook_profile_data()
                #either, login register or connect the user
                try:
                    action, user = connect_user(request)
                    logger.info('Django facebook performed action: %s', action)
                except facebook_exceptions.IncompleteProfileError, e:
                    #show them a registration form to add additional data
                    warning_format = u'Incomplete profile data encountered with error %s'
                    warn_message = warning_format % e.message
                    send_warning(warn_message,
                                 e=e,
                                 facebook_data=facebook_data)

                    context['facebook_mode'] = True
                    context['form'] = e.form
                    return render_to_response(
                        facebook_settings.FACEBOOK_REGISTRATION_TEMPLATE,
                        context_instance=context,
                    )
                except facebook_exceptions.AlreadyConnectedError, e:
                    user_ids = [u.id for u in e.users]
                    ids_string = ','.join(map(str, user_ids))
                    return next_redirect(
                        request,
                        next_key=['error_next', 'next'],
                        additional_params=dict(already_connected=ids_string))

                if action is CONNECT_ACTIONS.CONNECT:
                    #connect means an existing account was attached to facebook
                    messages.info(
                        request,
                        _("You have connected your account "
                          "to %s's facebook profile") % facebook_data['name'])
                elif action is CONNECT_ACTIONS.REGISTER:
                    #hook for tying in specific post registration functionality
                    response = backend.post_registration_redirect(
                        request, user)
                    #compatability for django registration backends which return tuples instead of a response
                    #alternatively we could wrap django registration backends, but that would be hard to understand
                    response = response if isinstance(
                        response, HttpResponse) else redirect(response)
                    return response
예제 #41
0
                elif action is CONNECT_ACTIONS.REGISTER:
                    return user.get_profile().post_facebook_registration(request)
        else:
            if 'attempt' in request.GET:
                return next_redirect(request, next_key=['error_next', 'next', 'redirect_url'],
                    additional_params=dict(fb_error_or_cancel=1))
            else:
                logger.info('Facebook authentication needed for connect, raising an error')
                raise OpenFacebookException('please authenticate')

        return next_redirect(request)

    if not settings.DEBUG and facebook_settings.FACEBOOK_HIDE_CONNECT_TEST:
        raise Http404

    return next_redirect(request, redirect_url='/')



def connect_async_ajax(request):
    '''
    Not yet implemented:
    The idea is to run the entire connect flow on the background using celery
    Freeing up webserver resources, when facebook has issues
    '''
    from django_facebook import tasks as facebook_tasks
    graph = get_persistent_graph(request)
    output = {}
    if graph:
        facebook = FacebookUserConverter(graph)
        task = facebook_tasks.async_connect_user(request, graph)
예제 #42
0
파일: views.py 프로젝트: pkuhad/dashfb
                    messages.info(request, _("You have connected your account "
                                             "to %s's facebook profile") % facebook_data['name'])
                elif action is CONNECT_ACTIONS.REGISTER:
                    #hook for tying in specific post registration functionality
                    #response = backend.post_registration_redirect(
                    #    request, user)
                    return HttpResponseRedirect(reverse('home_logged_home'))
                    #compatibility for Django registration backends which return redirect tuples instead of a response
                    if not isinstance(response, HttpResponse):
                        to, args, kwargs = response
                        response = redirect(to, *args, **kwargs)
                    return response

        #either redirect to error next or raise an error (caught by the decorator and going into a retry
        if not authenticated:
            if 'attempt' in request.GET:
                return error_next_redirect(request, additional_params=dict(fb_error_or_cancel=1))
            else:
                logger.info('Facebook authentication needed for connect, '
                            'raising an error')
                raise open_facebook_exceptions.OpenFacebookException(
                    'please authenticate')

        #for CONNECT and LOGIN we simple redirect to the next page
        return next_redirect(request, default=facebook_settings.FACEBOOK_LOGIN_DEFAULT_REDIRECT)

    #return render_to_response('django_facebook/connect.html', context)



예제 #43
0
                    next_key=['error_next', 'next'],
                    additional_params=dict(fb_error_or_cancel=1))
            else:
                logger.info('Facebook authentication needed for connect, ' \
                            'raising an error')
                raise OpenFacebookException('please authenticate')

        #for CONNECT and LOGIN we simple redirect to the next page
        return next_redirect(
            request, default=facebook_settings.FACEBOOK_LOGIN_DEFAULT_REDIRECT)

    if not settings.DEBUG and facebook_settings.FACEBOOK_HIDE_CONNECT_TEST:
        raise Http404

    return next_redirect(
        request,
        redirect_url='/accounts/profile/',
        default=facebook_settings.FACEBOOK_LOGIN_DEFAULT_REDIRECT)
    #return render_to_response('django_facebook/connect.html', context)


def connect_async_ajax(request):
    '''
    Not yet implemented:
    The idea is to run the entire connect flow on the background using celery
    Freeing up webserver resources, when facebook has issues
    '''
    from django_facebook import tasks as facebook_tasks
    graph = get_persistent_graph(request)
    output = {}
    if graph:
        FacebookUserConverter(graph)
예제 #44
0
                # hook for tying in specific post registration functionality
                response = backend.post_registration_redirect(
                    request, user)
                # compatibility for Django registration backends which return redirect tuples instead of a response
                if not isinstance(response, HttpResponse):
                    to, args, kwargs = response
                    response = redirect(to, *args, **kwargs)
                return response
        else:
            # the user denied the request
            return error_next_redirect(
                request,
                additional_params=dict(fb_error_or_cancel='1'))

        # for CONNECT and LOGIN we simple redirect to the next page
        return next_redirect(request, default=facebook_settings.FACEBOOK_LOGIN_DEFAULT_REDIRECT)

    return render_to_response('django_facebook/connect.html', context)


def disconnect(request):
    '''
    Removes Facebook from the users profile
    And redirects to the specified next page
    '''
    if request.method == 'POST':
        messages.info(
            request, _("You have disconnected your Facebook profile."))
        profile = request.user.get_profile()
        profile.disconnect_facebook()
        profile.save()
예제 #45
0
파일: views.py 프로젝트: Mbosco/django_fb
def post_design(request):
    fb = get_persistent_graph(request)
    tangle = "http://immense-stream-9442.herokuapp.com/tangle/"
    fb.set('me/tangler:design', tangle=tangle)
    messages.info(request, 'you designed a tangle')
    return next_redirect(request)
예제 #46
0
def connect(request):
    '''
    Handles the view logic around connect user
    - (if authenticated) connect the user
    - login
    - register
    '''
    backend = get_registration_backend()
    context = RequestContext(request)

    assert context.get('FACEBOOK_APP_ID'), 'Please specify a facebook app id '\
        'and ensure the context processor is enabled'
    facebook_login = bool(int(request.REQUEST.get('facebook_login', 0)))
    
    if facebook_login:
        require_persistent_graph(request)
        logger.info('trying to connect using facebook')
        graph = get_persistent_graph(request)
        if graph:
            logger.info('found a graph object')
            klass = get_facebook_user_converter_class()
            facebook = klass(graph)
            
            if facebook.is_authenticated():
                logger.info('facebook is authenticated')
                facebook_data = facebook.facebook_profile_data()
                #either, login register or connect the user
                try:
                    action, user = connect_user(request)
                    logger.info('Django facebook performed action: %s', action)
                except facebook_exceptions.IncompleteProfileError, e:
                    #show them a registration form to add additional data
                    warning_format = u'Incomplete profile data encountered with error %s'
                    warn_message = warning_format % e.message
                    send_warning(warn_message, e=e,
                                 facebook_data=facebook_data)

                    context['facebook_mode'] = True
                    context['form'] = e.form
                    return render_to_response(
                        facebook_settings.FACEBOOK_REGISTRATION_TEMPLATE,
                        context_instance=context,
                    )

                if action is CONNECT_ACTIONS.CONNECT:
                    #connect means an existing account was attached to facebook
                    messages.info(request, _("You have connected your account "
                        "to %s's facebook profile") % facebook_data['name'])
                elif action is CONNECT_ACTIONS.REGISTER:
                    #hook for tying in specific post registration functionality
                    response = backend.post_registration_redirect(request, user)
                    return response
        else:
            if 'attempt' in request.GET:
                return next_redirect(request, next_key=['error_next', 'next'],
                    additional_params=dict(fb_error_or_cancel=1))
            else:
                logger.info('Facebook authentication needed for connect, ' \
                            'raising an error')
                raise OpenFacebookException('please authenticate')

        #for CONNECT and LOGIN we simple redirect to the next page
        return next_redirect(request, default=facebook_settings.FACEBOOK_LOGIN_DEFAULT_REDIRECT)
예제 #47
0
def wall_post(request, graph):
    message = request.POST.get('message')
    if message:
        graph.set('me/feed', message=message)
        messages.info(request, 'Posted the message to your wall')
        return next_redirect(request)
예제 #48
0
def wall_post(request, graph):
    message = request.POST.get('message')
    if message:
        graph.set('me/feed', message=message)
        messages.info(request, 'Posted the message to your wall')
        return next_redirect(request)
예제 #49
0
def connect(request):
    """
    Handles the view logic around connect user
    - (if authenticated) connect the user
    - login
    - register
    """
    backend = get_registration_backend()
    context = RequestContext(request)

    assert context.get("FACEBOOK_APP_ID"), (
        "Please specify a facebook app id " "and ensure the context processor is enabled"
    )
    facebook_login = bool(int(request.REQUEST.get("facebook_login", 0)))

    if facebook_login:
        logger.info("trying to connect using facebook")
        graph = require_persistent_graph(request)
        if graph:
            logger.info("found a graph object")
            facebook = FacebookUserConverter(graph)

            if facebook.is_authenticated():
                logger.info("facebook is authenticated")
                facebook_data = facebook.facebook_profile_data()
                # either, login register or connect the user
                try:
                    action, user = connect_user(request)
                    logger.info("Django facebook performed action: %s", action)
                except facebook_exceptions.IncompleteProfileError, e:
                    # show them a registration form to add additional data
                    warning_format = u"Incomplete profile data encountered with error %s"
                    warn_message = warning_format % e.message
                    send_warning(warn_message, e=e, facebook_data=facebook_data)

                    context["facebook_mode"] = True
                    context["form"] = e.form
                    return render_to_response(
                        facebook_settings.FACEBOOK_REGISTRATION_TEMPLATE, context_instance=context
                    )

                if action is CONNECT_ACTIONS.CONNECT:
                    # connect means an existing account was attached to facebook
                    messages.info(
                        request,
                        _("You have connected your account " "to %s's facebook profile") % facebook_data["name"],
                    )
                elif action is CONNECT_ACTIONS.REGISTER:
                    # hook for tying in specific post registration functionality
                    response = backend.post_registration_redirect(request, user)
                    # compatability for django registration backends which return tuples instead of a response
                    # alternatively we could wrap django registration backends, but that would be hard to understand
                    response = response if isinstance(response, HttpResponse) else redirect(response)
                    return response
        else:
            if "attempt" in request.GET:
                return next_redirect(
                    request, next_key=["error_next", "next"], additional_params=dict(fb_error_or_cancel=1)
                )
            else:
                logger.info("Facebook authentication needed for connect, " "raising an error")
                raise OpenFacebookException("please authenticate")
예제 #50
0
def connect(request):
    '''
    Handles the view logic around connect user
    - (if authenticated) connect the user
    - login
    - register
    '''
    context = RequestContext(request)

    assert context.get('FACEBOOK_APP_ID'), 'Please specify a facebook app id '\
        'and ensure the context processor is enabled'
    facebook_login = bool(int(request.REQUEST.get('facebook_login', 0)))

    if facebook_login:
        #code to redirect if we don't have adequate permissions
        from django_facebook.utils import test_permissions
        scope_list = facebook_settings.FACEBOOK_DEFAULT_SCOPE
        #standardizing the url to prevent things like attempt from being included
        redirect_uri = request.build_absolute_uri(
            request.path) + '?facebook_login=1'
        oauth_url, redirect_uri = get_oauth_url(request,
                                                scope_list,
                                                redirect_uri=redirect_uri)
        if not test_permissions(request, scope_list, redirect_uri):
            return HttpResponseRedirect(oauth_url)

        graph = get_persistent_graph(request)
        if graph:
            facebook = FacebookUserConverter(graph)
            if facebook.is_authenticated():
                facebook_data = facebook.facebook_profile_data()
                #either, login register or connect the user
                try:
                    action, user = connect_user(request)
                    logger.info('Django facebook, action was %s', action)
                except facebook_exceptions.IncompleteProfileError, e:
                    warn_message = u'Incomplete profile data encountered '\
                        u'with error %s' % e
                    send_warning(
                        warn_message,
                        e=e,
                        facebook_data=facebook.facebook_profile_data())

                    context['facebook_mode'] = True
                    context['form'] = e.form
                    return render_to_response(
                        facebook_settings.FACEBOOK_REGISTRATION_TEMPLATE,
                        context_instance=context,
                    )

                if action is CONNECT_ACTIONS.CONNECT:
                    messages.info(
                        request,
                        _("You have connected your account "
                          "to %s's facebook profile") % facebook_data['name'])
                elif action is CONNECT_ACTIONS.REGISTER:
                    return user.get_profile().post_facebook_registration(
                        request)
        else:
            return next_redirect(request,
                                 next_key=['error_next', 'next'],
                                 additional_params=dict(fb_error_or_cancel=1))

        return next_redirect(request)
예제 #51
0
def connect(request):
    '''
    Handles the view logic around connect user
    - (if authenticated) connect the user
    - login
    - register
    '''
    backend = get_registration_backend()
    context = RequestContext(request)

    assert context.get('FACEBOOK_APP_ID'), 'Please specify a facebook app id '\
        'and ensure the context processor is enabled'
    facebook_login = bool(int(request.REQUEST.get('facebook_login', 0)))

    if facebook_login:
        require_persistent_graph(request)
        logger.info('trying to connect using facebook')
        graph = get_persistent_graph(request)
        if graph:
            logger.info('found a graph object')
            klass = get_facebook_user_converter_class()
            facebook = klass(graph)

            if facebook.is_authenticated():
                logger.info('facebook is authenticated')
                facebook_data = facebook.facebook_profile_data()
                #either, login register or connect the user
                try:
                    action, user = connect_user(request)
                    logger.info('Django facebook performed action: %s', action)
                except facebook_exceptions.IncompleteProfileError, e:
                    #show them a registration form to add additional data
                    warning_format = u'Incomplete profile data encountered with error %s'
                    warn_message = warning_format % e.message
                    send_warning(warn_message,
                                 e=e,
                                 facebook_data=facebook_data)

                    context['facebook_mode'] = True
                    context['form'] = e.form
                    return render_to_response(
                        facebook_settings.FACEBOOK_REGISTRATION_TEMPLATE,
                        context_instance=context,
                    )

                if action is CONNECT_ACTIONS.CONNECT:
                    #connect means an existing account was attached to facebook
                    messages.info(
                        request,
                        _("You have connected your account "
                          "to %s's facebook profile") % facebook_data['name'])
                elif action is CONNECT_ACTIONS.REGISTER:
                    #hook for tying in specific post registration functionality
                    response = backend.post_registration_redirect(
                        request, user)
                    return response
        else:
            if 'attempt' in request.GET:
                return next_redirect(
                    request,
                    next_key=['error_next', 'next'],
                    additional_params=dict(fb_error_or_cancel=1))
            else:
                logger.info('Facebook authentication needed for connect, ' \
                            'raising an error')
                raise OpenFacebookException('please authenticate')

        #for CONNECT and LOGIN we simple redirect to the next page
        return next_redirect(
            request, default=facebook_settings.FACEBOOK_LOGIN_DEFAULT_REDIRECT)
예제 #52
0
                    #compatability for django registration backends which return tuples instead of a response
                    #alternatively we could wrap django registration backends, but that would be hard to understand
                    if isinstance(response, HttpResponse):
                        return response
                    else:
                        try:
                            redirect(response)
                            #Not sure this return is necessary
                            return response
                        except TypeError:
                            #redirect to the next page
                            return next_redirect(request, default=facebook_settings.FACEBOOK_LOGIN_DEFAULT_REDIRECT)
                    
        else:
            if 'attempt' in request.GET:
                return next_redirect(request, next_key=['error_next', 'next'],
                    additional_params=dict(fb_error_or_cancel=1))
            else:
                logger.info('Facebook authentication needed for connect, ' \
                            'raising an error')
                raise OpenFacebookException('please authenticate')

        #for CONNECT and LOGIN we simple redirect to the next page
        return next_redirect(request, default=facebook_settings.FACEBOOK_LOGIN_DEFAULT_REDIRECT)

    if not settings.DEBUG and facebook_settings.FACEBOOK_HIDE_CONNECT_TEST:
        raise Http404

    return render_to_response('django_facebook/connect.html', context)


def disconnect(request):