156 lines
4.9 KiB
Dart
156 lines
4.9 KiB
Dart
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:ocbo_esign_mobile/widgets/box_widget.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';
|
|
import 'package:ocbo_esign_mobile/widgets/login_box_widget.dart';
|
|
import 'package:ocbo_esign_mobile/widgets/text_widget.dart';
|
|
|
|
class LoginPage extends StatefulWidget {
|
|
const LoginPage({super.key});
|
|
|
|
@override
|
|
State<LoginPage> createState() => _LoginPageState();
|
|
}
|
|
|
|
class _LoginPageState extends State<LoginPage> {
|
|
final _passwordController = TextEditingController();
|
|
final _approver = dotenv.env['HEAD']!;
|
|
final _approverId = dotenv.env['HEADID']!;
|
|
late ValueNotifier<String> passwordNotifier;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
passwordNotifier = ValueNotifier(_passwordController.text);
|
|
_passwordController.addListener(() {
|
|
passwordNotifier.value = _passwordController.text;
|
|
});
|
|
}
|
|
|
|
// 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> _securePassword(String password) async {
|
|
final firstHash = sha1.string(password);
|
|
final secondHash = sha384.string(firstHash.toString());
|
|
final thirdHash = sha1.string(secondHash.toString());
|
|
|
|
return thirdHash.toString();
|
|
}
|
|
|
|
// void _login() async {
|
|
// final connected = await _checkConnection();
|
|
|
|
// 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();
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
void _setLogin() {
|
|
blocSetUser(context, _approver);
|
|
context.push('/approval');
|
|
}
|
|
|
|
void _showDialog() {
|
|
showModal(context, 'Error', 'Invalid password, try again.', true);
|
|
}
|
|
|
|
void _ignoreButton() {}
|
|
|
|
@override
|
|
void dispose() {
|
|
_passwordController.dispose();
|
|
passwordNotifier.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
resizeToAvoidBottomInset: false,
|
|
body: Container(
|
|
alignment: Alignment.center,
|
|
height: MediaQuery.of(context).size.height,
|
|
decoration: const BoxDecoration(
|
|
gradient: LinearGradient(
|
|
begin: Alignment.topCenter,
|
|
end: Alignment.bottomCenter,
|
|
colors: [
|
|
Color.fromRGBO(37, 25, 44, 1),
|
|
Color.fromRGBO(22, 33, 44, 1),
|
|
Color.fromRGBO(22, 33, 44, 1),
|
|
Color.fromRGBO(22, 33, 44, 1),
|
|
Color.fromRGBO(25, 46, 41, 1),
|
|
],
|
|
),
|
|
),
|
|
child: Column(
|
|
children: [
|
|
const Gap(88),
|
|
const ImageWidget(imagePath: 'assets/logo.webp', size: 100, measureByHeight: true),
|
|
const Gap(58),
|
|
LoginBoxWidget(
|
|
title: 'Login',
|
|
content: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
const TextWidget(text: 'Name', bold: true, size: 16),
|
|
const Gap(8),
|
|
TextWidget(text: _approver, bold: false, size: 16),
|
|
const Gap(16),
|
|
const TextWidget(text: 'Password', bold: true, size: 16),
|
|
const Gap(8),
|
|
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,
|
|
// );
|
|
// },
|
|
// ),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|