From bdd1f6c6cc259db32dbbff413d78ede53c7b2475 Mon Sep 17 00:00:00 2001 From: wjrcode Date: Sun, 20 Nov 2022 22:53:37 -0300 Subject: [PATCH] =?UTF-8?q?corre=C3=A7=C3=A3o=20banca?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/Controller/LoginController.dart | 54 +++++++++++++++++++ lib/Repository/LoginRepository.dart | 20 +++++++ .../dialogs/login/entrarDialog.dart | 12 +++++ 3 files changed, 86 insertions(+) diff --git a/lib/Controller/LoginController.dart b/lib/Controller/LoginController.dart index fa70f5e..6203b26 100644 --- a/lib/Controller/LoginController.dart +++ b/lib/Controller/LoginController.dart @@ -70,6 +70,60 @@ class LoginController extends Base { } } + Future redefinirSenha() async { + if (!formKey.currentState!.validate()) { + return false; + } + + formKey.currentState!.save(); + + try { + bool ret = await repository.redefinirSenha(model); + + if (!ret) { + ScaffoldMessenger.of(context).showSnackBar(SnackBar( + elevation: 6.0, + behavior: SnackBarBehavior.floating, + shape: RoundedRectangleBorder( + side: const BorderSide(color: Colors.black, width: 3), + borderRadius: BorderRadius.circular(16), + ), + content: const Text( + 'Informe seu e-mail!', + style: TextStyle( + color: Colors.black, + fontWeight: FontWeight.w400, + ), + ), + backgroundColor: const Color(0xFFEF7E69), + )); + } else { + ScaffoldMessenger.of(context).showSnackBar(SnackBar( + elevation: 6.0, + behavior: SnackBarBehavior.floating, + shape: RoundedRectangleBorder( + side: const BorderSide(color: Colors.black, width: 3), + borderRadius: BorderRadius.circular(16), + ), + content: const Text( + 'Enviamos uma nova senha no seu e-mail!', + style: TextStyle( + color: Colors.black, + fontWeight: FontWeight.w400, + ), + ), + backgroundColor: const Color(0xFF74C198), + )); + } + + return ret; + } catch (e) { + return false; + } finally { + //closeAlertDialog(context); + } + } + Future getUsuarioLogado() async { return repository.getUsuarioLogado(); } diff --git a/lib/Repository/LoginRepository.dart b/lib/Repository/LoginRepository.dart index 04ca902..4773da8 100644 --- a/lib/Repository/LoginRepository.dart +++ b/lib/Repository/LoginRepository.dart @@ -34,6 +34,26 @@ class LoginRepository { return false; } + Future redefinirSenha(LoginModel model) async { + var _url = Uri.parse(ApiModel().ApiUrl + '/esquecisenha'); + var json = { + "email": model.usuario.toString().toLowerCase(), + }; + + Map headers = { + "Content-Type": "application/json", + }; + + final response = + await http.post(_url, headers: headers, body: jsonEncode(json)); + + if (response.statusCode == 201) { + return true; + } + + return false; + } + Future getUsuarioLogado() async { SharedPreferences prefs = await SharedPreferences.getInstance(); diff --git a/lib/components/dialogs/login/entrarDialog.dart b/lib/components/dialogs/login/entrarDialog.dart index a469de4..5256ec7 100644 --- a/lib/components/dialogs/login/entrarDialog.dart +++ b/lib/components/dialogs/login/entrarDialog.dart @@ -80,6 +80,18 @@ Future entrar(BuildContext context) { ; }, ), + ), + Padding( + padding: const EdgeInsets.fromLTRB(0, 0, 0, 16.0), + child: Botao( + key: Key("keyEntrarButton"), + texto: 'Esqueci senha', + cor: const Color(0xFFEF7E69), + clicar: () async { + bool succes = + await loginController.redefinirSenha(); + }, + ), ) ], ),