Skip to content

Commit

Permalink
Merge pull request #8 from prefeiturasp/fix/autenticacao
Browse files Browse the repository at this point in the history
fix: correções qa
  • Loading branch information
lucasdidur authored Apr 5, 2023
2 parents ac0759b + b7d9178 commit 6ead132
Show file tree
Hide file tree
Showing 13 changed files with 118 additions and 69 deletions.
1 change: 1 addition & 0 deletions build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ targets:
freezed:freezed:
generate_for:
- lib/**/blocs/**.dart
- lib/**/cubits/**.dart
- lib/**.entity.dart
- lib/**.model.dart
- lib/**.codegen.dart
Expand Down
29 changes: 28 additions & 1 deletion lib/app/network/dio_client.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import 'dart:io';

import 'package:dio/dio.dart';
import 'package:pretty_dio_logger/pretty_dio_logger.dart';
import 'package:sme_plateia/core/domain/failures/failure.codegen.dart';
import 'package:sme_plateia/core/utils/constants.dart';

class DioClient {
static Future<Dio> setup() async {
final options = BaseOptions(
responseType: ResponseType.json,
baseUrl: BASE_URL,
baseUrl: Endpoint.baseUrl,
);

final dio = Dio(options);
Expand All @@ -21,3 +24,27 @@ class DioClient {
return dio;
}
}

extension DioErrorX on DioError {
bool get isNoConnectionError =>
type == DioErrorType.unknown && error is SocketException; // import 'dart:io' for SocketException
}

handleNertorkError(DioError e) {
if (e.isNoConnectionError) {
throw Failure.serverFailure(message: 'Erro ao se conectar com o servidor');
}

if (e.response != null) {
String message = 'Erro desconhecido';
switch (e.response!.statusCode) {
case 401:
message = e.response!.data['errors'][0];
break;
}

throw Failure.serverFailure(message: message);
} else {
throw Failure.serverFailure(message: e.error.toString());
}
}
10 changes: 1 addition & 9 deletions lib/app/view/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,6 @@ class App extends StatelessWidget {
builder: (context, child) {
return MaterialApp.router(
scaffoldMessengerKey: rootScaffoldMessengerKey,
theme: ThemeData(
appBarTheme: const AppBarTheme(color: AppColor.primary),
colorScheme: ColorScheme.fromSwatch(
accentColor: AppColor.primary,
),
fontFamily: GoogleFonts.poppins().fontFamily,
textTheme: Typography.englishLike2018.apply(fontSizeFactor: 1.sp, displayColor: AppColor.primary),
),
localizationsDelegates: const [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
Expand All @@ -65,7 +57,7 @@ class App extends StatelessWidget {
foregroundColor: TemaUtil.preto01,
color: TemaUtil.amarelo01,
),
fontFamily: GoogleFonts.poppins().fontFamily,
fontFamily: GoogleFonts.roboto().fontFamily,
textTheme: Theme.of(context).textTheme.apply(
bodyColor: TemaUtil.preto01,
displayColor: TemaUtil.preto01,
Expand Down
6 changes: 5 additions & 1 deletion lib/core/utils/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';

const String BASE_URL = 'https://dev-plateia-api.sme.prefeitura.sp.gov.br/api/v1';
const String CACHED_TOKEN = 'autenticacao';

class Endpoint {
static const String baseUrl = 'https://dev-plateia-api.sme.prefeitura.sp.gov.br/api/v1';
static const String recuperarSenha = 'https://plateia.sme.prefeitura.sp.gov.br/Account/Reset';
}

class Environment {
const Environment._();
static const String development = 'development';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
import 'package:injectable/injectable.dart';
import 'package:sme_plateia/core/domain/failures/failure.codegen.dart';
import 'package:sme_plateia/app/network/dio_client.dart';
import 'package:sme_plateia/features/auth/data/models/autenticacao.model.dart';

import 'autenticacao_remote_service.dart';
Expand All @@ -27,12 +26,7 @@ class AutenticacaoRemoteDataSource implements IAutenticacaoRemoteDataSource {

return response.data;
} on DioError catch (e) {
debugPrint(e.toString());
if (e.response!.statusCode == 401) {
throw Failure.serverFailure(message: e.response!.data['errors'][0]);
} else {
throw Failure.serverFailure(message: e.error.toString());
}
throw handleNertorkError(e);
}
}

Expand All @@ -42,12 +36,7 @@ class AutenticacaoRemoteDataSource implements IAutenticacaoRemoteDataSource {
final response = await autenticacaoRemoteService.logout();
return response.data;
} on DioError catch (e) {
debugPrint(e.toString());
if (e.response!.statusCode == 401) {
throw Failure.serverFailure(message: e.response!.data['errors'][0]);
} else {
throw Failure.serverFailure(message: e.error.toString());
}
throw handleNertorkError(e);
}
}
}
15 changes: 4 additions & 11 deletions lib/features/auth/presentation/forms/login_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:sme_plateia/features/auth/presentation/cubits/login/login_cubit.
import 'package:sme_plateia/features/auth/presentation/widgets/login_page_input_fields.dart';
import 'package:sme_plateia/features/auth/presentation/widgets/snackbar/snackbar_widgets.dart';
import 'package:sme_plateia/injector.dart';
import 'package:sme_plateia/shared/presentation/widgets/text_button.dart';

class LoginForm extends StatelessWidget {
const LoginForm({Key? key}) : super(key: key);
Expand All @@ -21,7 +22,7 @@ class LoginForm extends StatelessWidget {
listener: (context, state) {
if (state.formStatus.isFailure) {
ScaffoldMessenger.of(context).showSnackBar(snackBarWhenFailure(
snackBarFailureText: 'Erro: ${state.exceptionError}',
snackBarFailureText: state.exceptionError,
));
}
},
Expand Down Expand Up @@ -67,11 +68,11 @@ class LoginForm extends StatelessWidget {
? const Center(
child: CircularProgressIndicator(),
)
: TextButton(
: ButtonText(
onPressed: () async {
_fazerLogin(context);
},
child: const Text('ENTRAR'),
text: 'Entrar'.toUpperCase(),
),
const SizedBox(height: 16),
InkWell(
Expand All @@ -85,14 +86,6 @@ class LoginForm extends StatelessWidget {
),
),
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Image.asset('assets/images/logo_saopaulo.png'),
],
),
),
],
),
);
Expand Down
55 changes: 28 additions & 27 deletions lib/features/auth/presentation/pages/esqueceu_senha_page.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:sme_plateia/core/utils/constants.dart';
import 'package:sme_plateia/core/utils/web_view.dart';
import 'package:sme_plateia/shared/presentation/widgets/rodape.dart';
import 'package:sme_plateia/shared/presentation/widgets/text_button.dart';

@RoutePage()
class EsqueceuSenhaPage extends StatefulWidget {
Expand All @@ -16,7 +19,10 @@ class _EsqueceuSenhaPageState extends State<EsqueceuSenhaPage> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Esqueci minha senha"),
title: const Text(
"Esqueci minha senha",
style: TextStyle(fontSize: 24),
),
),
body: SafeArea(
child: Column(
Expand All @@ -27,41 +33,36 @@ class _EsqueceuSenhaPageState extends State<EsqueceuSenhaPage> {
child: Center(child: SvgPicture.asset('assets/images/esqueceu_senha.svg')),
),
const SizedBox(height: 36),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 24),
child: Column(
children: [
const Text(
"Você será redirecionado(a) para o site do Plateia para recuperar sua senha.",
style: TextStyle(fontSize: 24),
),
const SizedBox(
height: 80,
),
TextButton(
onPressed: () async {
await _recuperarSenha();
},
child: Text('Recuperar minha senha'.toUpperCase()),
)
],
),
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Image.asset('assets/images/logo_saopaulo.png'),
],
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 24),
child: Column(
children: [
const Text(
"Você será redirecionado(a) para o site do Plateia para recuperar sua senha.",
style: TextStyle(fontSize: 24),
),
const SizedBox(
height: 80,
),
ButtonText(
onPressed: () async {
await _recuperarSenha();
},
text: 'Recuperar minha senha'.toUpperCase(),
)
],
),
),
),
Rodape(),
],
),
),
);
}

_recuperarSenha() async {
await launchURL(context, "http://identity.sme.prefeitura.sp.gov.br/Account/ForgotPassword");
await launchURL(context, Endpoint.recuperarSenha);
}
}
2 changes: 2 additions & 0 deletions lib/features/auth/presentation/pages/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:sme_plateia/features/auth/presentation/cubits/login/login_cubit.
import 'package:sme_plateia/features/auth/presentation/forms/login_form.dart';
import 'package:sme_plateia/gen/assets.gen.dart';
import 'package:sme_plateia/injector.dart';
import 'package:sme_plateia/shared/presentation/widgets/rodape.dart';

@RoutePage()
class LoginPage extends StatefulWidget {
Expand Down Expand Up @@ -43,6 +44,7 @@ class _LoginPageState extends State<LoginPage> {
child: LoginForm(),
),
),
Rodape(),
],
),
),
Expand Down
3 changes: 2 additions & 1 deletion lib/features/auth/presentation/widgets/auth_text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class AuthTextField extends StatefulWidget {
this.showError = true,
this.hasError = false,
this.autofillHints,
this.padding = const EdgeInsets.only(left: 15, right: 15, top: 5),
this.padding = const EdgeInsets.only(left: 16, right: 16),
}) : super(key: key);

@override
Expand Down Expand Up @@ -86,6 +86,7 @@ class _AuthTextFieldState extends State<AuthTextField> {
labelText: widget.isRequiredField ? '${widget.labelText}*' : widget.labelText,
labelStyle: TextStyle(
color: widget.error != null || widget.hasError ? TemaUtil.vermelhoErro : TemaUtil.preto01,
fontSize: 16,
),
hintText: widget.isRequiredField ? '${widget.hint}*' : widget.hint,
border: borderNone,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import 'package:flutter/material.dart';

SnackBar snackBarWhenFailure({required String snackBarFailureText}) {
return SnackBar(
content: Text(snackBarFailureText),
content: Center(child: Text(snackBarFailureText)),
backgroundColor: Colors.red,
);
}

SnackBar snackBarWhenSuccess() {
return const SnackBar(
content: Text("Success!"),
SnackBar snackBarWhenSuccess({required String snackBarSuccessText}) {
return SnackBar(
content: Center(child: Text(snackBarSuccessText)),
backgroundColor: Colors.green,
);
}
16 changes: 16 additions & 0 deletions lib/shared/presentation/widgets/rodape.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:flutter/material.dart';

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

@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Image.asset('assets/images/logo_saopaulo.png'),
SizedBox(height: 16),
],
);
}
}
23 changes: 23 additions & 0 deletions lib/shared/presentation/widgets/text_button.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'package:flutter/material.dart';

class ButtonText extends StatelessWidget {
const ButtonText({
super.key,
required this.onPressed,
required this.text,
});

final void Function()? onPressed;
final String text;

@override
Widget build(BuildContext context) {
return TextButton(
onPressed: onPressed,
child: Padding(
padding: const EdgeInsets.all(6.0),
child: Text(text),
),
);
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: sme_plateia
description: Aplicativo de eventos de São paulo
version: 1.0.2+1
version: 1.0.3+1
publish_to: none

environment:
Expand Down

0 comments on commit 6ead132

Please sign in to comment.