-
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 branch 'dev-securestorage' into main
- Loading branch information
Showing
16 changed files
with
359 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import 'package:flutter_secure_storage/flutter_secure_storage.dart'; | ||
|
||
class SecureStorage { | ||
// Create storage | ||
final storage = const FlutterSecureStorage( | ||
aOptions: AndroidOptions( | ||
encryptedSharedPreferences: true, | ||
)); | ||
|
||
final String _keyUserName = 'username'; | ||
final String _keyPassWord = 'password'; | ||
|
||
Future setUserName(String username) async { | ||
await storage.write(key: _keyUserName, value: username); | ||
} | ||
|
||
Future<String?> getUserName() async { | ||
return await storage.read(key: _keyUserName); | ||
} | ||
|
||
Future setPassWord(String password) async { | ||
await storage.write(key: _keyPassWord, value: password); | ||
} | ||
|
||
Future<String?> getPassWord() async { | ||
return await storage.read(key: _keyPassWord); | ||
} | ||
|
||
Future deleteAll() async { | ||
await storage.deleteAll(); | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -8,6 +8,7 @@ enum HomeStateStatus { | |
initial, | ||
loading, | ||
loaded, | ||
deslogado, | ||
error, | ||
} | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,30 @@ | ||
import 'dart:developer'; | ||
import 'package:academico_mobile/app/pages/splash/splash_state.dart'; | ||
import 'package:academico_mobile/app/repositories/auth/auth_repository.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
|
||
class SplashController extends Cubit<SplashState> { | ||
final AuthRepository _authRepository; | ||
SplashController(this._authRepository) : super(const SplashState.initial()); | ||
|
||
Future<void> splashLogin(String matricula, String password) async { | ||
emit(state.copyWith(status: SplashStatus.loading)); | ||
try { | ||
await Future.delayed(const Duration(seconds: 2)); | ||
final authModel = await _authRepository.login(matricula, password); | ||
|
||
final prefs = await SharedPreferences.getInstance(); | ||
await prefs.setString('access_token', authModel.accessToken); | ||
|
||
emit(state.copyWith(status: SplashStatus.loaded)); | ||
} catch (e, s) { | ||
log('Erro ao realizar Login Controller 1', error: e, stackTrace: s); | ||
emit( | ||
state.copyWith( | ||
status: SplashStatus.error, | ||
errorMessage: 'Erro ao realizar Login Controller 2'), | ||
); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.