Exemplo n.º 1
0
def add(request):
    # if this is a POST request we need to process the form data
    if request.session.get('logged_in'):
        if request.method == 'POST':
            # create a form instance and populate it with data from the request:
            form = IdeaForm(request.POST)
            # check whether it's valid:
            if form.is_bound:
                if form.is_valid():

                    form.save()

                    template = loader.get_template('error.html')
                    context = {
                        'message': 'Added Idea ' + form.cleaned_data['title'],
                        'link': {
                            'text': 'Return to Ideas home',
                            'url': '/ideas',
                        },
                        'slink': {
                            'text': 'Add an other Idea',
                            'url': '/ideas/add'
                        },
                    }
                    embed = Webhook(values['whurl'], color=123123)

                    embed.set_author(
                        name='Codeniacs Website',
                        icon=
                        'https://codename-codeniacs.herokuapp.com/static/favicon.png'
                    )
                    embed.set_desc('Added Idea')
                    embed.add_field(name='Name',
                                    value=form.cleaned_data['title'])
                    embed.set_thumbnail(
                        'https://codename-codeniacs.herokuapp.com/static/favicon.png'
                    )

                    embed.set_footer(
                        text=
                        'This message was automatically sent form Codeniacs Website',
                        icon=
                        'https://codename-codeniacs.herokuapp.com/static/favicon.png',
                        ts=True)
                    embed.post()
                    return HttpResponse(template.render(context, request))
                else:
                    template = loader.get_template('error.html')
                    context = {
                        'message': 'Form is not valid',
                        'link': {
                            'text': 'Return to Ideas home',
                            'url': '/ideas'
                        }
                    }
                    return HttpResponse(template.render(context, request))
            else:
                template = loader.get_template('error.html')
                context = {
                    'message': 'Form is not bound',
                    'link': {
                        'text': 'Return to Ideas home',
                        'url': '/ideas'
                    }
                }
                return HttpResponse(template.render(context, request))

        # if a GET (or any other method) we'll create a blank form
        else:
            form = IdeaForm()
            template = loader.get_template('ideas/add.html')
            context = {'form': form}
            return HttpResponse(template.render(context, request))
    else:
        return redirect('/')
Exemplo n.º 2
0
def delete(request, slug):
    if request.session.get('logged_in'):
        idea = Idea.objects.get(slug=slug)
        ideaname = idea.name
        user = Admin.objects.get(id=1)

        if request.GET:
            if request.GET['sk'] == values['securitykey']:
                idea.delete()
                template = loader.get_template('error.html')
                context = {
                    'message': 'Successfully deleted idea ' + ideaname,
                    'link': {
                        'text': 'Return to Ideas home',
                        'url': '/ideas'
                    }
                }
                embed = Webhook(values['whurl'], color=123123)

                embed.set_author(
                    name='Codeniacs Website',
                    icon=
                    'https://codename-codeniacs.herokuapp.com/static/favicon.png'
                )
                embed.set_desc('Deleted Idea')
                embed.add_field(name='Name', value=ideaname)
                embed.set_thumbnail(
                    'https://codename-codeniacs.herokuapp.com/static/favicon.png'
                )
                embed.set_footer(
                    text=
                    'This message was automatically sent form Codeniacs Website',
                    icon=
                    'https://codename-codeniacs.herokuapp.com/static/favicon.png',
                    ts=True)
                embed.post()
                return HttpResponse(template.render(context, request))
            else:
                template = loader.get_template('error.html')
                context = {
                    'message': 'Wrong Admin Key',
                    'link': {
                        'text': 'Return to Ideas home',
                        'url': '/ideas'
                    }
                }
                return HttpResponse(template.render(context, request))

        else:
            securitykey = ""
            for i in range(6):
                securitykey += str(random.randint(0, 9))

            print(securitykey)

            user.sendemail('Delete Idea',
                           'Your Security Key is ' + str(securitykey))
            values['securitykey'] = securitykey
            template = loader.get_template('ideas/delete.html')
            context = {}
            return HttpResponse(template.render(context, request))
    else:
        return redirect('/')
Exemplo n.º 3
0
def progress(request, slug):
    if request.session.get('logged_in'):
        task = Task.objects.get(slug=slug)
        task.inprogress = True
        task.save()
        embed = Webhook(values['whurl'], color=123123)

        embed.set_author(
            name='Codeniacs Website',
            icon='https://codename-codeniacs.herokuapp.com/static/favicon.png')
        embed.set_desc('Task in progress')
        embed.add_field(name='Name', value=task.name)
        embed.set_thumbnail(
            'https://codename-codeniacs.herokuapp.com/static/favicon.png')
        embed.set_footer(
            text='This message was automatically sent form Codeniacs Website',
            icon='https://codename-codeniacs.herokuapp.com/static/favicon.png',
            ts=True)
        embed.post()
        return redirect('/tasks')
    else:
        return redirect('/')
