Skip to content

Commit

Permalink
Merge pull request #52 from fga-eps-mds/qa/recover_account
Browse files Browse the repository at this point in the history
Qa/recover account
  • Loading branch information
GabrielCostaDeOliveira authored Dec 22, 2024
2 parents 4fc01ad + e984826 commit 9f3d130
Show file tree
Hide file tree
Showing 8 changed files with 666 additions and 100 deletions.
2 changes: 1 addition & 1 deletion lib/ui/login/view/LoginView.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart';

import 'package:aranduapp/ui/login/viewModel/LoginViewModel.dart';

import 'package:aranduapp/ui/recover_account/view/RecoverAccount.dart';
import 'package:aranduapp/ui/recover_account/view/recover_account_view.dart';
import 'package:aranduapp/ui/register_account/view/RegisterAccount.dart';

import 'package:aranduapp/ui/shared/TitleSlogan.dart';
Expand Down
82 changes: 0 additions & 82 deletions lib/ui/recover_account/view/RecoverAccount.dart

This file was deleted.

86 changes: 86 additions & 0 deletions lib/ui/recover_account/view/recover_account_view.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import 'package:aranduapp/core/log/Log.dart';
import 'package:aranduapp/ui/recover_account/viewModel/recover_account_view_model.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';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class RecoverAccount extends StatelessWidget {
const RecoverAccount({super.key});

@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (context) => RecoverAccountViewModel(),
builder: (context, child) {
return const RecoverAccountScreen();
});
}
}

class RecoverAccountScreen extends StatelessWidget {
const RecoverAccountScreen({super.key});

@override
Widget build(BuildContext context) {
RecoverAccountViewModel viewModel =
Provider.of<RecoverAccountViewModel>(context);

return Scaffold(
body: SingleChildScrollView(
child: Center(
child: Column(
children: <Widget>[
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: <Widget>[
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: () {
viewModel.forgetPassword().then((value) {
Log.d("Deu certo!");
}).catchError((e) => showDialog<Object>(
context: context,
builder: (BuildContext context) =>
ErrorPopUp(content: Text('$e')),
));
},
child: viewModel.isLoading
? const CircularProgressIndicator(value: null)
: const Text('Enviar'),
),
),
),
TextAndLink(
text: 'Já tem uma conta?',
link: 'Faça login',
action: () {
Navigator.of(context).pop();
},
)
],
),
),
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,20 @@ import 'package:aranduapp/ui/recover_account/service/RecoverAccountService.dart'
import 'package:flutter/material.dart';

class RecoverAccountViewModel extends ChangeNotifier {
final BuildContext context;

final formKey;

final emailController;
GlobalKey<FormState> formKey;

TextEditingController emailController;

bool isLoading;

RecoverAccountViewModel(this.context)
RecoverAccountViewModel()
: formKey = GlobalKey<FormState>(),
emailController = TextEditingController(),
isLoading = false;



Future<void> forgetPassword() async {

// TODO use mutex to make this
if (isLoading){
if (isLoading) {
return;
}

Expand All @@ -35,18 +29,13 @@ class RecoverAccountViewModel extends ChangeNotifier {
throw Exception('Valores inválidos');
}

await RecoverAccountService.forgetPassword(RecoverAccountRequest(emailController.text));

await RecoverAccountService.forgetPassword(
RecoverAccountRequest(emailController.text));
} catch (e) {
rethrow;
} finally {
isLoading = false;
super.notifyListeners();
}





}
}
Loading

0 comments on commit 9f3d130

Please sign in to comment.