add login invalid credentials error and logout funcationality
parent
118a4f4587
commit
98991c0ef6
|
@ -1,3 +1,6 @@
|
|||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:barcode_scan2/barcode_scan2.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
@ -7,6 +10,7 @@ import 'package:unit2/screens/unit2/login/functions/get_app_version.dart';
|
|||
import 'package:unit2/sevices/login_service/auth_service.dart';
|
||||
|
||||
import '../../utils/scanner.dart';
|
||||
import '../../utils/text_container.dart';
|
||||
|
||||
part 'user_event.dart';
|
||||
part 'user_state.dart';
|
||||
|
@ -14,6 +18,7 @@ part 'user_state.dart';
|
|||
class UserBloc extends Bloc<UserEvent, UserState> {
|
||||
UserData? _userData;
|
||||
VersionInfo? _versionInfo;
|
||||
String? _apkVersion;
|
||||
UserBloc() : super(UserInitial()) {
|
||||
// this event is called when opening the app to check if
|
||||
// there is new app version
|
||||
|
@ -23,7 +28,8 @@ class UserBloc extends Bloc<UserEvent, UserState> {
|
|||
VersionInfo versionInfo = await AuthService.instance.getVersionInfo();
|
||||
_versionInfo = versionInfo;
|
||||
String apkVersion = await getAppVersion();
|
||||
emit(VersionLoaded(versionInfo: _versionInfo,apkVersion: apkVersion));
|
||||
_apkVersion = apkVersion;
|
||||
emit(VersionLoaded(versionInfo: _versionInfo,apkVersion: _apkVersion));
|
||||
} catch (e) {
|
||||
emit(UserError(
|
||||
message: e.toString(),
|
||||
|
@ -31,7 +37,7 @@ class UserBloc extends Bloc<UserEvent, UserState> {
|
|||
}
|
||||
});
|
||||
on<LoadVersion>((event, emit) {
|
||||
emit(VersionLoaded(versionInfo: _versionInfo));
|
||||
emit(VersionLoaded(versionInfo: _versionInfo,apkVersion: _apkVersion));
|
||||
});
|
||||
on<UserLogin>((event, emit) async {
|
||||
try {
|
||||
|
@ -39,8 +45,12 @@ class UserBloc extends Bloc<UserEvent, UserState> {
|
|||
.webLogin(username: event.username, password: event.password);
|
||||
_userData = userData;
|
||||
emit(UserLoggedIn(userData: _userData));
|
||||
} catch (e) {
|
||||
emit(UserError(message: e.toString()));
|
||||
} on TimeoutException catch (_) {
|
||||
emit(InternetTimeout(message: timeoutError));
|
||||
}on SocketException catch (_){
|
||||
emit(InternetTimeout(message:timeoutError));
|
||||
}on Error catch(_){
|
||||
emit(InvalidCredentials(message: "Invalid username or password"));
|
||||
}
|
||||
});
|
||||
on<UuidLogin>((event, emit) async {
|
||||
|
@ -49,8 +59,12 @@ class UserBloc extends Bloc<UserEvent, UserState> {
|
|||
.qrLogin(uuid: event.uuid, password: event.password);
|
||||
_userData = userData;
|
||||
emit(UserLoggedIn(userData: _userData));
|
||||
} catch (e) {
|
||||
emit(UserError(message: e.toString()));
|
||||
} on TimeoutException catch (_) {
|
||||
emit(InternetTimeout(message: timeoutError));
|
||||
}on SocketException catch (_){
|
||||
emit(InternetTimeout(message:timeoutError));
|
||||
}on Error catch(_){
|
||||
emit(InvalidCredentials(message: "Invalid username or password"));
|
||||
}
|
||||
});
|
||||
on<LoadLoggedInUser>((event, emit) {
|
||||
|
|
|
@ -48,3 +48,15 @@ class UuidLoaded extends UserState{
|
|||
@override
|
||||
List<Object> get props => [uuid];
|
||||
}
|
||||
|
||||
class InternetTimeout extends UserState{
|
||||
final String message;
|
||||
InternetTimeout({required this.message});
|
||||
@override
|
||||
List<Object> get props => [message];
|
||||
}
|
||||
|
||||
class InvalidCredentials extends UserState{
|
||||
final String message ;
|
||||
InvalidCredentials ({required this.message});
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ class _MenuScreenState extends State<MenuScreen> {
|
|||
Expanded(
|
||||
child: Align(
|
||||
alignment: FractionalOffset.bottomLeft,
|
||||
child: getTile(WebSymbols.logout, "Logout", 'login', context,
|
||||
child: getTile(WebSymbols.logout, "Logout", '/', context,
|
||||
widget.userData!),
|
||||
)),
|
||||
],
|
||||
|
|
|
@ -7,6 +7,7 @@ import 'package:fluttericon/font_awesome5_icons.dart';
|
|||
import 'package:form_builder_validators/form_builder_validators.dart';
|
||||
import 'package:flutter_progress_hud/flutter_progress_hud.dart';
|
||||
import 'package:unit2/screens/unit2/login/components/update_required.dart';
|
||||
import 'package:unit2/utils/alerts.dart';
|
||||
import 'package:unit2/utils/text_container.dart';
|
||||
import 'package:unit2/widgets/error_state.dart';
|
||||
import '../../../bloc/user/user_bloc.dart';
|
||||
|
@ -43,8 +44,24 @@ class _UniT2LoginState extends State<UniT2Login> {
|
|||
Navigator.pushReplacementNamed(context, '/module-screen');
|
||||
}
|
||||
if (state is UuidLoaded) {
|
||||
final progress = ProgressHUD.of(context);
|
||||
progress!.dismiss();
|
||||
Navigator.pushNamed(context, '/qr-login');
|
||||
}
|
||||
if (state is UserError) {
|
||||
final progress = ProgressHUD.of(context);
|
||||
progress!.dismiss();
|
||||
}
|
||||
if (state is InternetTimeout) {
|
||||
final progress = ProgressHUD.of(context);
|
||||
progress!.dismiss();
|
||||
}
|
||||
if (state is InvalidCredentials) {
|
||||
final progress = ProgressHUD.of(context);
|
||||
progress!.dismiss();
|
||||
errorAlert(context, "Error Login", state.message);
|
||||
context.read<UserBloc>().add(LoadVersion());
|
||||
}
|
||||
}, builder: (context, state) {
|
||||
if (state is VersionLoaded) {
|
||||
return Builder(builder: (context) {
|
||||
|
@ -293,6 +310,7 @@ class _UniT2LoginState extends State<UniT2Login> {
|
|||
),
|
||||
);
|
||||
} else {
|
||||
//New update available
|
||||
return Update(
|
||||
apkVersion: state.apkVersion!,
|
||||
currenVersion: state.versionInfo!.version!,
|
||||
|
@ -305,6 +323,11 @@ class _UniT2LoginState extends State<UniT2Login> {
|
|||
message: state.message,
|
||||
);
|
||||
}
|
||||
if (state is InternetTimeout) {
|
||||
return ErrorState(
|
||||
message: state.message,
|
||||
);
|
||||
}
|
||||
if (state is SplashScreen) {
|
||||
return const UniTSplashScreen();
|
||||
}
|
||||
|
|
|
@ -4,8 +4,8 @@ class Url {
|
|||
|
||||
String host() {
|
||||
// return '192.168.10.221:3003';
|
||||
return 'agusandelnorte.gov.ph';
|
||||
// return 'devweb.agusandelnorte.gov.ph';
|
||||
// return 'agusandelnorte.gov.ph';
|
||||
return 'devweb.agusandelnorte.gov.ph';
|
||||
}
|
||||
|
||||
String authentication() {
|
||||
|
|
Loading…
Reference in New Issue