55 lines
1.6 KiB
Dart
55 lines
1.6 KiB
Dart
import 'package:didvan/models/enums.dart';
|
|
import 'package:didvan/models/view/alert_data.dart';
|
|
import 'package:didvan/providers/core_provider.dart';
|
|
import 'package:didvan/services/network/request.dart';
|
|
import 'package:didvan/services/network/request_helper.dart';
|
|
import 'package:didvan/utils/action_sheet.dart';
|
|
|
|
class AuthenticationState extends CoreProvier {
|
|
int _currentPageIndex = 0;
|
|
String username = '';
|
|
String password = '';
|
|
String verificationCode = '';
|
|
|
|
set currentPageIndex(int value) {
|
|
_currentPageIndex = value;
|
|
notifyListeners();
|
|
}
|
|
|
|
int get currentPageIndex => _currentPageIndex;
|
|
|
|
Future<void> confirmUsername() async {
|
|
appState = AppState.isolatedBusy;
|
|
final RequestService service = RequestService(
|
|
RequestHelper.confirmUsername,
|
|
useAutherization: false,
|
|
body: {'username': username},
|
|
);
|
|
await service.post();
|
|
if (service.isSuccess && service.result['confirmed']) {
|
|
appState = AppState.idle;
|
|
currentPageIndex++;
|
|
} else {
|
|
appState = AppState.failed;
|
|
ActionSheetUtils.showAlert(AlertData(message: service.errorMessage));
|
|
}
|
|
}
|
|
|
|
Future<String?> login() async {
|
|
appState = AppState.isolatedBusy;
|
|
final RequestService service = RequestService(
|
|
RequestHelper.login,
|
|
useAutherization: false,
|
|
body: {'username': username, "password": password},
|
|
);
|
|
await service.post();
|
|
if (service.isSuccess && service.result['loggedIn']) {
|
|
appState = AppState.idle;
|
|
return service.result['token'];
|
|
} else {
|
|
appState = AppState.failed;
|
|
ActionSheetUtils.showAlert(AlertData(message: service.errorMessage));
|
|
}
|
|
}
|
|
}
|