Skip to content

Commit

Permalink
correção banca
Browse files Browse the repository at this point in the history
  • Loading branch information
wjrcode committed Nov 21, 2022
1 parent 473c03c commit bdd1f6c
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
54 changes: 54 additions & 0 deletions lib/Controller/LoginController.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,60 @@ class LoginController extends Base {
}
}

Future<bool> 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<UsuarioModel> getUsuarioLogado() async {
return repository.getUsuarioLogado();
}
Expand Down
20 changes: 20 additions & 0 deletions lib/Repository/LoginRepository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,26 @@ class LoginRepository {
return false;
}

Future<bool> redefinirSenha(LoginModel model) async {
var _url = Uri.parse(ApiModel().ApiUrl + '/esquecisenha');
var json = {
"email": model.usuario.toString().toLowerCase(),
};

Map<String, String> 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<UsuarioModel> getUsuarioLogado() async {
SharedPreferences prefs = await SharedPreferences.getInstance();

Expand Down
12 changes: 12 additions & 0 deletions lib/components/dialogs/login/entrarDialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ Future<dynamic> 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();
},
),
)
],
),
Expand Down

0 comments on commit bdd1f6c

Please sign in to comment.