diff --git a/lib/Controller/LoginController.dart b/lib/Controller/LoginController.dart index 1078375..3f619cd 100644 --- a/lib/Controller/LoginController.dart +++ b/lib/Controller/LoginController.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:http/retry.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:organizei/Controller/Base/Base.dart'; import 'package:organizei/Controller/DeviceDetailsController.dart'; @@ -23,19 +24,15 @@ class LoginController extends Base { var controllerSenha = TextEditingController(); Future autentica() async { - /* if (!formKey.currentState!.validate()) { + if (!formKey.currentState!.validate()) { return false; - }*/ + } formKey.currentState!.save(); SharedPreferences prefs = await SharedPreferences.getInstance(); try { - //showReloadDialog(context, 'Realizando login, aguarde...'); - //model.cpfcnpj = prefs.getString('EmpresaCpfcnpj'); - - //model.chaveCentralizador = prefs.getString('EmpresaChaveCentralizador'); bool ret = await repository.autenticar(model); if (!ret) { @@ -90,11 +87,13 @@ class LoginController extends Base { return loginConfiguracoes.getLogin(); } - _limpaPreferencesLogin(LoginModel login) async { + limpaPreferencesLogin() async { var prefs = await SharedPreferences.getInstance(); prefs.setString('usuario', ''); prefs.setString('senha', ''); + prefs.setString('apelido', ''); + prefs.setString('token', ''); } Future getUsuarioLogado() async { diff --git a/lib/Model/API/APIModel.dart b/lib/Model/API/APIModel.dart index 005c58e..7e2fc06 100644 --- a/lib/Model/API/APIModel.dart +++ b/lib/Model/API/APIModel.dart @@ -1,6 +1,6 @@ class ApiModel { - //static const ApiUrl = "http://10.0.0.91:4444"; - static const ApiUrl = "http://192.168.100.74:4444"; + static const ApiUrl = "http://10.0.0.91:4444"; + //static const ApiUrl = "http://192.168.100.74:4444"; //static const ApiUrl = "http://192.168.100.82:4444"; static const String _token = "fd7bc88b7c0149adbc134d5d0a919814"; static const Map headers = { diff --git a/lib/Model/API/ResponseAPIModel.dart b/lib/Model/API/ResponseAPIModel.dart index 28d5781..73b977d 100644 --- a/lib/Model/API/ResponseAPIModel.dart +++ b/lib/Model/API/ResponseAPIModel.dart @@ -12,9 +12,9 @@ class ResponseAPIModel { Map toJson() { final Map data = new Map(); - data['valido'] = this.valido; - data['msg'] = this.msg; - data['statusCode'] = this.statusCode; + data['valido'] = valido; + data['msg'] = msg; + data['statusCode'] = statusCode; return data; } diff --git a/lib/components/dialogs/login/entrarDialog.dart b/lib/components/dialogs/login/entrarDialog.dart new file mode 100644 index 0000000..b47e5b0 --- /dev/null +++ b/lib/components/dialogs/login/entrarDialog.dart @@ -0,0 +1,90 @@ +import 'package:flutter/material.dart'; +import 'package:organizei/Controller/LoginController.dart'; +import 'package:organizei/Repository/LoginRepository.dart'; +import 'package:organizei/components/botao.dart'; +import 'package:organizei/components/dialog_personalizado.dart'; +import 'package:organizei/components/input.dart'; +import 'package:organizei/home_page.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + +Future entrar(BuildContext context) { + late LoginController loginController; + + loginController = LoginController(LoginRepository(), context); + + return showDialog( + barrierDismissible: false, + barrierColor: Colors.white.withOpacity(0), + context: context, + builder: (context) { + return Scaffold( + backgroundColor: Colors.transparent, + body: SingleChildScrollView( + scrollDirection: Axis.vertical, + child: Material( + type: MaterialType.transparency, + child: Material( + type: MaterialType.transparency, + child: Form( + key: loginController.formKey, + child: Padding( + padding: const EdgeInsets.only(top: 24.0), + child: ConstrainedBox( + constraints: BoxConstraints( + minHeight: MediaQuery.of(context).size.height, + ), + child: DialogPersonalizado( + nome: 'Login', + //minHeight: MediaQuery.of(context).size.height * 0.8, + child: [ + Padding( + padding: EdgeInsets.only(bottom: 16), + child: input( + onSaved: loginController.loginUsuario, + textController: + loginController.controllerUsuario, + label: 'e-mail', + ), + ), + Padding( + padding: EdgeInsets.only(bottom: 16), + child: input( + onSaved: loginController.loginSenha, + textController: + loginController.controllerSenha, + label: 'senha', + senha: true), + ), + Padding( + padding: const EdgeInsets.fromLTRB(0, 0, 0, 16.0), + child: Botao( + texto: 'Entrar', + cor: const Color(0xFF6BC8E4), + clicar: () async { + bool succes = + await loginController.autentica(); + SharedPreferences prefs = + await SharedPreferences.getInstance(); + + if (succes) { + Navigator.of(context).push( + MaterialPageRoute( + builder: (BuildContext context) => + const HomePage(), + ), + ); + } + ; + }, + ), + ) + ], + ), + ), + ), + ), + ), + ), + )); + }); +} diff --git a/lib/components/dialogs/login/sairDialog.dart b/lib/components/dialogs/login/sairDialog.dart new file mode 100644 index 0000000..f451868 --- /dev/null +++ b/lib/components/dialogs/login/sairDialog.dart @@ -0,0 +1,80 @@ +import 'package:flutter/material.dart'; +import 'package:organizei/Controller/LoginController.dart'; +import 'package:organizei/Model/Tarefa/TarefaModel.dart'; +import 'package:organizei/Model/Usuario/UsuarioModel.dart'; +import 'package:organizei/Repository/LoginRepository.dart'; +import 'package:organizei/Repository/TarefaRepository.dart'; +import 'package:organizei/components/botao.dart'; +import 'package:organizei/components/dialog_personalizado.dart'; +import 'package:organizei/components/dialogs/login/usuarioCadastroDialog.dart'; +import 'package:organizei/components/dialogs/tarefas/tarefaCadastroDialog.dart'; +import 'package:organizei/start_page.dart'; +import '../../../Controller/TarefaController.dart'; + +Future sair(BuildContext context, {Function? fecharDialog}) { + UsuarioModel? usuario; + + late LoginController loginController; + + loginController = LoginController(LoginRepository(), context); + return showDialog( + barrierDismissible: false, + barrierColor: Colors.white.withOpacity(0), + context: context, + builder: (context) { + return StatefulBuilder(builder: (context, StateSetter setState) { + return Scaffold( + backgroundColor: Colors.transparent, + body: SingleChildScrollView( + scrollDirection: Axis.vertical, + child: Material( + type: MaterialType.transparency, + child: Padding( + padding: const EdgeInsets.only(top: 24.0), + child: ConstrainedBox( + constraints: BoxConstraints( + minHeight: MediaQuery.of(context).size.height, + ), + child: DialogPersonalizado( + nome: '', + cor: '', + child: [ + Botao( + texto: 'Editar perfil', + cor: const Color(0xFF6385C3), + clicar: () async { + cadastrarUsuario(context, + usuario: usuario, fecharDialog: fecharDialog); + }, + ), + Padding( + padding: const EdgeInsets.only(bottom: 16, top: 16), + child: Botao( + texto: 'Sair', + cor: const Color(0xFFEF7E69), + clicar: () async { + await loginController.limpaPreferencesLogin(); + + Navigator.pushAndRemoveUntil( + context, + MaterialPageRoute( + builder: (_) => const StartPage()), + (route) => false); + + // if (succes == true) { + // Navigator.pop(context); + // fecharDialog!(); + // } + }, + ), + ), + ], + ), + ), + ), + ), + ), + ); + }); + }); +} diff --git a/lib/components/dialogs/login/usuarioCadastroDialog.dart b/lib/components/dialogs/login/usuarioCadastroDialog.dart new file mode 100644 index 0000000..d3ebf6f --- /dev/null +++ b/lib/components/dialogs/login/usuarioCadastroDialog.dart @@ -0,0 +1,93 @@ +import 'package:flutter/material.dart'; +import 'package:organizei/Controller/UsuarioController.dart'; +import 'package:organizei/Model/Usuario/UsuarioModel.dart'; +import 'package:organizei/Repository/UsuarioRepository.dart'; +import 'package:organizei/components/botao.dart'; +import 'package:organizei/components/dialog_personalizado.dart'; +import 'package:organizei/components/dialogs/login/entrarDialog.dart'; +import 'package:organizei/components/input.dart'; + +Future cadastrarUsuario(BuildContext context, + {UsuarioModel? usuario, Function? fecharDialog}) { + late UsuarioController usuarioController; + usuarioController = UsuarioController(UsuarioRepository(), context); + + return showDialog( + barrierDismissible: false, + barrierColor: Colors.white.withOpacity(0), + context: context, + builder: (context) { + return Scaffold( + backgroundColor: Colors.transparent, + body: SingleChildScrollView( + scrollDirection: Axis.vertical, + child: Material( + type: MaterialType.transparency, + child: Form( + key: usuarioController.formKey, + child: Padding( + padding: const EdgeInsets.only(top: 24.0), + child: ConstrainedBox( + constraints: BoxConstraints( + minHeight: MediaQuery.of(context).size.height, + ), + child: DialogPersonalizado( + nome: 'Cadastro', + //minHeight: MediaQuery.of(context).size.height * 0.8, + child: [ + Padding( + padding: const EdgeInsets.only(bottom: 16), + child: input( + onSaved: usuarioController.usuarioNome, + textController: usuarioController.controllerNome, + label: 'nome', + ), + ), + Padding( + padding: const EdgeInsets.only(bottom: 16), + child: input( + onSaved: usuarioController.usuarioApelido, + textController: usuarioController.controllerApelido, + label: 'apelido', + ), + ), + Padding( + padding: const EdgeInsets.only(bottom: 16), + child: input( + onSaved: usuarioController.usuarioEmail, + textController: usuarioController.controllerEmail, + label: 'e-mail', + ), + //child: Input(label: 'e-mail'), + ), + Padding( + padding: const EdgeInsets.only(bottom: 16), + child: input( + onSaved: usuarioController.usuarioSenha, + textController: usuarioController.controllerSenha, + label: 'senha', + senha: true), + //child: Input(label: 'senha'), + ), + Botao( + texto: 'Cadastrar', + cor: const Color(0xFF6BC8E4), + clicar: () async { + bool succes = await usuarioController.saveUsuario(); + + if (succes == true) { + Navigator.pop(context); + entrar(context); + } + }, + ), + ], + ), + ), + ), + ), + ), + ), + ); + }); +} diff --git a/lib/components/dialogs/tarefas/tarefaCadastroDialog.dart b/lib/components/dialogs/tarefas/tarefaCadastroDialog.dart index 9ef7e98..dbb3543 100644 --- a/lib/components/dialogs/tarefas/tarefaCadastroDialog.dart +++ b/lib/components/dialogs/tarefas/tarefaCadastroDialog.dart @@ -10,7 +10,7 @@ import 'package:organizei/components/selectPrioridade.dart'; import '../../../Controller/TarefaController.dart'; Future criarTarefa(BuildContext context, - {TarefaModel? tarefa = null, Function? fecharDialog = null}) { + {TarefaModel? tarefa, Function? fecharDialog}) { late TarefaController tarefaController; tarefaController = TarefaController(TarefaRepository(), context); diff --git a/lib/home_page.dart b/lib/home_page.dart index 7205463..4a01313 100644 --- a/lib/home_page.dart +++ b/lib/home_page.dart @@ -12,6 +12,8 @@ import 'package:intl/intl.dart'; import 'package:organizei/components/dialogs/atividades/atividadeDialog.dart'; import 'package:organizei/components/dialogs/habitos/habitoDialog.dart'; import 'package:organizei/components/dialogs/lembretes/lembreteDialog.dart'; +import 'package:organizei/components/dialogs/login/entrarDialog.dart'; +import 'package:organizei/components/dialogs/login/sairDialog.dart'; import 'package:organizei/components/dialogs/tarefas/tarefaDialog.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -114,18 +116,27 @@ class _HomePageState extends State { mainAxisAlignment: MainAxisAlignment.end, crossAxisAlignment: CrossAxisAlignment.end, children: [ - Container( - width: 40, - height: 40, - decoration: BoxDecoration( - shape: BoxShape.circle, - color: Color(0xFFE9E9E9), - border: Border.all( - width: 3, - color: Colors.black, - style: BorderStyle.solid, - )), + GestureDetector( + child: Icon( + Icons.settings, + size: 32, + ), + onTap: () { + sair(context); + }, ) + // Container( + // width: 40, + // height: 40, + // decoration: BoxDecoration( + // shape: BoxShape.circle, + // color: Color(0xFFE9E9E9), + // border: Border.all( + // width: 3, + // color: Colors.black, + // style: BorderStyle.solid, + // )), + // ) ], ), ], diff --git a/lib/start_page.dart b/lib/start_page.dart index 4d9f1fd..95f469b 100644 --- a/lib/start_page.dart +++ b/lib/start_page.dart @@ -5,6 +5,8 @@ import 'package:organizei/Repository/LoginRepository.dart'; import 'package:organizei/Repository/UsuarioRepository.dart'; import 'package:organizei/components/botao.dart'; import 'package:organizei/components/dialog_personalizado.dart'; +import 'package:organizei/components/dialogs/login/entrarDialog.dart'; +import 'package:organizei/components/dialogs/login/usuarioCadastroDialog.dart'; import 'package:organizei/components/input.dart'; import 'package:organizei/home_page.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -73,165 +75,11 @@ class _StartPageState extends State { texto: 'Cadastrar', cor: const Color(0xFF6385C3), clicar: () { - cadastrar(context); + cadastrarUsuario(context); }, ), ]), )), ); } - - Future entrar(BuildContext context) { - setState(() {}); - return showDialog( - barrierDismissible: false, - barrierColor: Colors.white.withOpacity(0), - context: context, - builder: (context) { - return Scaffold( - backgroundColor: Colors.transparent, - body: SingleChildScrollView( - scrollDirection: Axis.vertical, - child: Material( - type: MaterialType.transparency, - child: Material( - type: MaterialType.transparency, - child: Form( - key: controller.formKey, - child: Container( - margin: const EdgeInsets.only(top: 24), - height: MediaQuery.of(context).size.height, - child: DialogPersonalizado( - nome: 'Login', - //minHeight: MediaQuery.of(context).size.height * 0.8, - child: [ - Padding( - padding: EdgeInsets.only(bottom: 16), - child: input( - onSaved: controller.loginUsuario, - textController: controller.controllerUsuario, - label: 'e-mail', - ), - ), - Padding( - padding: EdgeInsets.only(bottom: 16), - child: input( - onSaved: controller.loginSenha, - textController: controller.controllerSenha, - label: 'senha', - senha: true), - ), - Padding( - padding: const EdgeInsets.fromLTRB(0, 0, 0, 16.0), - child: Botao( - texto: 'Entrar', - cor: const Color(0xFF6BC8E4), - clicar: () async { - bool succes = await controller.autentica(); - SharedPreferences prefs = - await SharedPreferences.getInstance(); - - apelido = prefs.getString('UsuarioApelido'); - - if (succes) { - Navigator.of(context).push( - MaterialPageRoute( - builder: (BuildContext context) => - HomePage(), - ), - ); - } - ; - }, - ), - ) - ], - ), - ), - ), - ), - ), - )); - }); - } - - Future cadastrar(BuildContext context) { - setState(() { - usuarioController = UsuarioController(UsuarioRepository(), context); - }); - return showDialog( - barrierDismissible: false, - barrierColor: Colors.white.withOpacity(0), - context: context, - builder: (context) { - return Scaffold( - backgroundColor: Colors.transparent, - body: SingleChildScrollView( - scrollDirection: Axis.vertical, - child: Material( - type: MaterialType.transparency, - child: Form( - key: usuarioController.formKey, - child: Container( - height: MediaQuery.of(context).size.height, - margin: const EdgeInsets.only(top: 24), - child: DialogPersonalizado( - nome: 'Cadastro', - //minHeight: MediaQuery.of(context).size.height * 0.8, - child: [ - Padding( - padding: const EdgeInsets.only(bottom: 16), - child: input( - onSaved: usuarioController.usuarioNome, - textController: usuarioController.controllerNome, - label: 'nome', - ), - ), - Padding( - padding: const EdgeInsets.only(bottom: 16), - child: input( - onSaved: usuarioController.usuarioApelido, - textController: usuarioController.controllerApelido, - label: 'apelido', - ), - ), - Padding( - padding: const EdgeInsets.only(bottom: 16), - child: input( - onSaved: usuarioController.usuarioEmail, - textController: usuarioController.controllerEmail, - label: 'e-mail', - ), - //child: Input(label: 'e-mail'), - ), - Padding( - padding: const EdgeInsets.only(bottom: 16), - child: input( - onSaved: usuarioController.usuarioSenha, - textController: usuarioController.controllerSenha, - label: 'senha', - senha: true), - //child: Input(label: 'senha'), - ), - Botao( - texto: 'Cadastrar', - cor: const Color(0xFF6BC8E4), - clicar: () async { - bool succes = await usuarioController.saveUsuario(); - - if (succes == true) { - Navigator.pop(context); - entrar(context); - } - }, - ), - ], - ), - ), - ), - ), - ), - ); - }); - } }