Updated pages
This commit is contained in:
parent
6a565815fc
commit
57ea482f66
3 changed files with 141 additions and 79 deletions
|
|
@ -1,11 +1,13 @@
|
|||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
// import 'package:go_router/go_router.dart';
|
||||
// import 'package:hashlib/hashlib.dart';
|
||||
// import 'package:ocbo_esign_mobile/blocs/user/functions/bloc_setuser.dart';
|
||||
// import 'package:ocbo_esign_mobile/functions/get_api.dart';
|
||||
// import 'package:ocbo_esign_mobile/functions/modal.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hashlib/hashlib.dart';
|
||||
import 'package:ocbo_esign_mobile/blocs/user/functions/bloc_setuser.dart';
|
||||
import 'package:ocbo_esign_mobile/functions/get_api.dart';
|
||||
import 'package:ocbo_esign_mobile/functions/modal.dart';
|
||||
import 'package:ocbo_esign_mobile/widgets/button_widget.dart';
|
||||
import 'package:ocbo_esign_mobile/widgets/image_widget.dart';
|
||||
import 'package:ocbo_esign_mobile/widgets/input_widget.dart';
|
||||
|
|
@ -22,7 +24,7 @@ class LoginPage extends StatefulWidget {
|
|||
class _LoginPageState extends State<LoginPage> {
|
||||
final _passwordController = TextEditingController();
|
||||
final _approver = dotenv.env['HEAD']!;
|
||||
// final _approverId = dotenv.env['HEADID']!;
|
||||
final _approverId = dotenv.env['HEADID']!;
|
||||
late ValueNotifier<String> passwordNotifier;
|
||||
|
||||
@override
|
||||
|
|
@ -34,58 +36,58 @@ class _LoginPageState extends State<LoginPage> {
|
|||
});
|
||||
}
|
||||
|
||||
// Future<bool> _checkConnection() async {
|
||||
// try {
|
||||
// final connection = await getApi('check-connection', null, null);
|
||||
// return connection["result"];
|
||||
// } catch (e) {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
Future<bool> _checkConnection() async {
|
||||
try {
|
||||
final connection = await getApi('check-connection', null, null);
|
||||
return connection["result"];
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Future<String> _getPassword(String employeeid) async {
|
||||
// try {
|
||||
// final response = await getApi('get-password', employeeid, null);
|
||||
// return (response["result"]);
|
||||
// } catch (e) {
|
||||
// return "0";
|
||||
// }
|
||||
// }
|
||||
Future<String> _getPassword(String employeeid) async {
|
||||
try {
|
||||
final response = await getApi('get-password', employeeid, null);
|
||||
return (response["result"]);
|
||||
} catch (e) {
|
||||
return "0";
|
||||
}
|
||||
}
|
||||
|
||||
// Future<String> _securePassword(String password) async {
|
||||
// final firstHash = sha1.string(password);
|
||||
// final secondHash = sha384.string(firstHash.toString());
|
||||
// final thirdHash = sha1.string(secondHash.toString());
|
||||
Future<String> _securePassword(String password) async {
|
||||
final firstHash = sha1.string(password);
|
||||
final secondHash = sha384.string(firstHash.toString());
|
||||
final thirdHash = sha1.string(secondHash.toString());
|
||||
|
||||
// return thirdHash.toString();
|
||||
// }
|
||||
return thirdHash.toString();
|
||||
}
|
||||
|
||||
// void _login() async {
|
||||
// final connected = await _checkConnection();
|
||||
void _login() async {
|
||||
final connected = await _checkConnection();
|
||||
|
||||
// if (connected) {
|
||||
// final employeeid = _approverId;
|
||||
// final dbpassword = await _getPassword(employeeid);
|
||||
// final hashPassword = await _securePassword(_passwordController.text);
|
||||
if (connected) {
|
||||
final employeeid = _approverId;
|
||||
final dbpassword = await _getPassword(employeeid);
|
||||
final hashPassword = await _securePassword(_passwordController.text);
|
||||
|
||||
// if (context.mounted) {
|
||||
// if (dbpassword == hashPassword) {
|
||||
// _setLogin();
|
||||
// } else {
|
||||
// _showDialog();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
if (context.mounted) {
|
||||
if (dbpassword == hashPassword) {
|
||||
_setLogin();
|
||||
} else {
|
||||
_showDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// void _setLogin() {
|
||||
// blocSetUser(context, _approver);
|
||||
// context.push('/approval');
|
||||
// }
|
||||
void _setLogin() {
|
||||
blocSetUser(context, _approver);
|
||||
context.push('/approval');
|
||||
}
|
||||
|
||||
// void _showDialog() {
|
||||
// showModal(context, 'Error', 'Invalid password, try again.', true);
|
||||
// }
|
||||
void _showDialog() {
|
||||
showModal(context, 'Error', 'Invalid password, try again.', true);
|
||||
}
|
||||
|
||||
void _ignoreButton() {}
|
||||
|
||||
|
|
@ -135,28 +137,28 @@ class _LoginPageState extends State<LoginPage> {
|
|||
InputWidget(controller: _passwordController, password: true),
|
||||
const Gap(24),
|
||||
|
||||
// ValueListenableBuilder<String>(
|
||||
// valueListenable: passwordNotifier,
|
||||
// builder: (context, password, child) {
|
||||
// return ButtonWidget(
|
||||
// text: password.isNotEmpty ? 'Login' : 'Required password',
|
||||
// onPressed: password.isNotEmpty ? _login : _ignoreButton,
|
||||
// disabled: password.isEmpty,
|
||||
// );
|
||||
// },
|
||||
// ),
|
||||
ValueListenableBuilder<String>(
|
||||
valueListenable: passwordNotifier,
|
||||
builder: (context, password, child) {
|
||||
return ButtonWidget(
|
||||
text: _passwordController.text.isNotEmpty
|
||||
? "Stop typing, login not ready"
|
||||
: 'Not yet functional',
|
||||
onPressed: _ignoreButton,
|
||||
disabled: true,
|
||||
text: password.isNotEmpty ? 'Login' : 'Required password',
|
||||
onPressed: password.isNotEmpty ? _login : _ignoreButton,
|
||||
disabled: password.isEmpty,
|
||||
);
|
||||
},
|
||||
),
|
||||
// ValueListenableBuilder<String>(
|
||||
// valueListenable: passwordNotifier,
|
||||
// builder: (context, password, child) {
|
||||
// return ButtonWidget(
|
||||
// text: _passwordController.text.isNotEmpty
|
||||
// ? "Stop typing, login not ready"
|
||||
// : 'Not yet functional',
|
||||
// onPressed: _ignoreButton,
|
||||
// disabled: true,
|
||||
// );
|
||||
// },
|
||||
// ),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue