Exemplo n.º 1
0
def unsubscribe(request):
    id = request.GET['id']
    id_type = request.GET.get('id_type', 'user')
    code = request.GET['code']
    pub = request.GET.get('pub')
    pub_id = request.GET.get('pub_id')

    if id_type == 'user':
        try:
            user = User.objects.get(id=id, is_active=True)
        except ObjectDoesNotExist:
            raise Http404
    elif id_type == 'donor':
        try:
            user = Donor.objects.get(id=id)
        except ObjectDoesNotExist:
            raise Http404
    else:
        raise Http404

    expected_code = salted_hash(user.email)
    if code <> expected_code:
        raise Http404

    if pub:
        pub = pubs[pub]
        publication_id = pub.publication_id
    elif pub_id:
        publication_id = pub_id
    else:
        raise Http404

    pub = Publication.objects.get(id=publication_id)

    unsub, created = Unsubscribe.objects.get_or_create(email=user.email,
                                                       publication_id=pub.id)

    if pub.user_settings_field:
        # Update user table anyway to allow for resubscription, etc.
        setattr(user, pub.user_settings_field, 0)
        user.save()
        cache.bust_on_handle(user, user.username)
    else:
        try:
            if id_type == 'donor':
                sub = Subscription.objects.get(donor=user.id,
                                               publication=pub.id)
            elif id_type == 'user':
                sub = Subscription.objects.get(user=user.id,
                                               publication=pub.id)
            sub.subscribed = False
            sub.save()
            #cache.bust([user, sub])
        except ObjectDoesNotExist:
            raise Http404

    return render(request, 'etc/unsubscribe.html', {
        'created': created,
        'user': user,
    })
Exemplo n.º 2
0
def fbot_update(request):
    if 'ot' not in request.POST:
        return HttpResponseBadRequest()
    request.user.fb_access_token = request.POST['ot']
    request.user.save()
    cache.bust_on_handle(request.user, request.user.username)
    return json_response({})
Exemplo n.º 3
0
def fbot_update(request):
    if 'ot' not in request.POST:
        return HttpResponseBadRequest()
    request.user.fb_access_token = request.POST['ot']
    request.user.save()
    cache.bust_on_handle(request.user, request.user.username)
    return json_response({})
Exemplo n.º 4
0
def unsubscribe(request):
    id = request.GET['id']
    id_type = request.GET.get('id_type', 'user')
    code = request.GET['code']
    pub = request.GET.get('pub')
    pub_id = request.GET.get('pub_id')

    if id_type == 'user':
        try:
            user = User.objects.get(id=id, is_active=True)
        except ObjectDoesNotExist:
            raise Http404
    elif id_type == 'donor':
        try:
            user = Donor.objects.get(id=id)
        except ObjectDoesNotExist:
            raise Http404
    else:
        raise Http404

    expected_code = salted_hash(user.email)
    if code <> expected_code:
        raise Http404

    if pub:
        pub = pubs[pub]
        publication_id = pub.publication_id
    elif pub_id:
        publication_id = pub_id
    else:
        raise Http404

    pub = Publication.objects.get(id=publication_id)

    unsub, created = Unsubscribe.objects.get_or_create(email=user.email, publication_id=pub.id)

    if pub.user_settings_field:
        # Update user table anyway to allow for resubscription, etc.
        setattr(user, pub.user_settings_field, 0)
        user.save()
        cache.bust_on_handle(user, user.username)
    else:
        try:
            if id_type=='donor':
                sub = Subscription.objects.get(donor=user.id, publication=pub.id)
            elif id_type=='user':
                sub = Subscription.objects.get(user=user.id, publication=pub.id)
            sub.subscribed=False
            sub.save()
            #cache.bust([user, sub])
        except ObjectDoesNotExist:
            raise Http404

    return render(request, 'etc/unsubscribe.html', {'created': created,
                     'user': user,})
Exemplo n.º 5
0
 def update_fb_follows(self, fb_ids, send_notifications=True):
     accounts = User.objects.filter(facebook_id__in = fb_ids)
     for acc in accounts:
         uuf, created = UserToUserFollow.objects.get_or_create(followed = acc, follower = self)
         if created:
             uuf.is_following = True
             uuf.save()
             cache.bust_on_handle(acc, acc.username)
             if acc.enable_followed_notification and send_notifications:
                 from mailer.notification_tasks import send_notification, EmailTypes
                 send_notification(type=EmailTypes.FOLLOW, user=acc, entity=self)
