141 lines
4.3 KiB
Dart
141 lines
4.3 KiB
Dart
import 'dart:developer';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
|
import 'package:gap/gap.dart';
|
|
import 'package:hashlib/hashlib.dart';
|
|
import 'package:ocbo_esign_validator/functions/get_api.dart';
|
|
import 'package:ocbo_esign_validator/widgets/box_widget.dart';
|
|
import 'package:ocbo_esign_validator/widgets/button_widget.dart';
|
|
import 'package:ocbo_esign_validator/widgets/image_widget.dart';
|
|
import 'package:ocbo_esign_validator/widgets/input_widget.dart';
|
|
import 'package:ocbo_esign_validator/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 (dbpassword == hashPassword) {
|
|
log('yeah');
|
|
} else {
|
|
log('no');
|
|
}
|
|
}
|
|
}
|
|
|
|
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(39, 26, 47, 1),
|
|
Color.fromRGBO(22, 33, 44, 1),
|
|
Color.fromRGBO(22, 33, 44, 1),
|
|
Color.fromRGBO(24, 45, 40, 1),
|
|
],
|
|
),
|
|
),
|
|
child: Column(
|
|
children: [
|
|
const Gap(88),
|
|
const ImageWidget(imagePath: 'assets/logo.png', size: 100, measureByHeight: true),
|
|
const Gap(58),
|
|
BoxWidget(
|
|
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,
|
|
);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|