Exemplo n.º 4
0
def delete(request, slug):
    if request.session.get('logged_in'):
        task = Task.objects.get(slug=slug)
        taskname = task.name
        user = task.user
        if request.GET:
            if request.GET['sk'] == user.secretKey:
                ctask = CompletedTask()
                ctask.name = task.name
                ctask.date = task.date
                ctask.user = task.user
                ctask.saveslug(ctask.name)
                ctask.save()
                task.delete()
                template = loader.get_template('error.html')
                context = {
                    'message': 'Successfully deleted task ' + taskname,
                    'link': {
                        'text': 'Return to Tasks home',
                        'url': '/tasks'
                    }
                }
                embed = Webhook(values['whurl'], color=123123)

                embed.set_author(
                    name='Codeniacs Website',
                    icon=
                    'https://codename-codeniacs.herokuapp.com/static/favicon.png'
                )
                embed.set_desc('Completed Task')
                embed.add_field(name='Name', value=taskname)
                embed.set_thumbnail(
                    'https://codename-codeniacs.herokuapp.com/static/favicon.png'
                )

                embed.set_footer(
                    text=
                    'This message was automatically sent form Codeniacs Website',
                    icon=
                    'https://codename-codeniacs.herokuapp.com/static/favicon.png',
                    ts=True)
                embed.post()
                return HttpResponse(template.render(context, request))
            else:
                template = loader.get_template('error.html')
                context = {
                    'message': 'Wrong Secret Key',
                    'link': {
                        'text': 'Return to Tasks home',
                        'url': '/tasks'
                    }
                }
                return HttpResponse(template.render(context, request))
        else:
            template = loader.get_template('tasks/delete.html')
            context = {'user': user}
            return HttpResponse(template.render(context, request))
    else:
        return redirect('/')
Exemplo n.º 5
0
def delete(request, slug):
    if request.session.get('logged_in'):
        user = People.objects.get(slug=slug)
        admin = Admin.objects.get(id=1)
        if request.GET:
            if request.GET['sk'] == user.secretKey:
                if request.GET['ak'] == values['securitykey']:
                    try:
                        username = user.name
                        user.delete()
                        template = loader.get_template('error.html')
                        context = {
                            'message': 'Deleted User ' + username,
                            'link': {
                                'text': 'Return to People home',
                                'url': '/people'
                            }
                        }
                        embed = Webhook(values['whurl'], color=123123)

                        embed.set_author(
                            name='Codeniacs Website',
                            icon=
                            'https://codename-codeniacs.herokuapp.com/static/favicon.png'
                        )
                        embed.set_desc('Deleted User')
                        embed.add_field(name='Name', value=username)
                        embed.set_thumbnail(
                            'https://codename-codeniacs.herokuapp.com/static/favicon.png'
                        )

                        embed.set_footer(
                            text=
                            'This message was automatically sent form Codeniacs Website',
                            icon=
                            'https://codename-codeniacs.herokuapp.com/static/favicon.png',
                            ts=True)
                        embed.post()
                        return HttpResponse(template.render(context, request))

                    except:
                        template = loader.get_template('error.html')
                        context = {
                            'message': 'Unable to delete',
                            'link': {
                                'text': 'Return to People home',
                                'url': '/people'
                            }
                        }
                        return HttpResponse(template.render(context, request))
                else:
                    template = loader.get_template('error.html')
                    context = {
                        'message': 'Wrong Admin Key',
                        'link': {
                            'text': 'Return to People home',
                            'url': '/people'
                        }
                    }
                    return HttpResponse(template.render(context, request))
            else:
                template = loader.get_template('error.html')
                context = {
                    'message': 'Wrong Secret Key',
                    'link': {
                        'text': 'Return to People home',
                        'url': '/people'
                    }
                }
                return HttpResponse(template.render(context, request))
        else:
            securitykey = ""
            for i in range(6):
                securitykey += str(random.randint(0, 9))

            print(securitykey)

            admin.sendemail('Delete User',
                            'Your Security Key is ' + str(securitykey))
            values['securitykey'] = securitykey
            template = loader.get_template('people/delete.html')
            context = {'user': user}
            return HttpResponse(template.render(context, request))
    else:
        return redirect('/')
Exemplo n.º 6
0
def add(request):
    if request.session.get('logged_in'):
        if 'n' in request.GET:
            one = People()
            one.name = request.GET['n']
            one.birthDate = request.GET['bd']
            one.rang = request.GET['r']
            one.secretKey = request.GET['sk']
            one.saveslug(request.GET['n'])
            one.activation = "".join(
                [str(random.randint(0, 9)) for i in range(15)])
            one.save()
            template = loader.get_template('error.html')
            context = {
                'message': 'Sent Activation Email to User ' + one.name,
                'link': {
                    'text': 'Return to People home',
                    'url': '/people'
                },
                'slink': {
                    'text': 'Add an other User',
                    'url': '/people/add'
                },
            }
            a = Admin.objects.get(id=1)
            a.sendemail(
                'Added user ' + one.name, 'User secret key: ' + one.secretKey +
                ' User is not activated yet.')
            send_mail(
                'Email Activation Codeniacs',
                'Hello ' + one.name + '(Sercret Key: ' + one.secretKey +
                '), Your account is not confirmed. Click on the link to activate: http://codename-codeniacs.herokuapp.com'
                + one.activationpath() + ' (Testers)',
                '*****@*****.**', [
                    request.GET['e'],
                ],
                fail_silently=False)

            embed = Webhook(values['whurl'], color=123123)

            embed.set_author(
                name='Codeniacs Website',
                icon=
                'https://codename-codeniacs.herokuapp.com/static/favicon.png')
            embed.set_desc('Added User')
            embed.add_field(name='Name', value=one.name)
            embed.add_field(name='Rank', value=one.rang)
            embed.set_thumbnail(
                'https://codename-codeniacs.herokuapp.com/static/favicon.png')

            embed.set_footer(
                text=
                'This message was automatically sent form Codeniacs Website',
                icon=
                'https://codename-codeniacs.herokuapp.com/static/favicon.png',
                ts=True)
            embed.post()
            return HttpResponse(template.render(context, request))
        else:
            context = {'message': "Add new users"}
            template = loader.get_template('people/add.html')
            return HttpResponse(template.render(context, request))
    else:
        return redirect('/')