Exemplo n.º 6
0
 def update_fb_follows(self, fb_ids, send_notifications=True):
     accounts = User.objects.filter(facebook_id__in=fb_ids)
     for acc in accounts:
         uuf, created = UserToUserFollow.objects.get_or_create(
             followed=acc, follower=self)
         if created:
             uuf.is_following = True
             uuf.save()
             cache.bust_on_handle(acc, acc.username)
             if acc.enable_followed_notification and send_notifications:
                 from mailer.notification_tasks import send_notification, EmailTypes
                 send_notification(type=EmailTypes.FOLLOW,
                                   user=acc,
                                   entity=self)
Exemplo n.º 7
0
    for f in int_fields:
        if f in org and org[f] != getattr(original, f):
            if org[f]:
                setattr(original, f, int(org[f]))
            else:
                setattr(original, f, None)

    for f in bool_fields:
        if f in org and org[f] != getattr(original, f):
            setattr(original, f, org[f])

    if 'handle' in org and org['handle'] != original.handle:
        _handle = original.handle
        original.handle = create_handle(org['handle'])
        cache.bust_on_handle(original, _handle, False)

    if 'methods' in org:
        for method in org['methods']:
            if method not in [l.method for l in original.method_set.all()]:
                m = Method()
                m.method = method
                m.date_created = datetime.datetime.now()
                m.date_updated = datetime.datetime.now()
                m.org = original
                m.save()

        for method in original.method_set.all():
            if method.method not in org['methods']:
                method.delete()
Exemplo n.º 8
0
 def delete(self):
     cache.bust_on_handle(self, self.username, False)
     return super(self.__class__, self).delete()
Exemplo n.º 9
0
def remove_user(request):
    request.user.is_active = False
    request.user.save()
    cache.bust_on_handle(request.user, request.user.username)
    logout(request)
    return unset_auth_cookies(HttpResponseRedirect('/'))
Exemplo n.º 10
0
def remove_user(request):
    request.user.is_active = False
    request.user.save()
    cache.bust_on_handle(request.user, request.user.username)
    logout(request)
    return unset_auth_cookies(HttpResponseRedirect('/'))
Exemplo n.º 11
0
def update_user(request):
    if 'user' not in request.POST:
        return HttpResponseBadRequest()
    user = json.loads(request.POST['user'])

    if 'location' in user and user['location']:
        loc = user['location']
        raw_geodata = json.dumps(loc["raw_geodata"]) if isinstance(
            loc.get("raw_geodata"), dict) else loc.get("raw_geodata")

        #Until we fix duplicate locations we have to do the following...lame.
        _locs = Location.objects.filter(
            raw_geodata=raw_geodata,
            longitude=loc.get('longitude', None),
            latitude=loc.get('latitude', None),
            address=loc.get('address', ' '),
            region=loc.get('region', ' '),
            locality=loc.get('locality', ' '),
            postal_code=loc.get('postal_code', ' '),
            country_name=loc.get('country_name', ' '))

        if len(_locs) > 0:
            _loc = _locs[0]
        else:
            _loc = Location(
                raw_geodata=raw_geodata,
                longitude=loc.get('longitude', None),
                latitude=loc.get('latitude', None),
                address=loc.get('address', ' '),
                region=loc.get('region', ' '),
                locality=loc.get('locality', ' '),
                postal_code=loc.get('postal_code', ' '),
                country_name=loc.get('country_name', ' '),
            )
            _loc.save()
        request.user.location = _loc
    else:
        request.user.location = None

    str_fields = [
        'first_name',
        'last_name',
        'email',
        'gender',
        'bio',
        'url',
        'twitter_id',
        'flickr_id',
        'youtube_id',
        'vimeo_id',
        'blog_url',
    ]

    settings_fields = [
        'enable_jumo_updates',
        'email_stream_frequency',
        'post_to_fb',
    ]

    int_fields = [
        'birth_year',
    ]

    if 'enable_followed_notification' in user:
        try:
            sub = request.user.subscriptions.get(id=NOTIFICATIONS_PUB)
        except Subscription.DoesNotExist:
            sub = Subscription.get_or_create(user=request.user,
                                             pub_id=NOTIFICATIONS_PUB)

        if sub.subscribed <> user['enable_follow_notification']:
            sub.subscribed = user['enable_follow_notification']
            sub.save()

    for f in str_fields:
        if f in user and user[f] != getattr(request.user, f):
            setattr(request.user, f, user[f])

    for f in settings_fields:
        settings = user['settings']
        if f in settings:
            setattr(request.user, f, settings[f])

    for f in int_fields:
        if f in user and user[f] != getattr(request.user, f):
            if user[f] == '':
                user[f] = None
            setattr(request.user, f, user[f])

    if 'password' in user and user['password'] != '':
        request.user.password = hash_password(user['password'])
    if 'username' in user and user['username'] != request.user.username:
        _username = request.user.username
        request.user.username = create_handle(user['username'])
        cache.bust_on_handle(request.user, _username, False)

    request.user.save()
    cache.bust_on_handle(request.user, request.user.username)
    return json_response({'result': request.user.username})
