From 4a9c766fec47756d20d7af163bb6dd6fcdd20059 Mon Sep 17 00:00:00 2001 From: Gabriel Costa de Oliveira Date: Thu, 12 Dec 2024 13:10:48 -0300 Subject: [PATCH 1/5] feat(#60) adiciona view e viewModel para o recoverAccount Co-authored-by: MarinaGaldi --- lib/ui/login/view/LoginView.dart | 2 +- .../recover_account/view/RecoverAccount.dart | 61 +++++++++++++++++-- .../viewModel/recoverAccountViewModel.dart | 13 ++++ 3 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 lib/ui/recover_account/viewModel/recoverAccountViewModel.dart diff --git a/lib/ui/login/view/LoginView.dart b/lib/ui/login/view/LoginView.dart index 8ae71f6..ae86c56 100644 --- a/lib/ui/login/view/LoginView.dart +++ b/lib/ui/login/view/LoginView.dart @@ -154,7 +154,7 @@ class _LoginState extends State<_Login> { onTap: () { Navigator.of(context).push( MaterialPageRoute( - builder: (context) => const RecoverAccount(), + builder: (context) => RecoverAccount(), ), ); }, diff --git a/lib/ui/recover_account/view/RecoverAccount.dart b/lib/ui/recover_account/view/RecoverAccount.dart index d157dc9..6708ffa 100644 --- a/lib/ui/recover_account/view/RecoverAccount.dart +++ b/lib/ui/recover_account/view/RecoverAccount.dart @@ -1,12 +1,63 @@ +import 'package:aranduapp/ui/recover_account/viewModel/recoverAccountViewModel.dart'; +import 'package:aranduapp/ui/shared/TextAndLink.dart'; +import 'package:aranduapp/ui/shared/TextEmail.dart'; +import 'package:aranduapp/ui/shared/TitleSlogan.dart'; import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; -class RecoverAccount extends StatelessWidget{ - const RecoverAccount({super.key}); - +class RecoverAccount extends StatelessWidget { @override Widget build(BuildContext context) { - // TODO: implement build - throw UnimplementedError(); + return Scaffold( + body: ChangeNotifierProvider( + create: (context) => RecoverAccountViewModel(context), + child: page(context), + )); } + Widget page(BuildContext context) { + RecoverAccountViewModel viewModel = + Provider.of(context); + + return SingleChildScrollView( + child: Center( + child: Column( + children: [ + const SizedBox(height: 80), + const TitleSlogan(), + const Padding( + padding: EdgeInsets.only(top: 70, left: 20, right: 20), + child: Text( + 'Coloque o seu e-mail no campo abaixo e clique em enviar. Logo em seguida, você receberá no seu e-mail as instruções para trocar a sua senha.', + ), + ), + Form( + key: viewModel.formKey, + child: Column(children: [ + TextEmail( + padding: + const EdgeInsets.only(top: 24, left: 20, right: 20), + controller: viewModel.emailController), + ])), + Padding( + padding: const EdgeInsets.only(top: 80), + child: SizedBox( + width: 291, + height: 64, + child: ElevatedButton( + onPressed: () {}, child: const Text('Enviar')), + ), + ), + TextAndLink( + text: 'Já tem uma conta?', + link: ' Click aqui', + action: () { + Navigator.of(context).pop(); + }, + ) + ], + ), + ), + ); + } } diff --git a/lib/ui/recover_account/viewModel/recoverAccountViewModel.dart b/lib/ui/recover_account/viewModel/recoverAccountViewModel.dart new file mode 100644 index 0000000..59952a5 --- /dev/null +++ b/lib/ui/recover_account/viewModel/recoverAccountViewModel.dart @@ -0,0 +1,13 @@ +import 'package:flutter/material.dart'; + +class RecoverAccountViewModel extends ChangeNotifier { + final BuildContext context; + + final formKey; + + final emailController; + + RecoverAccountViewModel(this.context) + : formKey = GlobalKey(), + emailController = TextEditingController(); +} From 23823a84cd28bb78c989bb1f0614a790a33c6c68 Mon Sep 17 00:00:00 2001 From: MarinaGaldi <231035722@aluno.unb.br> Date: Thu, 12 Dec 2024 17:32:57 -0300 Subject: [PATCH 2/5] =?UTF-8?q?fix(#60):Corre=C3=A7=C3=A3o=20do=20erro=20n?= =?UTF-8?q?a=20p=C3=A1gina=20de=20recurar=20conta?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: zDrNz --- .../recover_account/view/RecoverAccount.dart | 92 ++++++++++--------- 1 file changed, 47 insertions(+), 45 deletions(-) diff --git a/lib/ui/recover_account/view/RecoverAccount.dart b/lib/ui/recover_account/view/RecoverAccount.dart index 6708ffa..d911456 100644 --- a/lib/ui/recover_account/view/RecoverAccount.dart +++ b/lib/ui/recover_account/view/RecoverAccount.dart @@ -9,55 +9,57 @@ class RecoverAccount extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( - body: ChangeNotifierProvider( - create: (context) => RecoverAccountViewModel(context), - child: page(context), - )); + body: ChangeNotifierProvider( + create: (context) => RecoverAccountViewModel(context), + builder: (context, child) { + return page(context); + }), + ); } +} - Widget page(BuildContext context) { - RecoverAccountViewModel viewModel = - Provider.of(context); +Widget page(BuildContext context) { + RecoverAccountViewModel viewModel = + Provider.of(context); - return SingleChildScrollView( - child: Center( - child: Column( - children: [ - const SizedBox(height: 80), - const TitleSlogan(), - const Padding( - padding: EdgeInsets.only(top: 70, left: 20, right: 20), - child: Text( - 'Coloque o seu e-mail no campo abaixo e clique em enviar. Logo em seguida, você receberá no seu e-mail as instruções para trocar a sua senha.', - ), + return SingleChildScrollView( + child: Center( + child: Column( + children: [ + const SizedBox(height: 80), + const TitleSlogan(), + const Padding( + padding: EdgeInsets.only(top: 70, left: 20, right: 20), + child: Text( + 'Coloque o seu e-mail no campo abaixo e clique em enviar. Logo em seguida, você receberá no seu e-mail as instruções para trocar a sua senha.', ), - Form( - key: viewModel.formKey, - child: Column(children: [ - TextEmail( - padding: - const EdgeInsets.only(top: 24, left: 20, right: 20), - controller: viewModel.emailController), - ])), - Padding( - padding: const EdgeInsets.only(top: 80), - child: SizedBox( - width: 291, - height: 64, - child: ElevatedButton( - onPressed: () {}, child: const Text('Enviar')), - ), + ), + Form( + key: viewModel.formKey, + child: Column(children: [ + TextEmail( + padding: + const EdgeInsets.only(top: 24, left: 20, right: 20), + controller: viewModel.emailController), + ])), + Padding( + padding: const EdgeInsets.only(top: 80), + child: SizedBox( + width: 291, + height: 64, + child: + ElevatedButton(onPressed: () {}, child: const Text('Enviar')), ), - TextAndLink( - text: 'Já tem uma conta?', - link: ' Click aqui', - action: () { - Navigator.of(context).pop(); - }, - ) - ], - ), + ), + TextAndLink( + text: 'Já tem uma conta?', + link: ' Click aqui', + action: () { + Navigator.of(context).pop(); + }, + ) + ], ), - ); - } + ), + ); } From 55bc99536aa859c1c1a4fad7512e8992ec58e767 Mon Sep 17 00:00:00 2001 From: Gabriel Costa de Oliveira Date: Fri, 13 Dec 2024 13:37:08 -0300 Subject: [PATCH 3/5] =?UTF-8?q?feat(#60)=20cria=20conex=C3=A3o=20com=20o?= =?UTF-8?q?=20servidor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Yasm1nNasc1mento --- .../model/RecoverAccountRequest.dart | 16 +++++++ .../service/RecoverAccountService.dart | 17 ++++++++ .../recover_account/view/RecoverAccount.dart | 11 +++-- .../viewModel/recoverAccountViewModel.dart | 42 ++++++++++++++++++- 4 files changed, 82 insertions(+), 4 deletions(-) create mode 100644 lib/ui/recover_account/model/RecoverAccountRequest.dart create mode 100644 lib/ui/recover_account/service/RecoverAccountService.dart diff --git a/lib/ui/recover_account/model/RecoverAccountRequest.dart b/lib/ui/recover_account/model/RecoverAccountRequest.dart new file mode 100644 index 0000000..240a184 --- /dev/null +++ b/lib/ui/recover_account/model/RecoverAccountRequest.dart @@ -0,0 +1,16 @@ +import 'dart:convert'; + +class RecoverAccountRequest { + + final String email; + + RecoverAccountRequest(this.email); + + factory RecoverAccountRequest.fromJsonString(String jsonString) { + Map json = jsonDecode(jsonString); + return RecoverAccountRequest( + json['email'] as String, + ); + } + +} diff --git a/lib/ui/recover_account/service/RecoverAccountService.dart b/lib/ui/recover_account/service/RecoverAccountService.dart new file mode 100644 index 0000000..3afc7a2 --- /dev/null +++ b/lib/ui/recover_account/service/RecoverAccountService.dart @@ -0,0 +1,17 @@ +import 'package:aranduapp/core/network/BaseApi.dart'; +import 'package:aranduapp/ui/recover_account/model/RecoverAccountRequest.dart'; + +class RecoverAccountService { + + + static Future forgetPassword(RecoverAccountRequest recoverAccountRequest) async { + + await BaseApi.getInstance().post( + path: '/auth/forgot-password', + data: { + 'email' : recoverAccountRequest.email, + } + ); + } + +} diff --git a/lib/ui/recover_account/view/RecoverAccount.dart b/lib/ui/recover_account/view/RecoverAccount.dart index d911456..8dad747 100644 --- a/lib/ui/recover_account/view/RecoverAccount.dart +++ b/lib/ui/recover_account/view/RecoverAccount.dart @@ -47,13 +47,18 @@ Widget page(BuildContext context) { child: SizedBox( width: 291, height: 64, - child: - ElevatedButton(onPressed: () {}, child: const Text('Enviar')), + child: ElevatedButton( + onPressed: () {}, + child: Consumer( + builder: (context, value, child) => value.isLoading + ? const CircularProgressIndicator(value: null) + : const Text('Enviar'), + )), ), ), TextAndLink( text: 'Já tem uma conta?', - link: ' Click aqui', + link: 'Faça login', action: () { Navigator.of(context).pop(); }, diff --git a/lib/ui/recover_account/viewModel/recoverAccountViewModel.dart b/lib/ui/recover_account/viewModel/recoverAccountViewModel.dart index 59952a5..6dc5d57 100644 --- a/lib/ui/recover_account/viewModel/recoverAccountViewModel.dart +++ b/lib/ui/recover_account/viewModel/recoverAccountViewModel.dart @@ -1,3 +1,5 @@ +import 'package:aranduapp/ui/recover_account/model/RecoverAccountRequest.dart'; +import 'package:aranduapp/ui/recover_account/service/RecoverAccountService.dart'; import 'package:flutter/material.dart'; class RecoverAccountViewModel extends ChangeNotifier { @@ -7,7 +9,45 @@ class RecoverAccountViewModel extends ChangeNotifier { final emailController; + final recoverAccountService; + + bool isLoading; + RecoverAccountViewModel(this.context) : formKey = GlobalKey(), - emailController = TextEditingController(); + emailController = TextEditingController(), + recoverAccountService = RecoverAccountService(), + isLoading = false; + + + + Future forgetPassword(String email) async { + + // TODO use mutex to make this + if (isLoading){ + return; + } + + try { + isLoading = true; + super.notifyListeners(); + + if (!formKey.currentState!.validate()) { + throw Exception('Valores inválidos'); + } + + await recoverAccountService.forgetPassword(RecoverAccountRequest(email)); + + } catch (e) { + rethrow; + } finally { + isLoading = false; + super.notifyListeners(); + } + + + + + + } } From 72d486caf4e3b16194586c3e3958f9affd617af8 Mon Sep 17 00:00:00 2001 From: Yasm1nNasc1mento Date: Fri, 13 Dec 2024 16:34:03 -0300 Subject: [PATCH 4/5] =?UTF-8?q?fix(#60)=20modifica=20bot=C3=A3o=20RecoverA?= =?UTF-8?q?ccount?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ui/recover_account/view/RecoverAccount.dart | 14 +++++++++++++- .../viewModel/recoverAccountViewModel.dart | 6 ++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/ui/recover_account/view/RecoverAccount.dart b/lib/ui/recover_account/view/RecoverAccount.dart index 8dad747..2c3a94f 100644 --- a/lib/ui/recover_account/view/RecoverAccount.dart +++ b/lib/ui/recover_account/view/RecoverAccount.dart @@ -1,4 +1,6 @@ +import 'package:aranduapp/core/log/Log.dart'; import 'package:aranduapp/ui/recover_account/viewModel/recoverAccountViewModel.dart'; +import 'package:aranduapp/ui/shared/ErrorPopUp.dart'; import 'package:aranduapp/ui/shared/TextAndLink.dart'; import 'package:aranduapp/ui/shared/TextEmail.dart'; import 'package:aranduapp/ui/shared/TitleSlogan.dart'; @@ -6,6 +8,8 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; class RecoverAccount extends StatelessWidget { + const RecoverAccount({super.key}); + @override Widget build(BuildContext context) { return Scaffold( @@ -48,7 +52,15 @@ Widget page(BuildContext context) { width: 291, height: 64, child: ElevatedButton( - onPressed: () {}, + onPressed: () { + viewModel.forgetPassword().then((Value){ + Log.d("Deu certo!"); + }).catchError((e) => showDialog( + context: context, + builder: (BuildContext context) => + ErrorPopUp(content: Text('$e')), + )); + }, child: Consumer( builder: (context, value, child) => value.isLoading ? const CircularProgressIndicator(value: null) diff --git a/lib/ui/recover_account/viewModel/recoverAccountViewModel.dart b/lib/ui/recover_account/viewModel/recoverAccountViewModel.dart index 6dc5d57..ac8a632 100644 --- a/lib/ui/recover_account/viewModel/recoverAccountViewModel.dart +++ b/lib/ui/recover_account/viewModel/recoverAccountViewModel.dart @@ -1,3 +1,5 @@ +import 'dart:js_interop'; + import 'package:aranduapp/ui/recover_account/model/RecoverAccountRequest.dart'; import 'package:aranduapp/ui/recover_account/service/RecoverAccountService.dart'; import 'package:flutter/material.dart'; @@ -21,7 +23,7 @@ class RecoverAccountViewModel extends ChangeNotifier { - Future forgetPassword(String email) async { + Future forgetPassword() async { // TODO use mutex to make this if (isLoading){ @@ -36,7 +38,7 @@ class RecoverAccountViewModel extends ChangeNotifier { throw Exception('Valores inválidos'); } - await recoverAccountService.forgetPassword(RecoverAccountRequest(email)); + await recoverAccountService.forgetPassword(RecoverAccountRequest(emailController.text)); } catch (e) { rethrow; From 291895fbb70c0835c8e8240718f848363cbfffd4 Mon Sep 17 00:00:00 2001 From: Gabriel Costa de Oliveira Date: Fri, 13 Dec 2024 16:59:16 -0300 Subject: [PATCH 5/5] fix(#60) corrige e implementa recoverAccount Co-authored-by: Yasm1nNasc1mento --- lib/ui/recover_account/view/RecoverAccount.dart | 12 ++++++------ .../viewModel/recoverAccountViewModel.dart | 7 ++----- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/ui/recover_account/view/RecoverAccount.dart b/lib/ui/recover_account/view/RecoverAccount.dart index 2c3a94f..3aa73f3 100644 --- a/lib/ui/recover_account/view/RecoverAccount.dart +++ b/lib/ui/recover_account/view/RecoverAccount.dart @@ -53,13 +53,13 @@ Widget page(BuildContext context) { height: 64, child: ElevatedButton( onPressed: () { - viewModel.forgetPassword().then((Value){ + viewModel.forgetPassword().then((value) { Log.d("Deu certo!"); - }).catchError((e) => showDialog( - context: context, - builder: (BuildContext context) => - ErrorPopUp(content: Text('$e')), - )); + }).catchError((e) => showDialog( + context: context, + builder: (BuildContext context) => + ErrorPopUp(content: Text('$e')), + )); }, child: Consumer( builder: (context, value, child) => value.isLoading diff --git a/lib/ui/recover_account/viewModel/recoverAccountViewModel.dart b/lib/ui/recover_account/viewModel/recoverAccountViewModel.dart index ac8a632..2f6f261 100644 --- a/lib/ui/recover_account/viewModel/recoverAccountViewModel.dart +++ b/lib/ui/recover_account/viewModel/recoverAccountViewModel.dart @@ -1,5 +1,4 @@ -import 'dart:js_interop'; - +import 'package:aranduapp/core/log/Log.dart'; import 'package:aranduapp/ui/recover_account/model/RecoverAccountRequest.dart'; import 'package:aranduapp/ui/recover_account/service/RecoverAccountService.dart'; import 'package:flutter/material.dart'; @@ -11,14 +10,12 @@ class RecoverAccountViewModel extends ChangeNotifier { final emailController; - final recoverAccountService; bool isLoading; RecoverAccountViewModel(this.context) : formKey = GlobalKey(), emailController = TextEditingController(), - recoverAccountService = RecoverAccountService(), isLoading = false; @@ -38,7 +35,7 @@ class RecoverAccountViewModel extends ChangeNotifier { throw Exception('Valores inválidos'); } - await recoverAccountService.forgetPassword(RecoverAccountRequest(emailController.text)); + await RecoverAccountService.forgetPassword(RecoverAccountRequest(emailController.text)); } catch (e) { rethrow;