diff --git a/lib/pages/login_page.dart b/lib/pages/login_page.dart index 9fbf443..f6b4a84 100644 --- a/lib/pages/login_page.dart +++ b/lib/pages/login_page.dart @@ -1,5 +1,10 @@ +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'; @@ -15,7 +20,8 @@ class LoginPage extends StatefulWidget { class _LoginPageState extends State { final _passwordController = TextEditingController(); - final _approver = "ARCH. KHASHAYAR L. TOGHYANI"; + final _approver = dotenv.env['HEAD']!; + final _approverId = dotenv.env['HEADID']!; late ValueNotifier passwordNotifier; @override @@ -27,8 +33,45 @@ class _LoginPageState extends State { }); } - void _login() { - debugPrint("Login button clicked"); + Future _checkConnection() async { + try { + final connection = await getApi('check-connection', null, null); + return connection["result"]; + } catch (e) { + return false; + } + } + + Future _getPassword(String employeeid) async { + try { + final response = await getApi('get-password', employeeid, null); + return (response["result"]); + } catch (e) { + return "0"; + } + } + + Future _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() {} diff --git a/lib/pages/validate_page.dart b/lib/pages/validate_page.dart index d1eca99..47b5035 100644 --- a/lib/pages/validate_page.dart +++ b/lib/pages/validate_page.dart @@ -43,11 +43,20 @@ class _BarcodeScannerScreenState extends State { ), child: Center( child: Padding( - padding: const EdgeInsets.only(top: 64, left: 16, right: 16), + padding: const EdgeInsets.only(top: 88, left: 16, right: 16), child: Column( children: [ - Expanded( - flex: 2, + Container( + padding: EdgeInsets.only(top: 8, bottom: 8, left: 20, right: 20), + decoration: BoxDecoration( + color: Color.fromARGB(149, 16, 22, 28), + borderRadius: BorderRadius.circular(8), + ), + child: TextWidget(text: 'Scan OCBO e-Sign QR Code', size: 14, bold: true), + ), + Gap(50), + SizedBox( + height: 350, child: ClipRRect( borderRadius: BorderRadius.circular(20), // Adjust the radius as needed child: MobileScanner( @@ -63,15 +72,6 @@ class _BarcodeScannerScreenState extends State { ), ), ), - Expanded( - flex: 2, - child: Column( - children: [ - Gap(20), - TextWidget(text: 'Scan OCBO e-Sign QR', size: 20, bold: true), - ], - ), - ), ], ), ),