-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from fga-eps-mds/qas
[RELEASE] Adiciona modificações para a Release Minor
- Loading branch information
Showing
70 changed files
with
3,590 additions
and
892 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
android/app/src/main/kotlin/com/example/aranduapp/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package com.example.aranduapp | ||
|
||
import io.flutter.embedding.android.FlutterActivity | ||
import io.flutter.embedding.android.FlutterFragmentActivity | ||
|
||
class MainActivity: FlutterActivity() | ||
class MainActivity: FlutterFragmentActivity() |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import 'package:aranduapp/core/data/local/StorageValue.dart'; | ||
import 'package:aranduapp/core/log/Log.dart'; | ||
import 'package:aranduapp/core/network/token_manager/auth_service.dart'; | ||
import 'package:aranduapp/core/network/token_manager/model/refresh_token_response.dart'; | ||
import 'package:dio/dio.dart'; | ||
|
||
class AppInterceptors extends Interceptor { | ||
@override | ||
Future<void> onRequest( | ||
RequestOptions options, RequestInterceptorHandler handler) async { | ||
String? token = await StorageValue.getInstance().getAuthToken(); | ||
|
||
Log.w(token); | ||
|
||
if (token != null) { | ||
options.headers['Authorization'] = 'Bearer $token'; | ||
} else { | ||
Log.w('Token não encontrado'); | ||
} | ||
|
||
super.onRequest(options, handler); | ||
} | ||
|
||
@override | ||
Future onError(DioException err, ErrorInterceptorHandler handler) async { | ||
if (err.response?.statusCode == 401) { | ||
try { | ||
Log.i('Token expirado. Tentando atualizar o token...'); | ||
|
||
RefreshTokenResponse tokens = | ||
await AuthService().refreshToken(); | ||
|
||
final requestOptions = err.requestOptions; | ||
|
||
requestOptions.headers['Authorization'] = 'Bearer ${tokens.authToken}'; | ||
|
||
final response = await Dio().request( | ||
requestOptions.path, | ||
options: Options( | ||
method: requestOptions.method, | ||
headers: requestOptions.headers, | ||
), | ||
data: requestOptions.data, | ||
); | ||
|
||
Log.i('Token expirado atualizado.'); | ||
return handler.resolve(response); | ||
} catch (e) { | ||
super.onError(err, handler); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import 'package:aranduapp/core/log/Log.dart'; | ||
import 'package:aranduapp/core/network/app_interceptors.dart'; | ||
|
||
import 'package:dio/dio.dart'; | ||
|
||
class BaseApi { | ||
final Dio _dio; | ||
|
||
static BaseApi? _authInstance, _nonAuthInstance; | ||
|
||
final String url = 'https://arandu-user-service.onrender.com'; | ||
|
||
BaseApi._internal(bool auth) : _dio = Dio() { | ||
_dio.options.baseUrl = url; | ||
_dio.options.connectTimeout = const Duration(seconds: 5); | ||
_dio.options.receiveTimeout = const Duration(seconds: 5); | ||
|
||
if (auth) _dio.interceptors.add(AppInterceptors()); | ||
|
||
_dio.interceptors.add(LogInterceptor( | ||
requestBody: true, | ||
responseBody: true, | ||
requestHeader: true, | ||
error: true, | ||
responseHeader: true, | ||
request: true)); | ||
} | ||
|
||
static BaseApi getInstance({required bool auth}) { | ||
if (auth) { | ||
return _authInstance ??= BaseApi._internal(auth); | ||
} else { | ||
return _nonAuthInstance ??= BaseApi._internal(auth); | ||
} | ||
} | ||
|
||
Future<Response> get( | ||
{required String path, Map<String, dynamic>? queryParameters}) async { | ||
try { | ||
return await _dio.get(path, queryParameters: queryParameters); | ||
} catch (e) { | ||
Log.e(e); | ||
rethrow; | ||
} | ||
} | ||
|
||
Future<Response> post({required String path, Object? data}) async { | ||
try { | ||
return await _dio.post(path, data: data); | ||
} catch (e) { | ||
Log.e(e); | ||
rethrow; | ||
} | ||
} | ||
|
||
|
||
Future<Response> patch({required String path, Object? data}) async { | ||
try { | ||
return await _dio.patch(path, data: data); | ||
} catch (e) { | ||
Log.e(e); | ||
rethrow; | ||
} | ||
} | ||
|
||
|
||
|
||
Future<Response> put({required String path, Object? data}) async { | ||
try { | ||
return await _dio.put(path, data: data); | ||
} catch (e) { | ||
Log.e(e); | ||
rethrow; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import 'package:aranduapp/core/data/local/StorageValue.dart'; | ||
import 'package:aranduapp/core/log/Log.dart'; | ||
import 'package:aranduapp/core/network/base_api.dart'; | ||
import 'package:aranduapp/core/network/token_manager/model/refresh_token_response.dart'; | ||
import 'package:dio/dio.dart'; | ||
|
||
class AuthService { | ||
Future<RefreshTokenResponse> refreshToken() async { | ||
String? refresh = await StorageValue.getInstance().getRefreshToken(); | ||
|
||
assert(refresh != null); | ||
|
||
Response response = await BaseApi.getInstance(auth: false).post( | ||
path: '/auth/refresh', | ||
data: <String, dynamic>{'refreshToken': refresh}); | ||
|
||
RefreshTokenResponse tokens = | ||
RefreshTokenResponse.fromJsonString(response.toString()); | ||
|
||
await StorageValue.getInstance().setAuthToken(tokens.authToken!); | ||
await StorageValue.getInstance().setRefreshToken(tokens.refreshToken!); | ||
|
||
Log.i("Tokens atualizados com sucesso."); | ||
|
||
return tokens; | ||
} | ||
|
||
Future<void> validateToken() async { | ||
await BaseApi.getInstance(auth: true).get(path: '/auth/validate-token'); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
lib/core/network/token_manager/model/refresh_token_response.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import 'dart:convert'; | ||
|
||
class RefreshTokenResponse { | ||
|
||
String? authToken; | ||
String? refreshToken; | ||
|
||
RefreshTokenResponse(this.authToken, this.refreshToken); | ||
|
||
factory RefreshTokenResponse.fromJsonString(String jsonString) { | ||
Map<String, dynamic> json = jsonDecode(jsonString); | ||
return RefreshTokenResponse( | ||
json['accessToken'] as String?, | ||
json['refreshToken'] as String? | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import 'package:async/async.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
abstract class Command<T> extends ChangeNotifier { | ||
Result<T>? _result; | ||
|
||
bool _running = false; | ||
|
||
Command(); | ||
|
||
bool get isError => result?.asError != null; | ||
|
||
bool get isOk => result?.asValue != null; | ||
|
||
Result<T>? get result => _result; | ||
|
||
bool get running => _running; | ||
|
||
Future<void> _execute(action) async { | ||
if (running) return; | ||
|
||
_result = null; | ||
_running = true; | ||
notifyListeners(); | ||
|
||
try { | ||
_result = await action(); | ||
} catch (e) { | ||
_result = Result.error(e); | ||
} finally { | ||
_running = false; | ||
notifyListeners(); | ||
} | ||
} | ||
} | ||
|
||
class Command0<T> extends Command<T> { | ||
final Future<Result<T>> Function() action; | ||
|
||
Command0(this.action); | ||
|
||
Future<Result<T>> execute() async { | ||
await _execute(action); | ||
|
||
return _result!; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import 'dart:convert'; | ||
|
||
class EditPasswordRequest { | ||
final String oldPassword; | ||
final String newPassword; | ||
|
||
EditPasswordRequest({ | ||
required this.oldPassword, | ||
required this.newPassword, | ||
}); | ||
|
||
Map<String, dynamic> toJson() { | ||
return <String, dynamic>{ | ||
'oldPassword': oldPassword, | ||
'newPassword': newPassword, | ||
}; | ||
} | ||
|
||
factory EditPasswordRequest.fromJsonString(String jsonString) { | ||
final json = jsonDecode(jsonString); | ||
|
||
return EditPasswordRequest( | ||
oldPassword: json['oldPpassword']! as String, | ||
newPassword: json['newPassword']! as String, | ||
); | ||
} | ||
} | ||
|
Oops, something went wrong.