Example #1
0
def add_group_post(request):
    if not request.user.is_authenticated:
        raise PermissionDenied

    group_id = request.POST.get("group_id", "null")
    member_id = request.POST.get("member_id", "null")
    post_text = request.POST.get("post_text", "null")

    utils.check_captcha(request)

    if not group_exists(group_id):
        raise PermissionDenied
    if not member_exists(member_id):
        raise PermissionDenied

    group = Groups.objects.get(id=group_id)
    member = CustomUser.objects.get(id=member_id)

    if not (isMember(member, group) or isAdmin(member, group)):
        raise PermissionDenied

    Group_Posts.objects.create(group=group,
                               author=member,
                               description=post_text)
    return HttpResponseRedirect(
        reverse('groups:group_view', kwargs={'group_id': group_id}))
Example #2
0
def send_message(request):
    if not request.user.is_authenticated:
        raise PermissionDenied
    if request.user.user_type == 1:
        return utils.raise_exception(request,
                                     "Upgrade your account to send messages.")
    utils.check_captcha(request)
    friend_username = request.POST.get('friend_username', 'null')
    if not username_exists(friend_username):
        raise PermissionDenied
    friend_user = CustomUser.objects.get(username=friend_username)
    if request.user.user_type != 5 and not are_friend(request.user,
                                                      friend_user):
        return utils.raise_exception(
            request, "You are not allowed to send messages to strangers.")
    message_text = request.POST.get("message_text", "null")
    my_friends = get_friends(request.user)
    Private_Message.objects.create(sender=request.user,
                                   receiver=friend_user,
                                   message=message_text)
    context = {'my_friends': my_friends}
    context['chats'] = getAllMessages(user1=request.user, user2=friend_user)
    context['friend_username'] = friend_username
    context['display_message_box'] = True
    return HttpResponseRedirect(
        reverse('private_message:friends_message_username',
                kwargs={'friend_username': friend_username}))
def add_post(request):
    if not request.user.is_authenticated:
        raise PermissionDenied
    if request.user.user_type != 5:
        raise PermissionDenied
    page_id = request.POST.get("page_id", "null")
    page = CommercialPage.objects.get(id=page_id)
    if not isPageAdmin(request.user, page):
        raise PermissionDenied
    utils.check_captcha(request)
    post_text = request.POST.get("post_text", "null")
    CommercialPagePosts.objects.create(page=page, post_text=post_text)
    return HttpResponseRedirect(
        reverse('commercial_page:page_timeline', kwargs={'page_id': page_id}))
def add_post(request):
    # TODO add checks
    if not request.user.is_authenticated:
        raise PermissionDenied
    author_name = request.user.username
    recipient_name = request.user.username
    post_text = request.POST.get('post_text', "N/A")

    utils.check_captcha(request)

    Post.objects.create(author_name=author_name,
                        recipient_name=recipient_name,
                        post_text=post_text)
    return redirect('friends:timeline')
def add_page(request):
    if not request.user.is_authenticated:
        raise PermissionDenied
    if request.user.user_type != 5:
        raise PermissionDenied
    # if request.method == 'POST':
    #     recaptcha_response = request.POST.get('g-recaptcha-response')
    #     data = {
    #         'secret': settings.GOOGLE_RECAPTCHA_SECRET_KEY,
    #         'response': recaptcha_response
    #     }
    #     result = requests.post('https://www.google.com/recaptcha/api/siteverify', data=data).json()
    #     if not result['success']:
    #         raise PermissionDenied
    utils.check_captcha(request)
    page_name = request.POST.get("page_name", "null")
    admin = request.user
    description = request.POST.get("description", "null")
    CommercialPage.objects.create(page_name=page_name,
                                  admin=admin,
                                  description=description)
    return HttpResponseRedirect(reverse('commercial_page:page_list'))
Example #6
0
def addgroup(request):
    if not request.user.is_authenticated:
        raise PermissionDenied
    if request.user.user_type == 1:
        return utils.raise_exception(request,
                                     "Upgrade your account to make groups.")
    num_groups = len(getOwnedGroups(request.user))
    allowed_groups = 2147483646
    if request.user.user_type == 2:
        allowed_groups = 2
    elif request.user.user_type == 3:
        allowed_groups = 4

    utils.check_captcha(request)

    # if num_groups >= allowed_groups:
    #     return utils.raise_exception(request, "You have reached the limit of adding groups (" + str(allowed_groups) + ")")
    if request.method == "POST":
        if num_groups >= allowed_groups:
            return utils.raise_exception(
                request, "You have reached the limit of adding groups (" +
                str(allowed_groups) + ")")
        form = GroupCreateForm(request.POST)
        if form.is_valid():
            group_name = form.cleaned_data['group_name']
            description = form.cleaned_data['description']
            fees = form.cleaned_data['fees']
            if fees < 0:
                raise PermissionDenied
            obj = Groups.objects.create(group_name=group_name,
                                        description=description,
                                        fees=fees,
                                        admin_id=request.user.id)
            obj.save()
            return HttpResponseRedirect(reverse('groups:add_group'))
    else:
        form = GroupCreateForm()
    return render(request, 'create_group.html', {'form': form})
def add_post_friend(request, friend_username):
    # TODO add checks
    if not request.user.is_authenticated:
        raise PermissionDenied
    # friend = None
    # try:
    #     friend = CustomUser.objects.get(username=friend_username)
    # except:
    #     raise PermissionDenied
    utils.check_captcha(request)
    if not username_exists(friend_username):
        raise PermissionDenied
    friend = CustomUser.objects.get(username=friend_username)
    if not are_friend(request.user, friend):
        raise PermissionDenied
    author_name = request.user.username
    recipient_name = friend_username
    post_text = request.POST.get('post_text', "N/A")

    Post.objects.create(author_name=author_name,
                        recipient_name=recipient_name,
                        post_text=post_text)
    return redirect('friends:friend_timeline', friend_username=friend_username)
 def dispatch(self, request, *args, **kwargs):
     if request.user.is_authenticated:
         return HttpResponseRedirect(reverse('friends:timeline'))
     utils.check_captcha(request)
     return super(SignUp, self).dispatch(request, *args, **kwargs)