Exemplo n.º 1
0
def login_view(request):
    clr.clear_msgs(request)
    if request.user.is_authenticated:
        # msgs.info(request, sw().status())
        return redirect('/home/')
    else:
        user_login = UserLogin(data=request.POST)
        if request.method == 'POST':
            email = user_login.data.get('email')
            password = user_login.data.get('password')
            user = authenticate(request, username=email, password=password)
            if user is not None:
                auth_login(request, user)
                msgs.success(
                    request,
                    'Welcome to the Bug bash {}'.format(user.first_name))
                # msgs.info(request, sw().status())
                return HttpResponseRedirect('/home/')

            elif CustomUser.objects.filter(email=email).exists():
                msgs.error(request,
                           'Wrong password for user: {}'.format(email))
                return render(request, 'login.html',
                              {'user_login': user_login})
            else:
                msgs.error(request, 'Error: User not registered')
                return render(request, 'login.html',
                              {'user_login': user_login})
        else:
            return render(request, 'login.html', {'user_login': user_login})
Exemplo n.º 2
0
def create_bashing_session(request):
    clr.clear_msgs(request)
    submitted = False
    if request.method == "POST":
        form = BashSessionForm(request.POST)
        if form.is_valid():
            try:
                message = "Starting Bash Session!"
                request.session['feature'] = request.POST['feature']
                request.session['device'] = request.POST['device']
                bash_session = form.save(commit=False)
                bash_session.user = request.user
                bash_session.save()

                return redirect('/bugreport/',
                                messages.success(request, message))

            except:
                message = "ERROR: Could not Start Bash Session successfully"
                return redirect('/home', messages.error(request, message))
    else:
        form = BashSessionForm()
    messages.info(request, sw().status())
    return render(request, 'startpage.html', {
        'form': form,
        'submitted': submitted
    })
Exemplo n.º 3
0
def create_user_bug_view(request):
    clr.clear_msgs(request)
    template_vars = {
        'all_bugs':
        BugLogStructure.objects.filter(user=request.user).reverse(),
        'form':
        BugLogForm(
            initial={
                'device': request.session['device'],
                'feature': request.session['feature']
            })
    }

    return render(request, 'bugreport.html', template_vars)
Exemplo n.º 4
0
def register(request):
    clr.clear_msgs(request)
    register_form = RegisterForm(data=request.POST)
    if request.method == 'POST':
        msg = "Unable to create account"
        if register_form.is_valid():
            user = register_form.save()
            auth_login(request, user)
            msgs.success(request, "You are registered!")
            return HttpResponseRedirect('/home/')
        else:
            try:
                if 'This email address is already in use' in register_form.errors[
                        'email'][0]:
                    msg = "Email already registered, try logging in"
            except:
                msg = "Please try to register again!"
            msgs.error(request, msg)
    else:
        register_form = RegisterForm()
    return render(request, "register.html", {'form': register_form})
Exemplo n.º 5
0
def create_report(request):
    clr.clear_msgs(request)
    if request.method == 'POST':
        try:
            logged_bug = BugLogStructure(user=request.user,
                                         device=request.POST.get('device'),
                                         feature=request.POST.get('feature'),
                                         summary=request.POST.get('summary'),
                                         steps=request.POST.get('steps'),
                                         result=request.POST.get('result'))
            logged_bug.save()
            response_data = {
                'id': logged_bug.id,
                'summary': request.POST.get('summary')
            }
            return JsonResponse(response_data)
        except IntegrityError:
            raise
    else:
        return HttpResponse(json.dumps(
            {"nothing to see": "this isn't happening"}),
                            content_type="application/json")
Exemplo n.º 6
0
def logout_view(request):
    clr.clear_msgs(request)
    logout(request)
    user_login = UserLogin()
    msgs.success(request, 'You have successfully logged out')
    return render(request, 'login.html', {'user_login': user_login})