Skip to content

Commit

Permalink
Update login page and site views.
Browse files Browse the repository at this point in the history
  • Loading branch information
HeitorLouzeiro committed Jan 4, 2024
1 parent 0d6bb84 commit 3c59bc1
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 33 deletions.
43 changes: 29 additions & 14 deletions accounts/templates/accounts/pages/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,40 @@
border-top-left-radius: 0;
border-top-right-radius: 0;
}
a {
color: #FFFFFF;
text-decoration: none;
}
</style>
<body class="d-flex align-items-center py-4 bg-body-tertiary">
{% include "../partials/_messeges.html" %}
<main class="form-signin w-100 m-auto">
<form action="{% url 'accounts:login' %}" method="POST">
{% csrf_token %}
<h1 class="h3 mb-3 text-light">Please sign in</h1>

<div class="form-floating mb-3">
<input type="text" class="form-control" name="username" />
<label>Username</label>
{% if user.is_authenticated %}
<h1 class="text-light text-center">You are already logged in</h1>
<div class="text-center">
<a href="{% url 'accounts:logout' %}" class="btn btn-primary">Logout</a>
<a href="{% url 'chatbot:index' %}" class="btn btn-secondary">Home</a>
</div>
<div class="form-floating">
<input type="password" class="form-control" name="password" />
<label>Password</label>
</div>
<button class="btn btn-primary w-100 py-2" type="submit">Sign in</button>
<p class="mt-5 mb-3 text-light">© 2017–2023</p>
</form>
{% else %}

<h1 class="h3 mb-3 text-light">Please sign in</h1>
<form action="{% url 'accounts:login' %}" method="POST">
{% csrf_token %}
<div class="form-floating mb-3">
<input type="text" class="form-control" name="username" />
<label>Username</label>
</div>
<div class="form-floating">
<input type="password" class="form-control" name="password" />
<label>Password</label>
</div>
<button class="btn btn-primary w-100 py-2" type="submit">Sign in</button>
<div class="text-center py-3">
<a href="https://github.com/HeitorLouzeiro" target="_blank">Git Hub</a> /
<a href="https://www.linkedin.com/in/heitor-louzeiro/" target="_blank">Linkedin</a>
</div>
</form>
{% endif %}
</main>
</body>
</html>
5 changes: 4 additions & 1 deletion chatbot/templates/static/assets/custom/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ body {
color: #FFFFFF;
font-family: 'Inter', sans-serif;
}

a {
text-decoration: none;
color: inherit;
}
.container {
padding: 0 2rem;
}
Expand Down
32 changes: 14 additions & 18 deletions chatbot/views/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from django.contrib.auth.decorators import login_required
from django.http import JsonResponse
from django.shortcuts import render
from django.shortcuts import redirect, render
from django.views.decorators.csrf import csrf_exempt

from .chatbot import carrega, trata_resposta
Expand All @@ -16,32 +16,28 @@ def index(request):
return render(request, template_name)


@login_required(login_url='accounts:login', redirect_field_name='next')
@csrf_exempt
def chat(request):
if request.method == 'POST':
try:
data = json.loads(request.body.decode('utf-8'))
prompt = data['msg']

nome_do_arquivo = request.user.username

historico = ''
if os.path.exists(nome_do_arquivo):
historico = carrega(nome_do_arquivo)
data = json.loads(request.body.decode('utf-8'))
prompt = data['msg']

response = list(trata_resposta(prompt, historico, nome_do_arquivo))
nome_do_arquivo = request.user.username

# Return the result as a JsonResponse
return JsonResponse({'response': response})
historico = ''
if os.path.exists(nome_do_arquivo):
historico = carrega(nome_do_arquivo)

except json.JSONDecodeError: # noqua
return JsonResponse({'response': 'Invalid JSON format'}, status=400)
response = list(trata_resposta(prompt, historico, nome_do_arquivo))

# If the request is not a POST request, render a template
template_name = 'pages/index.html'
return render(request, template_name)
# Return the result as a JsonResponse
return JsonResponse({'response': response})
else:
return redirect('chatbot:index')


@login_required(login_url='accounts:login', redirect_field_name='next')
@csrf_exempt
def limpar_historico(request):
nome_do_arquivo = request.user.username
Expand Down

0 comments on commit 3c59bc1

Please sign in to comment.