From aa5ae227e7af01ffac3be949ca289fd701285043 Mon Sep 17 00:00:00 2001 From: Pedro Lucas Garcia <190115548@aluno.unb.br> Date: Tue, 2 Apr 2024 08:40:24 -0300 Subject: [PATCH 01/10] Atualiza como subir backend em README.md --- README.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 72be0d95..71aae008 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,14 @@ Como a versão LTS mais recente do Django (2024) é a 4.2, escolhemos configurar Estas etapas são válidas para Linux OS e WSL. #### Como subir o back-end: -Primeiramente, interrompa qualquer processo que use o porto 8080, 3306 e 6379. +Primeiramente, interrompa qualquer processo que use o porto 8080, 3306 e 6379. Então atualize o seu sistema: + ``` + sudo apt-get update + ``` + + ``` + sudo apt-get upgrade + ``` Em seguida, caso já não tenha instalado: @@ -124,10 +131,10 @@ Em seguida, caso já não tenha instalado: Virtualenv: ``` - pip install virtualenv + sudo pip3 install virtualenv ``` -Dentro da pasta raiz `api`: +Vá para dentro da pasta raiz `api`: 1. Cria o ambiente virtual e ative-o: From 84566b5c1bd9d39c070ecc55987005a030220ffe Mon Sep 17 00:00:00 2001 From: Pedro Lucas Garcia <190115548@aluno.unb.br> Date: Tue, 2 Apr 2024 10:07:04 -0300 Subject: [PATCH 02/10] Configura cors no backend --- api/sigeie/settings.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/api/sigeie/settings.py b/api/sigeie/settings.py index e2edb5b4..ecc98239 100644 --- a/api/sigeie/settings.py +++ b/api/sigeie/settings.py @@ -6,7 +6,7 @@ DEBUG = True -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = ['127.0.0.1', '10.0.2.2'] INSTALLED_APPS = [ 'django.contrib.admin', @@ -16,6 +16,7 @@ 'django.contrib.messages', 'django.contrib.staticfiles', 'rest_framework', + 'corsheaders', 'users', 'places', 'systems' @@ -24,6 +25,7 @@ MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', + "corsheaders.middleware.CorsMiddleware", 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', @@ -117,4 +119,6 @@ 'DEFAULT_PERMISSION_CLASSES': { 'rest_framework.permissions.IsAUthenticatedOrReadOnly', } -} \ No newline at end of file +} + +CORS_ALLOW_ALL_ORIGINS = True \ No newline at end of file From 86debee03dd892a40bbf383735c04757cf53075a Mon Sep 17 00:00:00 2001 From: Pedro Lucas Garcia <190115548@aluno.unb.br> Date: Tue, 2 Apr 2024 10:11:36 -0300 Subject: [PATCH 03/10] Atualiza requirements.txt --- api/requirements.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/api/requirements.txt b/api/requirements.txt index 7d82a237..9268dd4e 100644 --- a/api/requirements.txt +++ b/api/requirements.txt @@ -1,7 +1,10 @@ asgiref==3.7.2 async-timeout==4.0.3 Django==4.2 +django-cors-headers==4.3.1 django-redis==5.4.0 +django-redis-session-store==0.1.1 +django-redis-sessions==0.6.2 djangorestframework==3.14.0 mysqlclient==2.2.4 pytz==2024.1 From 8c55a3d1bb5ce7ba430f8930094790a86b41a72c Mon Sep 17 00:00:00 2001 From: Pedro Lucas Garcia <190115548@aluno.unb.br> Date: Tue, 2 Apr 2024 11:00:47 -0300 Subject: [PATCH 04/10] =?UTF-8?q?Corrige=20erro=20no=20campo=20de=20serial?= =?UTF-8?q?iza=C3=A7=C3=A3o=20de=20User?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/users/serializers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/users/serializers.py b/api/users/serializers.py index 47dd2327..2c30b80a 100644 --- a/api/users/serializers.py +++ b/api/users/serializers.py @@ -6,7 +6,7 @@ class UserSerializer(serializers.ModelSerializer): class Meta: model = User - fields = ['id', 'password', 'username', 'first_name', 'email', 'is_active', 'date_joined', 'groups', 'places'] + fields = ['id', 'password', 'username', 'first_name', 'email', 'is_active', 'date_joined', 'groups'] extra_kwargs = { 'password': {'write_only': True}, 'first_name': {'required': True}, From 7e1f68227c88ef167926c9a9295f5a92a0c9db56 Mon Sep 17 00:00:00 2001 From: EngDann Date: Tue, 2 Apr 2024 11:17:13 -0300 Subject: [PATCH 05/10] Atualizacao conexao front-back --- frontend/sige_ie/lib/screens/facilities.dart | 0 frontend/sige_ie/lib/screens/home.dart | 0 frontend/sige_ie/lib/screens/login.dart | 14 +++++++----- frontend/sige_ie/lib/screens/maps.dart | 0 frontend/sige_ie/lib/screens/register.dart | 22 +++++++++++-------- .../lib/screens/\341\271\225roflile.dart" | 0 6 files changed, 22 insertions(+), 14 deletions(-) create mode 100644 frontend/sige_ie/lib/screens/facilities.dart create mode 100644 frontend/sige_ie/lib/screens/home.dart create mode 100644 frontend/sige_ie/lib/screens/maps.dart create mode 100644 "frontend/sige_ie/lib/screens/\341\271\225roflile.dart" diff --git a/frontend/sige_ie/lib/screens/facilities.dart b/frontend/sige_ie/lib/screens/facilities.dart new file mode 100644 index 00000000..e69de29b diff --git a/frontend/sige_ie/lib/screens/home.dart b/frontend/sige_ie/lib/screens/home.dart new file mode 100644 index 00000000..e69de29b diff --git a/frontend/sige_ie/lib/screens/login.dart b/frontend/sige_ie/lib/screens/login.dart index ed25423d..ef7e1502 100644 --- a/frontend/sige_ie/lib/screens/login.dart +++ b/frontend/sige_ie/lib/screens/login.dart @@ -16,12 +16,16 @@ class _LoginScreenState extends State { final TextEditingController passwordController = TextEditingController(); Future login(String username, String password) async { - var url = Uri.parse('http://127.0.0.1:8000/api/login/'); + var url = Uri.parse('http://10.0.2.2:8000/api/login/'); try { - var response = await http.post(url, body: { - 'username': username, - 'password': password, - }); + var response = await http.post(url, + headers: { + 'Content-Type': 'application/json', + }, + body: jsonEncode({ + 'username': username, + 'password': password, + })); if (response.statusCode == 200) { var data = jsonDecode(response.body); print("Login bem-sucedido: $data"); diff --git a/frontend/sige_ie/lib/screens/maps.dart b/frontend/sige_ie/lib/screens/maps.dart new file mode 100644 index 00000000..e69de29b diff --git a/frontend/sige_ie/lib/screens/register.dart b/frontend/sige_ie/lib/screens/register.dart index fdb871e8..f8337358 100644 --- a/frontend/sige_ie/lib/screens/register.dart +++ b/frontend/sige_ie/lib/screens/register.dart @@ -20,15 +20,19 @@ class _RegisterScreenState extends State { final TextEditingController emailController = TextEditingController(); Future register( - String username, String name, String password, String email) async { - var url = Uri.parse('http://127.0.0.1:8000/api/users/'); + String username, String firstName, String password, String email) async { + var url = Uri.parse('http://10.0.2.2:8000/api/users/'); try { - var response = await http.post(url, body: { - 'username': username, - 'name': name, - 'password': password, - 'email': email, - }); + var response = await http.post(url, + headers: { + 'Content-Type': 'application/json', + }, + body: jsonEncode({ + 'username': username, + 'first_name': firstName, + 'password': password, + 'email': email, + })); if (response.statusCode == 200 || response.statusCode == 201) { var data = jsonDecode(response.body); print("Registro bem-sucedido: $data"); @@ -285,7 +289,7 @@ class _RegisterScreenState extends State { if (success) { Navigator.of(context).pushReplacementNamed( - '/home'); // Certifique-se de que esta é a rota correta. + '/loginScreen'); // Certifique-se de que esta é a rota correta. } else { ScaffoldMessenger.of(context) .showSnackBar( diff --git "a/frontend/sige_ie/lib/screens/\341\271\225roflile.dart" "b/frontend/sige_ie/lib/screens/\341\271\225roflile.dart" new file mode 100644 index 00000000..e69de29b From 989c3851afda0fb60f2093b69463f57f5d70ee34 Mon Sep 17 00:00:00 2001 From: EngDann Date: Tue, 2 Apr 2024 13:46:32 -0300 Subject: [PATCH 06/10] Resolucao bug --- frontend/sige_ie/lib/screens/login.dart | 1 - frontend/sige_ie/lib/screens/register.dart | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/frontend/sige_ie/lib/screens/login.dart b/frontend/sige_ie/lib/screens/login.dart index ef7e1502..1b3dc404 100644 --- a/frontend/sige_ie/lib/screens/login.dart +++ b/frontend/sige_ie/lib/screens/login.dart @@ -11,7 +11,6 @@ class LoginScreen extends StatefulWidget { class _LoginScreenState extends State { bool rememberMe = false; final _loginScreen = GlobalKey(); - final _loginFormKey = GlobalKey(); final TextEditingController usernameController = TextEditingController(); final TextEditingController passwordController = TextEditingController(); diff --git a/frontend/sige_ie/lib/screens/register.dart b/frontend/sige_ie/lib/screens/register.dart index f8337358..7d64fb70 100644 --- a/frontend/sige_ie/lib/screens/register.dart +++ b/frontend/sige_ie/lib/screens/register.dart @@ -1,7 +1,6 @@ import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; -import 'package:sige_ie/screens/login.dart'; import 'package:http/http.dart' as http; class RegisterScreen extends StatefulWidget { @@ -288,8 +287,9 @@ class _RegisterScreenState extends State { .hideCurrentSnackBar(); if (success) { - Navigator.of(context).pushReplacementNamed( - '/loginScreen'); // Certifique-se de que esta é a rota correta. + FocusScope.of(context).unfocus(); + Navigator.of(context) + .pushReplacementNamed('/loginScreen'); } else { ScaffoldMessenger.of(context) .showSnackBar( From 1e00464bc7445b6fe07d73347a86afe2aac893b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kauan=20Jos=C3=A9?= Date: Tue, 2 Apr 2024 13:57:34 -0300 Subject: [PATCH 07/10] fixing rooms --- api/places/models.py | 3 +++ api/places/serializers.py | 2 +- api/places/views.py | 4 ++-- api/sigeie/urls.py | 1 + api/systems/models.py | 3 +++ api/systems/serializers.py | 2 +- api/systems/views.py | 12 +++++++----- 7 files changed, 18 insertions(+), 9 deletions(-) diff --git a/api/places/models.py b/api/places/models.py index 8c75c1d1..901f0268 100644 --- a/api/places/models.py +++ b/api/places/models.py @@ -7,6 +7,9 @@ class Place(models.Model): name = models.CharField(max_length=50) user = models.ForeignKey(User, verbose_name=("creator"), on_delete=models.CASCADE) + def __str__(self): + return self.name + class Room(models.Model): name = models.CharField(max_length=50) diff --git a/api/places/serializers.py b/api/places/serializers.py index ce8ca9b2..39ef39d0 100644 --- a/api/places/serializers.py +++ b/api/places/serializers.py @@ -9,7 +9,7 @@ class Meta: class RoomSerializer(serializers.ModelSerializer): class Meta: model = Room - fields = ['id', 'name', 'floor', 'place_id', 'systems'] + fields = ['id', 'name', 'floor', 'systems', 'place'] extra_kwargs = { 'name': {'required': True}, 'floor': {'required': True}, diff --git a/api/places/views.py b/api/places/views.py index 475c5c8d..c4dbd123 100644 --- a/api/places/views.py +++ b/api/places/views.py @@ -14,7 +14,7 @@ class PlaceViewSet(viewsets.ModelViewSet): queryset = Place.objects.all() serializer_class = PlaceSerializer - permission_classes = [IsAuthenticated] + permission_classes = [] @action(detail=True, methods=['get']) def rooms(self, request, pk=None): @@ -32,4 +32,4 @@ def room(self, request, pk=None, room_pk=None): class RoomViewSet(viewsets.ModelViewSet): queryset = Room.objects.all() serializer_class = RoomSerializer - permission_classes = [IsAuthenticated] \ No newline at end of file + permission_classes = [] \ No newline at end of file diff --git a/api/sigeie/urls.py b/api/sigeie/urls.py index b7e1443d..85eb9ed4 100644 --- a/api/sigeie/urls.py +++ b/api/sigeie/urls.py @@ -23,4 +23,5 @@ path('api/', include('users.urls')), path('api/', include(router.urls)), path('auth/', include('rest_framework.urls')), + path('api/', include('systems.urls')) ] diff --git a/api/systems/models.py b/api/systems/models.py index 8519e21a..ed104f43 100644 --- a/api/systems/models.py +++ b/api/systems/models.py @@ -3,3 +3,6 @@ class System(models.Model): name = models.CharField(max_length=50) + + def __str__(self): + return self.name diff --git a/api/systems/serializers.py b/api/systems/serializers.py index 73107c82..a7e01212 100644 --- a/api/systems/serializers.py +++ b/api/systems/serializers.py @@ -4,4 +4,4 @@ class SystemSerializer(serializers.ModelSerializer): class Meta: model = System - fields = ['id', 'name', 'rooms'] + fields = ['id', 'name'] diff --git a/api/systems/views.py b/api/systems/views.py index a6dc6c60..9d14da17 100644 --- a/api/systems/views.py +++ b/api/systems/views.py @@ -1,11 +1,13 @@ -from django.shortcuts import render - -from rest_framework import viewsets - +from rest_framework import viewsets, generics from .models import System from .serializers import SystemSerializer -class SystemViewSet(viewsets.ModelViewSet): +class SystemViewList(generics.ListAPIView): + queryset = System.objects.all() + serializer_class = SystemSerializer + permission_classes = [] + +class SystemViewDetail(generics.RetrieveAPIView): queryset = System.objects.all() serializer_class = SystemSerializer permission_classes = [] \ No newline at end of file From f0ccf5d5baff3fe83025922cfcd1cb5818aa300a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kauan=20Jos=C3=A9?= Date: Tue, 2 Apr 2024 13:59:14 -0300 Subject: [PATCH 08/10] ajustando2 --- api/systems/urls.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 api/systems/urls.py diff --git a/api/systems/urls.py b/api/systems/urls.py new file mode 100644 index 00000000..0f12d8fa --- /dev/null +++ b/api/systems/urls.py @@ -0,0 +1,8 @@ +from django.urls import path, include +from .views import SystemViewDetail, SystemViewList + +urlpatterns = [ + path('systems/', SystemViewList.as_view()), + path('systems//', SystemViewDetail.as_view()) +] + From a458bf0c3d7bcb0b66c966edacb54f17b58413a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kauan=20Jos=C3=A9?= Date: Wed, 3 Apr 2024 11:50:08 -0300 Subject: [PATCH 09/10] Correge CSRF --- api/sigeie/settings.py | 3 +-- api/sigeie/urls.py | 4 ++-- api/users/models.py | 3 ++- api/users/serializers.py | 12 ++++++++++++ api/users/views.py | 38 ++++++++++++++++++++------------------ 5 files changed, 37 insertions(+), 23 deletions(-) diff --git a/api/sigeie/settings.py b/api/sigeie/settings.py index ecc98239..30273ec0 100644 --- a/api/sigeie/settings.py +++ b/api/sigeie/settings.py @@ -113,11 +113,10 @@ REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': [ - 'rest_framework.authentication.BasicAuthentication', 'rest_framework.authentication.SessionAuthentication', ], 'DEFAULT_PERMISSION_CLASSES': { - 'rest_framework.permissions.IsAUthenticatedOrReadOnly', + 'rest_framework.permissions.IsAuthenticatedOrReadOnly', } } diff --git a/api/sigeie/urls.py b/api/sigeie/urls.py index 85eb9ed4..c44d28d7 100644 --- a/api/sigeie/urls.py +++ b/api/sigeie/urls.py @@ -22,6 +22,6 @@ path('admin/', admin.site.urls), path('api/', include('users.urls')), path('api/', include(router.urls)), - path('auth/', include('rest_framework.urls')), - path('api/', include('systems.urls')) + path('api/', include('systems.urls')), + path('auth/', include('rest_framework.urls')) ] diff --git a/api/users/models.py b/api/users/models.py index 508029f6..41229132 100644 --- a/api/users/models.py +++ b/api/users/models.py @@ -1,5 +1,6 @@ from django.db import models -# Create your models here. +# Create your models here + diff --git a/api/users/serializers.py b/api/users/serializers.py index 2c30b80a..705c1c4c 100644 --- a/api/users/serializers.py +++ b/api/users/serializers.py @@ -15,3 +15,15 @@ class Meta: 'date_joined': {'read_only': True}, 'groups': {'read_only': True} } + + def create(self, validated_data): + user = User.objects.create_user( + username=validated_data['username'], + password=validated_data['password'], + email=validated_data.get('email') # use get se o email for opcional + ) + return user + +class UserSerializerP(serializers.Serializer): + username = serializers.CharField(max_length=200) + password = serializers.CharField(max_length=200) \ No newline at end of file diff --git a/api/users/views.py b/api/users/views.py index 842e8600..c6120c26 100644 --- a/api/users/views.py +++ b/api/users/views.py @@ -1,47 +1,49 @@ # views.py +from django.http import JsonResponse from rest_framework import viewsets, permissions, status from rest_framework.views import APIView from rest_framework.response import Response from rest_framework.permissions import IsAuthenticated from rest_framework.authentication import BasicAuthentication from rest_framework import generics - +from django.views.decorators.csrf import csrf_protect, csrf_exempt from .permissions import IsOwner -from .serializers import UserSerializer +from .serializers import UserSerializer, UserSerializerP from django.contrib.auth.models import User from django.contrib.auth import authenticate, login, logout -from django.views.decorators.csrf import csrf_exempt from django.utils.decorators import method_decorator -@method_decorator(csrf_exempt, name='dispatch') +@method_decorator(csrf_protect, name='dispatch') class UserCreateView(generics.CreateAPIView): queryset = User.objects.all() serializer_class = UserSerializer permission_classes = [] authentication_classes = [] -@method_decorator(csrf_exempt, name='dispatch') +@method_decorator(csrf_protect, name='dispatch') class UserDetailView(generics.RetrieveUpdateDestroyAPIView): queryset = User.objects.all() serializer_class = UserSerializer permission_classes = [IsOwner, IsAuthenticated] -@method_decorator(csrf_exempt, name='dispatch') +@method_decorator(csrf_protect, name='dispatch') class LoginView(APIView): - authentication_classes = [] permission_classes = [] - - def post(self, request, format=None): - username = request.data.get('username') - password = request.data.get('password') - user = authenticate(username=username, password=password) - if user is not None: - login(request, user) - return Response({'message': 'Login successful'}, status=status.HTTP_200_OK) - else: - return Response({'message': 'Invalid credentials'}, status=status.HTTP_401_UNAUTHORIZED) - + def post(self, request, format=None): + serializer = UserSerializerP(data=request.data) + if(serializer.is_valid()): + username = serializer.validated_data["username"] + password = serializer.validated_data["password"] + user = authenticate(username=username, password=password) + if user is not None: + login(request, user) + return Response({'message': 'Login successful'}, status=status.HTTP_200_OK) + else: + print(user) + return Response({'message': 'Invalid credentials'}, status=status.HTTP_401_UNAUTHORIZED) + return JsonResponse(serializer.errors) + class LogoutView(APIView): permission_classes = [permissions.IsAuthenticated] From 230a9fbbe59f71386ac2c0c582ecaa611e6e1edc Mon Sep 17 00:00:00 2001 From: ramires Date: Wed, 3 Apr 2024 12:26:49 -0300 Subject: [PATCH 10/10] Corrigir branch --- frontend/sige_ie/lib/screens/facilities.dart | 0 frontend/sige_ie/lib/screens/home.dart | 0 frontend/sige_ie/lib/screens/login.dart | 264 ------------- frontend/sige_ie/lib/screens/maps.dart | 0 frontend/sige_ie/lib/screens/register.dart | 359 ------------------ .../lib/screens/\341\271\225roflile.dart" | 0 6 files changed, 623 deletions(-) delete mode 100644 frontend/sige_ie/lib/screens/facilities.dart delete mode 100644 frontend/sige_ie/lib/screens/home.dart delete mode 100644 frontend/sige_ie/lib/screens/login.dart delete mode 100644 frontend/sige_ie/lib/screens/maps.dart delete mode 100644 frontend/sige_ie/lib/screens/register.dart delete mode 100644 "frontend/sige_ie/lib/screens/\341\271\225roflile.dart" diff --git a/frontend/sige_ie/lib/screens/facilities.dart b/frontend/sige_ie/lib/screens/facilities.dart deleted file mode 100644 index e69de29b..00000000 diff --git a/frontend/sige_ie/lib/screens/home.dart b/frontend/sige_ie/lib/screens/home.dart deleted file mode 100644 index e69de29b..00000000 diff --git a/frontend/sige_ie/lib/screens/login.dart b/frontend/sige_ie/lib/screens/login.dart deleted file mode 100644 index 1b3dc404..00000000 --- a/frontend/sige_ie/lib/screens/login.dart +++ /dev/null @@ -1,264 +0,0 @@ -import 'dart:convert'; -import 'package:flutter/material.dart'; -import 'package:http/http.dart' as http; - -class LoginScreen extends StatefulWidget { - const LoginScreen({Key? key}) : super(key: key); - @override - State createState() => _LoginScreenState(); -} - -class _LoginScreenState extends State { - bool rememberMe = false; - final _loginScreen = GlobalKey(); - final TextEditingController usernameController = TextEditingController(); - final TextEditingController passwordController = TextEditingController(); - - Future login(String username, String password) async { - var url = Uri.parse('http://10.0.2.2:8000/api/login/'); - try { - var response = await http.post(url, - headers: { - 'Content-Type': 'application/json', - }, - body: jsonEncode({ - 'username': username, - 'password': password, - })); - if (response.statusCode == 200) { - var data = jsonDecode(response.body); - print("Login bem-sucedido: $data"); - return true; - } else { - print("Falha no login: ${response.body}"); - return false; - } - } catch (e) { - print("Erro ao tentar fazer login: $e"); - return false; - } - } - - @override - Widget build(BuildContext context) { - return Scaffold( - backgroundColor: const Color(0xff123c75), - appBar: AppBar( - iconTheme: IconThemeData(color: Colors.white), - backgroundColor: const Color(0xff123c75), - ), - body: Center( - child: Column( - children: [ - Expanded( - flex: 2, - child: Container( - decoration: BoxDecoration( - image: DecorationImage( - image: AssetImage('assets/1000x1000.png'), - fit: BoxFit.cover, - ), - ), - ), - ), - Expanded( - flex: 6, - child: Container( - padding: const EdgeInsets.fromLTRB(25.0, 50.0, 25.0, 20.0), - decoration: const BoxDecoration( - color: Colors.white, - borderRadius: - BorderRadius.only(topLeft: Radius.circular(50.0))), - child: SingleChildScrollView( - child: Form( - key: _loginScreen, - child: Column( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Text( - 'Login', - style: TextStyle( - fontSize: 30.0, - fontWeight: FontWeight.w900, - color: Colors.black), - ), - const SizedBox(height: 35), - TextFormField( - controller: usernameController, - validator: (value) { - if (value == null || value.isEmpty) { - return 'Por favor, insira um username válido'; - } - return null; - }, - decoration: InputDecoration( - label: const Text('Username'), - labelStyle: const TextStyle(color: Colors.black), - hintText: 'Insira o seu username', - hintStyle: const TextStyle( - color: Colors.black, - ), - border: OutlineInputBorder( - borderSide: const BorderSide( - color: Color.fromARGB(255, 39, 38, 38), - ), - borderRadius: BorderRadius.circular(10), - ), - enabledBorder: OutlineInputBorder( - borderSide: const BorderSide( - color: Color.fromARGB(255, 0, 0, 0), - ), - borderRadius: BorderRadius.circular(10), - ), - )), - const SizedBox(height: 20), - TextFormField( - controller: passwordController, - obscureText: true, - obscuringCharacter: '*', - validator: (value) { - if (value == null || value.isEmpty) { - return 'Por favor, insira uma senha válida'; - } - return null; - }, - decoration: InputDecoration( - label: const Text('Senha'), - labelStyle: const TextStyle(color: Colors.black), - hintText: 'Insira a senha', - hintStyle: const TextStyle( - color: Color.fromARGB(255, 0, 0, 0), - ), - border: OutlineInputBorder( - borderSide: const BorderSide( - color: Color.fromARGB(31, 255, 3, 3), - ), - borderRadius: BorderRadius.circular(10), - ), - enabledBorder: OutlineInputBorder( - borderSide: const BorderSide( - color: Color.fromARGB(255, 0, 0, 0), - ), - borderRadius: BorderRadius.circular(10), - ), - ), - ), - const SizedBox(height: 20), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Row( - children: [ - Checkbox( - value: rememberMe, - onChanged: (bool? value) { - setState(() { - rememberMe = value!; - }); - }, - activeColor: - Color.fromARGB(255, 12, 78, 170)), - const Text( - 'Manter conectado', - style: TextStyle( - color: Color.fromARGB(255, 0, 0, 0), - ), - ), - ], - ), - GestureDetector( - child: Text( - 'Esqueceu a senha?', - style: TextStyle( - fontWeight: FontWeight.bold, - color: Color(0xff123c75), - ), - ), - ), - ], - ), - const SizedBox(height: 20), - SizedBox( - width: 200, - height: 50, - child: ElevatedButton( - onPressed: () async { - if (_loginScreen.currentState!.validate()) { - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar( - content: Text('Processando dados')), - ); - - bool success = await login( - usernameController.text, - passwordController.text); - - ScaffoldMessenger.of(context) - .hideCurrentSnackBar(); - - if (success) { - Navigator.of(context) - .pushReplacementNamed('/?'); - } else { - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar( - content: Text( - 'Login falhou, verifique suas credenciais')), - ); - } - } else { - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar( - content: Text( - 'Por favor, preencha todos os campos')), - ); - } - }, - child: const Text( - 'Login', - style: TextStyle( - fontSize: 20, fontWeight: FontWeight.bold), - ), - style: ElevatedButton.styleFrom( - elevation: 6, - backgroundColor: - Color.fromARGB(255, 244, 248, 0), - foregroundColor: Color(0xff123c75), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(12), - )), - ), - ), - const SizedBox(height: 30), - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const Text( - 'Não tem uma conta? ', - style: TextStyle( - color: Color.fromARGB(255, 0, 0, 0)), - ), - GestureDetector( - onTap: () { - Navigator.pushNamed( - context, '/registerScreen'); - }, - child: Text( - 'Registre-se', - style: TextStyle( - fontWeight: FontWeight.bold, - color: const Color(0xff123c75), - ), - ), - ), - ]) - ], - ), - )), - )) - ], - ), - ), - ); - } -} diff --git a/frontend/sige_ie/lib/screens/maps.dart b/frontend/sige_ie/lib/screens/maps.dart deleted file mode 100644 index e69de29b..00000000 diff --git a/frontend/sige_ie/lib/screens/register.dart b/frontend/sige_ie/lib/screens/register.dart deleted file mode 100644 index 7d64fb70..00000000 --- a/frontend/sige_ie/lib/screens/register.dart +++ /dev/null @@ -1,359 +0,0 @@ -import 'dart:convert'; -import 'package:flutter/material.dart'; -import 'package:flutter/widgets.dart'; -import 'package:http/http.dart' as http; - -class RegisterScreen extends StatefulWidget { - const RegisterScreen({super.key}); - @override - State createState() => _RegisterScreenState(); -} - -// Definição da classe da tela de Registro -class _RegisterScreenState extends State { - bool terms = true; - final _registerScreen = GlobalKey(); - final TextEditingController usernameController = TextEditingController(); - final TextEditingController nameController = TextEditingController(); - final TextEditingController passwordController = TextEditingController(); - final TextEditingController emailController = TextEditingController(); - - Future register( - String username, String firstName, String password, String email) async { - var url = Uri.parse('http://10.0.2.2:8000/api/users/'); - try { - var response = await http.post(url, - headers: { - 'Content-Type': 'application/json', - }, - body: jsonEncode({ - 'username': username, - 'first_name': firstName, - 'password': password, - 'email': email, - })); - if (response.statusCode == 200 || response.statusCode == 201) { - var data = jsonDecode(response.body); - print("Registro bem-sucedido: $data"); - return true; - } else { - print("Falha no registro: ${response.body}"); - return false; - } - } catch (e) { - print("Erro ao tentar registrar: $e"); - return false; - } - } - - @override - Widget build(BuildContext context) { - return Scaffold( - backgroundColor: const Color(0xff123c75), - appBar: AppBar( - iconTheme: IconThemeData(color: Colors.white), - backgroundColor: const Color(0xff123c75), - ), - body: Center( - // Logo da Página e Seu Formato - child: Column( - children: [ - Expanded( - flex: 2, - child: Container( - decoration: BoxDecoration( - image: DecorationImage( - image: AssetImage('assets/1000x1000.png'), - fit: BoxFit.cover, - ), - ), - ), - ), - Expanded( - flex: 6, // Configuração da página - child: Container( - padding: const EdgeInsets.fromLTRB(25.0, 50.0, 25.0, 20.0), - decoration: const BoxDecoration( - color: Colors.white, - borderRadius: - BorderRadius.only(topLeft: Radius.circular(50.0))), - child: SingleChildScrollView( - child: Form( - key: _registerScreen, - child: Column( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Text('Registro', // Nome da Página de Registro - style: TextStyle( - fontSize: 30.0, - fontWeight: FontWeight.w900, - color: Colors.black)), - const SizedBox(height: 35), - TextFormField( - controller: usernameController, - decoration: InputDecoration( - label: const Text('Username'), - labelStyle: const TextStyle(color: Colors.black), - hintText: 'Insira o seu username', - hintStyle: const TextStyle( - color: Colors.black, - ), - border: OutlineInputBorder( - borderSide: const BorderSide( - color: Color.fromARGB(255, 39, 38, 38), - ), - borderRadius: BorderRadius.circular(10), - ), - enabledBorder: OutlineInputBorder( - borderSide: const BorderSide( - color: Color.fromARGB(255, 0, 0, 0), - ), - borderRadius: BorderRadius.circular(10), - ), - // Outras propriedades... - ), - validator: (value) { - if (value == null || value.isEmpty) { - return 'Por favor, insira um username válido'; - } - return null; - }, - ), - const SizedBox(height: 20), - - // Campo de nome e decoração da borda de inserção dos dados - TextFormField( - controller: nameController, - decoration: InputDecoration( - label: const Text('Nome'), - labelStyle: const TextStyle(color: Colors.black), - hintText: 'Insira seu Nome', - hintStyle: const TextStyle( - color: Colors.black, - ), - border: OutlineInputBorder( - borderSide: const BorderSide( - color: Color.fromARGB(255, 39, 38, 38), - ), - borderRadius: BorderRadius.circular(10), - ), - enabledBorder: OutlineInputBorder( - borderSide: const BorderSide( - color: Color.fromARGB(255, 0, 0, 0), - ), - borderRadius: BorderRadius.circular(10), - ), - // Outras propriedades... - ), - validator: (value) { - if (value == null || value.isEmpty) { - return 'Por Favor Insira seu Nome'; - } - return null; - }, - ), - const SizedBox(height: 20), - TextFormField( - controller: emailController, - validator: (value) { - if (value == null || value.isEmpty) { - return 'Insira um email valido'; - } - return null; - }, - decoration: InputDecoration( - label: const Text('Email'), - labelStyle: - const TextStyle(color: Colors.black), - hintText: 'Insira o Email', - hintStyle: const TextStyle( - color: Colors.black, - ), - border: OutlineInputBorder( - borderSide: const BorderSide( - color: Color.fromARGB(255, 39, 38, 38), - ), - borderRadius: BorderRadius.circular(10), - ), - enabledBorder: OutlineInputBorder( - borderSide: const BorderSide( - color: Color.fromARGB(255, 0, 0, 0), - ), - borderRadius: BorderRadius.circular(10), - ), - )), - const SizedBox(height: 20), - TextFormField( - controller: passwordController, - obscureText: true, - obscuringCharacter: '*', - validator: (value) { - if (value == null || value.isEmpty) { - return 'Por Favor, insira uma senha valida'; - } - return null; - }, - decoration: InputDecoration( - label: const Text('Senha'), - labelStyle: const TextStyle(color: Colors.black), - hintText: 'Insira a senha', - hintStyle: const TextStyle( - color: Color.fromARGB(255, 0, 0, 0), - ), - border: OutlineInputBorder( - borderSide: const BorderSide( - color: Color.fromARGB(31, 255, 3, 3), - ), - borderRadius: BorderRadius.circular(10), - ), - enabledBorder: OutlineInputBorder( - borderSide: const BorderSide( - color: Color.fromARGB(255, 0, 0, 0), - ), - borderRadius: BorderRadius.circular(10)), - ), - ), - const SizedBox(height: 20), - TextFormField( - obscureText: true, - obscuringCharacter: '*', - validator: (value) { - if (value == null || - value.isEmpty || - value != passwordController.text) { - return 'As senhas não coincidem'; - } - return null; - }, - decoration: InputDecoration( - label: const Text('Confirmar Senha'), - labelStyle: const TextStyle(color: Colors.black), - hintText: 'Confirme sua senha', - hintStyle: const TextStyle( - color: Color.fromARGB(255, 0, 0, 0), - ), - border: OutlineInputBorder( - borderSide: const BorderSide( - color: Color.fromARGB(31, 255, 3, 3), - ), - borderRadius: BorderRadius.circular(10), - ), - ), - ), - const SizedBox(height: 20), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Row( - children: [ - Checkbox( - value: terms, - onChanged: (bool? value) { - setState(() { - terms = value!; - }); - }, - activeColor: - Color.fromARGB(255, 12, 78, 170)), - const Text( - 'Aceite os Termos', - style: TextStyle( - color: const Color(0xff123c75), - ), - ), - ], - ), - ], - ), - const SizedBox(height: 20), - SizedBox( - width: 200, - height: 50, - child: ElevatedButton( - onPressed: () async { - if (_registerScreen.currentState!.validate()) { - if (terms) { - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar( - content: Text('Processando Dados'), - ), - ); - bool success = await register( - usernameController.text, - nameController.text, - passwordController.text, - emailController.text); - ScaffoldMessenger.of(context) - .hideCurrentSnackBar(); - - if (success) { - FocusScope.of(context).unfocus(); - Navigator.of(context) - .pushReplacementNamed('/loginScreen'); - } else { - ScaffoldMessenger.of(context) - .showSnackBar( - const SnackBar( - content: Text( - 'Registro falhou, por favor tente novamente.'), - ), - ); - } - } else { - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar( - content: Text( - 'Por Favor, concorde com o processamento de dados pessoais'), - ), - ); - } - } - }, - child: const Text( - 'Registro', - style: TextStyle( - fontSize: 20, fontWeight: FontWeight.bold), - ), - style: ElevatedButton.styleFrom( - elevation: 6, - backgroundColor: - Color.fromARGB(255, 244, 248, 0), - foregroundColor: Color(0xff123c75), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(12), - )), - ), - ), - const SizedBox(height: 30), - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const Text( - 'Já tem uma conta? ', - style: TextStyle( - color: Color.fromARGB(255, 0, 0, 0)), - ), - GestureDetector( - onTap: () { - Navigator.pushNamed(context, '/loginScreen'); - }, - child: Text( - 'Fazer login', - style: TextStyle( - fontWeight: FontWeight.bold, - color: const Color(0xff123c75), - ), - ), - ), - ], - ), - const SizedBox(height: 10), - ], - ), - )), - )) - ], - ), - )); - } -} diff --git "a/frontend/sige_ie/lib/screens/\341\271\225roflile.dart" "b/frontend/sige_ie/lib/screens/\341\271\225roflile.dart" deleted file mode 100644 index e69de29b..00000000