Exemplo n.º 12
0
def remove_user(request):
    request.user.is_active = False
    request.user.save()
    cache.bust_on_handle(request.user, request.user.username)
    logout(request)
    return unset_auth_cookies(json_response({'result': 1}))
Exemplo n.º 13
0
 def delete(self):
     cache.bust_on_handle(self, self.username, False)
     return super(self.__class__, self).delete()
Exemplo n.º 14
0
def update_user(request):
    if 'user' not in request.POST:
        return HttpResponseBadRequest()
    user = json.loads(request.POST['user'])

    if 'location' in user and user['location']:
        loc = user['location']
        raw_geodata = json.dumps(loc["raw_geodata"]) if isinstance(loc.get("raw_geodata"), dict) else loc.get("raw_geodata")

        #Until we fix duplicate locations we have to do the following...lame.
        _locs = Location.objects.filter(raw_geodata = raw_geodata,
            longitude = loc.get('longitude', None),
            latitude = loc.get('latitude', None),
            address = loc.get('address', ' '),
            region = loc.get('region', ' '),
            locality = loc.get('locality', ' '),
            postal_code = loc.get('postal_code', ' '),
            country_name = loc.get('country_name', ' '))

        if len(_locs) > 0:
            _loc = _locs[0]
        else:
            _loc = Location(raw_geodata = raw_geodata,
                longitude = loc.get('longitude', None),
                latitude = loc.get('latitude', None),
                address = loc.get('address', ' '),
                region = loc.get('region', ' '),
                locality = loc.get('locality', ' '),
                postal_code = loc.get('postal_code', ' '),
                country_name = loc.get('country_name', ' '),)
            _loc.save()
        request.user.location = _loc
    else:
        request.user.location = None

    str_fields = [
                    'first_name', 'last_name', 'email', 'gender', 'bio',
                    'url', 'twitter_id', 'flickr_id', 'youtube_id', 'vimeo_id', 'blog_url',
                 ]

    settings_fields = [
                    'enable_jumo_updates', 'email_stream_frequency', 'post_to_fb',
                  ]

    int_fields = [
                    'birth_year',
                 ]

    if 'enable_followed_notification' in user:
        try:
            sub = request.user.subscriptions.get(id=NOTIFICATIONS_PUB)
        except Subscription.DoesNotExist:
            sub = Subscription.get_or_create(user=request.user, pub_id=NOTIFICATIONS_PUB)

        if sub.subscribed <> user['enable_follow_notification']:
            sub.subscribed = user['enable_follow_notification']
            sub.save()

    for f in str_fields:
        if f in user and user[f] != getattr(request.user, f):
            setattr(request.user, f, user[f])

    for f in settings_fields:
        settings = user['settings']
        if f in settings:
            setattr(request.user, f, settings[f])

    for f in int_fields:
        if f in user and user[f] != getattr(request.user, f):
            if user[f] == '':
                user[f] = None
            setattr(request.user, f, user[f])

    if 'password' in user and user['password'] != '':
        request.user.password = hash_password(user['password'])
    if 'username' in user and user['username'] != request.user.username:
        _username = request.user.username
        request.user.username = create_handle(user['username'])
        cache.bust_on_handle(request.user, _username, False)

    request.user.save()
    cache.bust_on_handle(request.user, request.user.username)
    return json_response({'result' : request.user.username})
Exemplo n.º 15
0
def remove_user(request):
    request.user.is_active = False
    request.user.save()
    cache.bust_on_handle(request.user, request.user.username)
    logout(request)
    return unset_auth_cookies(json_response({'result':1}))
Exemplo n.º 16
0
    for f in int_fields:
        if f in org and org[f] != getattr(original, f):
            if org[f]:
                setattr(original, f, int(org[f]))
            else:
                setattr(original, f, None)

    for f in bool_fields:
        if f in org and org[f] != getattr(original, f):
            setattr(original, f, org[f])

    if 'handle' in org and org['handle'] != original.handle:
        _handle = original.handle
        original.handle = create_handle(org['handle'])
        cache.bust_on_handle(original, _handle, False)

    if 'methods' in org:
        for method in org['methods']:
            if method not in [l.method for l in original.method_set.all()]:
                m = Method()
                m.method = method
                m.date_created = datetime.datetime.now()
                m.date_updated = datetime.datetime.now()
                m.org = original
                m.save()

        for method in original.method_set.all():
            if method.method not in org['methods']:
                method.delete()