Skip to content

Commit

Permalink
logout
Browse files Browse the repository at this point in the history
  • Loading branch information
wjrcode committed Oct 17, 2022
1 parent 1e185b4 commit d6e3250
Show file tree
Hide file tree
Showing 9 changed files with 300 additions and 179 deletions.
13 changes: 6 additions & 7 deletions lib/Controller/LoginController.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -23,19 +24,15 @@ class LoginController extends Base {
var controllerSenha = TextEditingController();

Future<bool> 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) {
Expand Down Expand Up @@ -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<String> getUsuarioLogado() async {
Expand Down
4 changes: 2 additions & 2 deletions lib/Model/API/APIModel.dart
Original file line number Diff line number Diff line change
@@ -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<String, String> headers = {
Expand Down
6 changes: 3 additions & 3 deletions lib/Model/API/ResponseAPIModel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class ResponseAPIModel {

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['valido'] = this.valido;
data['msg'] = this.msg;
data['statusCode'] = this.statusCode;
data['valido'] = valido;
data['msg'] = msg;
data['statusCode'] = statusCode;

return data;
}
Expand Down
90 changes: 90 additions & 0 deletions lib/components/dialogs/login/entrarDialog.dart
Original file line number Diff line number Diff line change
@@ -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<dynamic> 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: <Widget>[
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<void>(
MaterialPageRoute<void>(
builder: (BuildContext context) =>
const HomePage(),
),
);
}
;
},
),
)
],
),
),
),
),
),
),
));
});
}
80 changes: 80 additions & 0 deletions lib/components/dialogs/login/sairDialog.dart
Original file line number Diff line number Diff line change
@@ -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<dynamic> 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: <Widget>[
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!();
// }
},
),
),
],
),
),
),
),
),
);
});
});
}
93 changes: 93 additions & 0 deletions lib/components/dialogs/login/usuarioCadastroDialog.dart
Original file line number Diff line number Diff line change
@@ -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<dynamic> 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: <Widget>[
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);
}
},
),
],
),
),
),
),
),
),
);
});
}
2 changes: 1 addition & 1 deletion lib/components/dialogs/tarefas/tarefaCadastroDialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:organizei/components/selectPrioridade.dart';
import '../../../Controller/TarefaController.dart';

Future<dynamic> criarTarefa(BuildContext context,
{TarefaModel? tarefa = null, Function? fecharDialog = null}) {
{TarefaModel? tarefa, Function? fecharDialog}) {
late TarefaController tarefaController;

tarefaController = TarefaController(TarefaRepository(), context);
Expand Down
33 changes: 22 additions & 11 deletions lib/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -114,18 +116,27 @@ class _HomePageState extends State<HomePage> {
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
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,
// )),
// )
],
),
],
Expand Down
Loading

0 comments on commit d6e3250

Please sign in to comment.