CHANGE_
This commit is contained in:
parent
a2e6ad558a
commit
76ba68f022
@ -25,7 +25,7 @@ class _CustomAppBarState extends State<CustomAppBar> {
|
||||
final String? token = prefs.getString('token');
|
||||
|
||||
if (token != null && token.isNotEmpty) {
|
||||
// await prefs.clear();
|
||||
await prefs.clear();
|
||||
Navigator.pushNamed(context, 'login');
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import 'package:firebase_core/firebase_core.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:nhance_app_pwa/pages/enrollment/addons.dart';
|
||||
@ -28,7 +27,6 @@ import 'models/environment.dart';
|
||||
|
||||
Future<void> main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await Firebase.initializeApp();
|
||||
await dotenv.load(fileName: Environment.fileName);
|
||||
final AuthService _authService = AuthService();
|
||||
|
||||
|
||||
5
lib/models/platform_helper_mobile.dart
Normal file
5
lib/models/platform_helper_mobile.dart
Normal file
@ -0,0 +1,5 @@
|
||||
import 'dart:io';
|
||||
|
||||
bool isMobilePlatform() {
|
||||
return Platform.isAndroid || Platform.isIOS;
|
||||
}
|
||||
3
lib/models/platform_helper_other.dart
Normal file
3
lib/models/platform_helper_other.dart
Normal file
@ -0,0 +1,3 @@
|
||||
bool isMobilePlatform() {
|
||||
return false;
|
||||
}
|
||||
@ -2,16 +2,15 @@ import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:nhance_app_pwa/pages/session/SetPinBiometric.dart';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:flutter_animated_button/flutter_animated_button.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
|
||||
import '../customAppBar/responsive.dart';
|
||||
import '../customAppBar/toastHelper.dart';
|
||||
import '../models/environment.dart';
|
||||
import '../models/platform_helper_mobile.dart'
|
||||
if (dart.library.html) '../models/platform_helper_other.dart';
|
||||
|
||||
class login extends StatefulWidget {
|
||||
const login({Key? key});
|
||||
@ -31,30 +30,16 @@ class _loginState extends State<login> {
|
||||
void initState() {
|
||||
countryController.text = "+91";
|
||||
super.initState();
|
||||
checkLoginPin();
|
||||
WidgetsBinding.instance
|
||||
.addPostFrameCallback((_) => checkTokenAvailability());
|
||||
checkLoginPinOnMobile();
|
||||
}
|
||||
|
||||
Future<void> checkTokenAvailability() async {
|
||||
if (_isCheckingToken) return;
|
||||
_isCheckingToken = true;
|
||||
print('checkTokenAvailability');
|
||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
final String? token = prefs.getString('token');
|
||||
final mpin = prefs.getString('user_pin');
|
||||
int skipStatus = prefs.getInt('skipStatus') ?? 1;
|
||||
final emp_status = prefs.getString('emp_status');
|
||||
|
||||
// if (prefs.containsKey('skipStatus') && skipStatus == 1) {
|
||||
// if (prefs.containsKey('user_pin') && mpin != null && mpin.isNotEmpty) {
|
||||
// Navigator.pushReplacementNamed(context, 'pinPage');
|
||||
// }
|
||||
// }
|
||||
// checkLoginPin();
|
||||
void checkLoginPinOnMobile() {
|
||||
if (isMobilePlatform()) {
|
||||
checkLoginPin(context);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> checkLoginPin() async {
|
||||
Future<void> checkLoginPin(BuildContext context) async {
|
||||
print('checkLoginPin');
|
||||
try {
|
||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
@ -73,7 +58,8 @@ class _loginState extends State<login> {
|
||||
Map<String, dynamic> data = json.decode(response.body);
|
||||
if (data['status'] == 'success') {
|
||||
print('data');
|
||||
prefs.setString('mpin', data['data']);
|
||||
prefs.setString('mpinText', data['data']);
|
||||
prefs.setString('mpin', data['Mpin']);
|
||||
Navigator.pushReplacementNamed(context, 'pinPage');
|
||||
}
|
||||
} else {
|
||||
|
||||
@ -11,6 +11,10 @@ import '../../customAppBar/responsive.dart';
|
||||
import '../../customAppBar/tabs.dart';
|
||||
import '../../customAppBar/toastHelper.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import '../../models/platform_helper_mobile.dart'
|
||||
if (dart.library.html) '../../models/platform_helper_other.dart';
|
||||
|
||||
import '../session/authenticationService.dart';
|
||||
|
||||
class profile extends StatefulWidget {
|
||||
const profile({Key? key}) : super(key: key);
|
||||
@ -21,6 +25,7 @@ class profile extends StatefulWidget {
|
||||
|
||||
class _profileState extends State<profile> {
|
||||
late ApiService apiService;
|
||||
final AuthService _authService = AuthService();
|
||||
int _currentIndex = 0;
|
||||
bool isActive = true;
|
||||
dynamic _token;
|
||||
@ -140,12 +145,25 @@ class _profileState extends State<profile> {
|
||||
}
|
||||
|
||||
Future<void> logout(BuildContext context) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
if (Responsive.isDesktop(context)) {
|
||||
if (isMobilePlatform()) {
|
||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
|
||||
// Get the value of the mobile_number key
|
||||
String? mobileNumber = prefs.getString('empMobileNo');
|
||||
|
||||
// Clear all keys
|
||||
await prefs.clear();
|
||||
|
||||
// Re-set the mobile_number key
|
||||
if (mobileNumber != null) {
|
||||
await prefs.setString('empMobileNo', mobileNumber);
|
||||
}
|
||||
ToastHelper.showSuccessToast(context, 'logout');
|
||||
// Navigate to login page
|
||||
Navigator.pushNamed(context, 'login');
|
||||
} else {
|
||||
// await prefs.clear();
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.clear();
|
||||
Navigator.pushNamed(context, 'login');
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,6 +35,7 @@ class _pinPageState extends State<pinPage> {
|
||||
dynamic clientName;
|
||||
dynamic clientLogo;
|
||||
dynamic emp_status;
|
||||
dynamic bioMetricMpin;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -51,15 +52,17 @@ class _pinPageState extends State<pinPage> {
|
||||
}
|
||||
|
||||
Future<void> _checkBiometricAuthentication() async {
|
||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
bioMetricMpin = prefs.getString('mpin');
|
||||
bool authenticated = await _authService.authenticateWithBiometrics();
|
||||
if (authenticated) {
|
||||
enterPinApi();
|
||||
enterPinApi(bioMetricMpin);
|
||||
} else {
|
||||
ToastHelper.showErrorToast(context, 'Biometric authentication failed');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> enterPinApi() async {
|
||||
Future<void> enterPinApi(mpin) async {
|
||||
try {
|
||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
empMobileNo = prefs.getString('empMobileNo');
|
||||
@ -67,8 +70,7 @@ class _pinPageState extends State<pinPage> {
|
||||
|
||||
final response = await http.post(
|
||||
Uri.parse(Environment.apiUrl + 'verifyMpin'),
|
||||
body: json.encode(
|
||||
{'mobile_number': empMobileNo, 'mpin': _pinController.text}),
|
||||
body: json.encode({'mobile_number': empMobileNo, 'mpin': mpin}),
|
||||
headers: {
|
||||
HttpHeaders.contentTypeHeader: 'application/json',
|
||||
},
|
||||
@ -124,7 +126,7 @@ class _pinPageState extends State<pinPage> {
|
||||
Future<void> enterLoginPin() async {
|
||||
try {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
enterPinApi();
|
||||
enterPinApi(_pinController.text);
|
||||
}
|
||||
} catch (e) {
|
||||
ToastHelper.showErrorToast(context, 'Something went wrong');
|
||||
@ -573,51 +575,4 @@ class _pinPageState extends State<pinPage> {
|
||||
]),
|
||||
)));
|
||||
}
|
||||
// Widget build(BuildContext context) {
|
||||
// return Scaffold(
|
||||
// appBar: AppBar(title: Text('Authenticate')),
|
||||
// body: Padding(
|
||||
// padding: const EdgeInsets.all(16.0),
|
||||
// child: Column(
|
||||
// children: [
|
||||
// ElevatedButton(
|
||||
// onPressed: () async {
|
||||
// bool authenticated =
|
||||
// await _authService.authenticateWithBiometrics();
|
||||
// if (authenticated) {
|
||||
// Navigator.pushReplacementNamed(context, 'home');
|
||||
// } else {
|
||||
// ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
// content: Text('Biometric authentication failed'),
|
||||
// ));
|
||||
// }
|
||||
// },
|
||||
// child: Text('Authenticate with Biometric'),
|
||||
// ),
|
||||
// TextField(
|
||||
// controller: _pinController,
|
||||
// decoration: InputDecoration(labelText: 'Enter PIN'),
|
||||
// keyboardType: TextInputType.number,
|
||||
// obscureText: true,
|
||||
// ),
|
||||
// SizedBox(height: 20),
|
||||
// ElevatedButton(
|
||||
// onPressed: () async {
|
||||
// String pin = _pinController.text;
|
||||
// String? savedPin = await _authService.getPin();
|
||||
// if (pin == savedPin) {
|
||||
// Navigator.pushReplacementNamed(context, 'home');
|
||||
// } else {
|
||||
// ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
// content: Text('Incorrect PIN'),
|
||||
// ));
|
||||
// }
|
||||
// },
|
||||
// child: Text('Authenticate with PIN'),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
}
|
||||
|
||||
@ -158,19 +158,6 @@ class _pinSettingPageState extends State<pinSettingPage> {
|
||||
top: 0, // Example value for mobile
|
||||
);
|
||||
}
|
||||
// final defaultPinTheme = PinTheme(
|
||||
// width: 56,
|
||||
// height: 56,
|
||||
// textStyle: TextStyle(
|
||||
// fontSize: 20,
|
||||
// color: Color.fromRGBO(30, 60, 87, 1),
|
||||
// fontWeight: FontWeight.w600,
|
||||
// ),
|
||||
// decoration: BoxDecoration(
|
||||
// border: Border.all(color: Color.fromRGBO(234, 239, 243, 1)),
|
||||
// borderRadius: BorderRadius.circular(20),
|
||||
// ),
|
||||
// );
|
||||
|
||||
final defaultPinTheme = PinTheme(
|
||||
width: 56,
|
||||
@ -664,41 +651,4 @@ class _pinSettingPageState extends State<pinSettingPage> {
|
||||
]),
|
||||
)));
|
||||
}
|
||||
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// return Scaffold(
|
||||
// appBar: AppBar(title: Text('Set PIN and Biometric')),
|
||||
// body: Padding(
|
||||
// padding: const EdgeInsets.all(16.0),
|
||||
// child: Column(
|
||||
// children: [
|
||||
// TextField(
|
||||
// controller: _pinController,
|
||||
// decoration: InputDecoration(labelText: 'Enter PIN'),
|
||||
// keyboardType: TextInputType.number,
|
||||
// obscureText: true,
|
||||
// ),
|
||||
// SizedBox(height: 20),
|
||||
// ElevatedButton(
|
||||
// onPressed: () async {
|
||||
// String pin = _pinController.text;
|
||||
// await _authService.savePin(pin);
|
||||
// bool biometricEnabled =
|
||||
// await _authService.authenticateWithBiometrics();
|
||||
// if (biometricEnabled) {
|
||||
// Navigator.pushReplacementNamed(context, 'home');
|
||||
// } else {
|
||||
// ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
// content: Text('Biometric authentication failed'),
|
||||
// ));
|
||||
// }
|
||||
// },
|
||||
// child: Text('Set PIN and Enable Biometric'),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
}
|
||||
|
||||
@ -12,6 +12,8 @@ import 'package:jwt_decode/jwt_decode.dart';
|
||||
import '../customAppBar/responsive.dart';
|
||||
import '../customAppBar/toastHelper.dart';
|
||||
import '../models/environment.dart';
|
||||
import '../models/platform_helper_mobile.dart'
|
||||
if (dart.library.html) '../models/platform_helper_other.dart';
|
||||
|
||||
class MyVerify extends StatefulWidget {
|
||||
const MyVerify({Key? key}) : super(key: key);
|
||||
@ -157,9 +159,15 @@ class _MyVerifyState extends State<MyVerify> {
|
||||
// Redirect to another page
|
||||
final token = prefs.getString('token');
|
||||
// int skipStatus = prefs.getInt('skipStatus') ?? 1;
|
||||
final mpin = prefs.getString('mpin');
|
||||
|
||||
if (prefs.containsKey('mpin') && mpin != 'Mpin - exist') {
|
||||
// final mpinText = prefs.getString('mpinText');
|
||||
print(isMobilePlatform());
|
||||
if (isMobilePlatform()) {
|
||||
// if (prefs.containsKey('mpin') && mpinText == 'Mpin - exist') {
|
||||
if (token != null && token.isNotEmpty) {
|
||||
Navigator.pushReplacementNamed(context, 'pinSettingPage');
|
||||
}
|
||||
// }
|
||||
} else {
|
||||
if (token != null && token.isNotEmpty) {
|
||||
ToastHelper.showSuccessToast(context, 'Successfully Login');
|
||||
if (emp_status == 'enrolled') {
|
||||
@ -168,8 +176,6 @@ class _MyVerifyState extends State<MyVerify> {
|
||||
Navigator.pushReplacementNamed(context, 'empDetails');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Navigator.pushReplacementNamed(context, 'pinSettingPage');
|
||||
}
|
||||
} else {
|
||||
ToastHelper.showErrorToast(context, 'Invalid OTP. Please try again');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user