From bd750439e517f04cbc7cbd2ac20d4c7dc09ec9e1 Mon Sep 17 00:00:00 2001 From: TIVMOF Date: Wed, 24 Apr 2024 14:19:05 +0300 Subject: [PATCH] Login page --- flutter_bank_ui/lib/main.dart | 1 + flutter_bank_ui/lib/pages/about_page.dart | 6 +- flutter_bank_ui/lib/pages/home_page.dart | 45 +----- flutter_bank_ui/lib/pages/login_page.dart | 34 +++-- flutter_bank_ui/lib/utill/app_bar.dart | 74 +++++----- flutter_bank_ui/lib/utill/my_list_tile.dart | 93 ++++++------ flutter_bank_ui/lib/utill/my_transaction.dart | 134 ++++++++++-------- .../lib/utill/session_manager.dart | 37 +++++ 8 files changed, 226 insertions(+), 198 deletions(-) create mode 100644 flutter_bank_ui/lib/utill/session_manager.dart diff --git a/flutter_bank_ui/lib/main.dart b/flutter_bank_ui/lib/main.dart index c0b2f79..5460bf9 100644 --- a/flutter_bank_ui/lib/main.dart +++ b/flutter_bank_ui/lib/main.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +// import 'package:online_bank/pages/home_page.dart'; import 'pages/login_page.dart'; void main() { diff --git a/flutter_bank_ui/lib/pages/about_page.dart b/flutter_bank_ui/lib/pages/about_page.dart index fe85af3..69eea60 100644 --- a/flutter_bank_ui/lib/pages/about_page.dart +++ b/flutter_bank_ui/lib/pages/about_page.dart @@ -38,7 +38,7 @@ class _AboutPageState extends State { MyRead( content: - '„Пропър Инвест Банк“ АД е учредена на 10 октомври 2022 година Акционерният капитал на Банката възлиза на 13 000 000 лева и е разпределен на 13 безналични, поименни акции, всяка с номинална стойност 1 000 000.00 лева и право на глас.', + '„Пропър Инвест Банк“ АД е учредена на 10 октомври 2022 година Акционерният капитал на Банката възлиза на 13 000 лева и е разпределен на 13 безналични, поименни акции, всяка с номинална стойност 1 000.00 лева и право на глас.', trimLines: 7, align: TextAlign.justify, size: 16, @@ -62,7 +62,7 @@ class _AboutPageState extends State { MyRead( content: - 'Ние ще ви помогнем: Да увеличите средствата чрез депозит; Да увеличите капитала си чрез набирателна сметка; Да плащате и разполагате със средства навсякъде, лесно и удобно с банкова платежна карта', + 'Ние ще ви помогнем: Да увеличите средствата чрез депозит; Да увеличите капитала си чрез набирателна сметка; Да плащате и разполагате със средства навсякъде, лесно и удобно с банкова платежна карта; Да закупите мечтания си дом;', trimLines: 1, align: TextAlign.justify, size: 16, @@ -70,7 +70,7 @@ class _AboutPageState extends State { MyRead( content: - 'Банкови продукти и услуги: Банкови сметки-(Разплащателна сметка, Набирателна сметка, Депозитна сметка, Спестовна сметка); Вложения-(Влогове и депозити); Банкови платежни карти-(Дебитни и кредитни карти); Банкови платежни документи;', + 'Банкови продукти и услуги: Банкови сметки-(Разплащателна сметка, Набирателна сметка, Депозитна сметка, Спестовна сметка); Ипотечни кредити; Вложения-(Влогове и депозити); Банкови платежни карти-(Дебитни и кредитни карти); Банкови платежни документи;', trimLines: 1, align: TextAlign.justify, size: 16, diff --git a/flutter_bank_ui/lib/pages/home_page.dart b/flutter_bank_ui/lib/pages/home_page.dart index 31b2803..bcfcc12 100644 --- a/flutter_bank_ui/lib/pages/home_page.dart +++ b/flutter_bank_ui/lib/pages/home_page.dart @@ -1,19 +1,15 @@ // ignore_for_file: prefer_const_literals_to_create_immutables, prefer_const_constructors, sized_box_for_whitespace import 'package:flutter/material.dart'; -import 'pay_page.dart'; import 'statistics_page.dart'; import 'transaction_page.dart'; import '../utill/app_bar.dart'; import '../utill/bottom_app_bar.dart'; -import '../utill/my_button.dart'; import '../utill/my_card.dart'; import '../utill/my_list_tile.dart'; import 'package:smooth_page_indicator/smooth_page_indicator.dart'; import 'package:online_bank/pages/send_page.dart'; -import 'bills_page.dart'; - class HomePage extends StatefulWidget { const HomePage({super.key}); @@ -85,46 +81,19 @@ class _HomePageState extends State { SizedBox(height: 20), - // 3 buttons ->send + pay + bills + // column -> stats + transaction Padding( - padding: const EdgeInsets.symmetric(horizontal: 25.0), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, + padding: const EdgeInsets.all(25.0), + child: Column( children: [ - // send button - MyButton( + //Send + MyListTile( iconImagePath: 'lib/icons/send.png', - buttonText: 'Прати', + tileTitle: 'Преводи', + tileSubtitle: 'Прати по сметка', page: SendPage(context: context), - is_paying: false, ), - //pay button - MyButton( - iconImagePath: 'lib/icons/credit-card.png', - buttonText: 'Плати', - page: PayPage(context: context), - is_paying: true, - ), - - //bills button - MyButton( - iconImagePath: 'lib/icons/bill.png', - buttonText: 'Сметки', - page: BillsPage(context: context), - is_paying: false, - ), - ], - ), - ), - - SizedBox(height: 20), - - // column -> stats + transaction - Padding( - padding: const EdgeInsets.all(25.0), - child: Column( - children: [ //Stats MyListTile( iconImagePath: 'lib/icons/statistics.png', diff --git a/flutter_bank_ui/lib/pages/login_page.dart b/flutter_bank_ui/lib/pages/login_page.dart index 0cab207..ba76e66 100644 --- a/flutter_bank_ui/lib/pages/login_page.dart +++ b/flutter_bank_ui/lib/pages/login_page.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; import 'home_page.dart'; // Adjust if needed +// import '../utill/session_manager.dart'; // Import your session management class class LoginPage extends StatefulWidget { @override @@ -12,6 +13,8 @@ class _LoginPageState extends State { final TextEditingController _usernameController = TextEditingController(); final TextEditingController _passwordController = TextEditingController(); + final String basicAuth = 'Basic ' + base64Encode(utf8.encode('admin:admin')); + Future _login() async { final username = _usernameController.text.trim(); final password = _passwordController.text.trim(); @@ -24,23 +27,36 @@ class _LoginPageState extends State { return; } - // Example backend authentication (adjust endpoint and request parameters as needed) + // Example backend authentication final response = await http.post( - Uri.parse('https://example.com/api/login'), // Update with your endpoint - headers: {'Content-Type': 'application/json'}, + Uri.parse( + 'http://113.30.151.151:8080/services/ts/dirigible-bank-server-api/user.ts/login'), // Adjust endpoint + headers: {'Content-Type': 'application/json', 'Authorization': basicAuth}, body: json.encode({ - 'username': username, - 'password': password, + 'Username': username, + 'Password': password, }), ); if (response.statusCode == 200) { - // Successful login, navigate to the Home Page + // Parse the session data from the response + // var sessionData = jsonDecode(response.body); + + // Store the session data + // await SessionManager.setSessionId( + // sessionData['sessionId']); // Store session ID + // await SessionManager.setUserId(sessionData['userId']); // Store user ID + + // Navigate to the Home Page Navigator.pushReplacement( context, - MaterialPageRoute(builder: (context) => HomePage()), + MaterialPageRoute( + builder: (context) => + HomePage(), // Corrected extra positional argument + ), ); } else { + print(response.statusCode); // Login failed ScaffoldMessenger.of(context).showSnackBar( SnackBar(content: Text("Login failed. Please try again.")), @@ -53,7 +69,7 @@ class _LoginPageState extends State { return Scaffold( appBar: AppBar(title: Text("Login")), body: Padding( - padding: const EdgeInsets.all(16.0), + padding: const EdgeInsets.all(16), // Ensure padding is provided child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -62,7 +78,7 @@ class _LoginPageState extends State { decoration: InputDecoration(labelText: "Username"), ), TextField( - controller: _passwordController, // Corrected variable name + controller: _passwordController, obscureText: true, decoration: InputDecoration(labelText: "Password"), ), diff --git a/flutter_bank_ui/lib/utill/app_bar.dart b/flutter_bank_ui/lib/utill/app_bar.dart index 54b7de3..9246d0e 100644 --- a/flutter_bank_ui/lib/utill/app_bar.dart +++ b/flutter_bank_ui/lib/utill/app_bar.dart @@ -3,7 +3,6 @@ import 'package:flutter/material.dart'; class MyAppBar extends StatelessWidget { - final String first_name; final String second_name; @@ -11,48 +10,47 @@ class MyAppBar extends StatelessWidget { super.key, required this.first_name, required this.second_name, - }); + }); @override Widget build(BuildContext context) { return Align( - alignment: Alignment.topLeft, - child: Container( - width: 600, - decoration: BoxDecoration( - color: Colors.blue.shade800, - borderRadius: BorderRadius.only( - bottomRight: Radius.circular(95), - ) - ), - child: Padding( - padding: const EdgeInsets.only(left: 30.0, top: 10.0, bottom: 10.0), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Row( - children: [ - Text( - first_name, - style: TextStyle( - fontSize: 28, - fontWeight: FontWeight.bold, - color: Colors.white, - ), - ), - Text( - ' ' + second_name, - style: TextStyle( - fontSize: 28, - color: Colors.white, - ), - ), - ], + alignment: Alignment.topLeft, + child: Container( + width: 600, + decoration: BoxDecoration( + color: Colors.blue.shade800, + borderRadius: BorderRadius.only( + bottomRight: Radius.circular(95), + )), + child: Padding( + padding: const EdgeInsets.only(left: 30.0, top: 10.0, bottom: 10.0), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Row( + children: [ + Text( + first_name, + style: TextStyle( + fontSize: 28, + fontWeight: FontWeight.bold, + color: Colors.white, + ), + ), + Text( + ' ' + second_name, + style: TextStyle( + fontSize: 28, + color: Colors.white, ), - ], ), + ], ), - ), - ); + ], + ), + ), + ), + ); } -} \ No newline at end of file +} diff --git a/flutter_bank_ui/lib/utill/my_list_tile.dart b/flutter_bank_ui/lib/utill/my_list_tile.dart index 21f135c..255a848 100644 --- a/flutter_bank_ui/lib/utill/my_list_tile.dart +++ b/flutter_bank_ui/lib/utill/my_list_tile.dart @@ -4,19 +4,17 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; class MyListTile extends StatelessWidget { - final String iconImagePath; final String tileTitle; final String tileSubtitle; final Widget page; - const MyListTile({ - super.key, - required this.iconImagePath, - required this.tileTitle, - required this.tileSubtitle, - required this.page - }); + const MyListTile( + {super.key, + required this.iconImagePath, + required this.tileTitle, + required this.tileSubtitle, + required this.page}); @override Widget build(BuildContext context) { @@ -25,55 +23,54 @@ class MyListTile extends StatelessWidget { child: ElevatedButton( onPressed: () { HapticFeedback.vibrate(); - Navigator.push(context, MaterialPageRoute(builder: (context) => this.page)); + Navigator.push( + context, MaterialPageRoute(builder: (context) => this.page)); }, style: ElevatedButton.styleFrom( - shadowColor: Colors.transparent, - backgroundColor: Colors.transparent, - foregroundColor: Colors.black, - elevation: 0, - ), + shadowColor: Colors.transparent, + backgroundColor: Colors.transparent, + foregroundColor: Colors.black, + elevation: 0, + ), child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + //Icon + Row( children: [ - //Icon - Row( - children: [ - Container( - height: 80, - padding: EdgeInsets.all(12), - decoration: BoxDecoration( - color: Colors.grey[100], - borderRadius: BorderRadius.circular(12.0), - ), - child: Image.asset(iconImagePath), - ), - - SizedBox(width: 5,), - - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - tileTitle, + Container( + height: 80, + padding: EdgeInsets.all(12), + decoration: BoxDecoration( + color: Colors.grey[100], + borderRadius: BorderRadius.circular(12.0), + ), + child: Image.asset(iconImagePath), + ), + SizedBox( + width: 5, + ), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(tileTitle, style: TextStyle( fontWeight: FontWeight.bold, fontSize: 20, - ) - ), - Text( - tileSubtitle, + )), + Text(tileSubtitle, style: TextStyle( fontSize: 18, - ) - ), - ],), - ], - ), - - Icon(Icons.arrow_forward_ios), - ],), + )), + ], + ), + ], + ), + + Icon(Icons.arrow_forward_ios), + ], + ), ), ); } -} \ No newline at end of file +} diff --git a/flutter_bank_ui/lib/utill/my_transaction.dart b/flutter_bank_ui/lib/utill/my_transaction.dart index c120802..6dded95 100644 --- a/flutter_bank_ui/lib/utill/my_transaction.dart +++ b/flutter_bank_ui/lib/utill/my_transaction.dart @@ -12,7 +12,7 @@ class MyTransaction extends StatelessWidget { required this.date, required this.sum, required this.sentOrReceived, - }); + }); final backgroundSent = Color.fromARGB(255, 189, 201, 226); final textSent = 'Към:'; @@ -32,76 +32,86 @@ class MyTransaction extends StatelessWidget { height: 80, padding: EdgeInsets.only(top: 15, bottom: 15, left: 10, right: 10), decoration: BoxDecoration( - color: sentOrReceived? backgroundReceived: backgroundSent, - borderRadius: BorderRadius.circular(5), - boxShadow: [ - BoxShadow( - color: Color.fromARGB(193, 158, 158, 158).withOpacity(0.5), - spreadRadius: 5, - blurRadius: 10, - offset: Offset(4, 8), - ) - ] - ), + color: sentOrReceived ? backgroundReceived : backgroundSent, + borderRadius: BorderRadius.circular(5), + boxShadow: [ + BoxShadow( + color: Color.fromARGB(193, 158, 158, 158).withOpacity(0.5), + spreadRadius: 5, + blurRadius: 10, + offset: Offset(4, 8), + ) + ]), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Row( - children: [ - Text( - sentOrReceived? textReceived: textSent, - style: TextStyle( - fontSize: 20, - fontWeight: FontWeight.bold + Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Row( + children: [ + Text( + sentOrReceived ? textReceived : textSent, + overflow: TextOverflow.ellipsis, + style: + TextStyle(fontSize: 20, fontWeight: FontWeight.bold), ), - ), - SizedBox(width: 10,), - Text( - recipient, - style: TextStyle( - fontSize: 18, - fontWeight: FontWeight.bold, + SizedBox( + width: 10, ), - ), - ], - ), - Row( - children: [ - Text( - 'Прехвърлени:', - style: TextStyle( - fontSize: 18, - fontWeight: FontWeight.bold, - color: Colors.grey.shade800, + Text( + recipient, + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontSize: 18, + fontWeight: FontWeight.bold, + ), + ), + ], + ), + Row( + children: [ + Text( + 'Прехвърлени:', + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontSize: 18, + fontWeight: FontWeight.bold, + color: Colors.grey.shade800, + ), ), - ), - SizedBox(width: 5,), - Text( - date, - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.bold, - color: Colors.grey.shade700, + SizedBox( + width: 5, ), - ), - ], + Text( + date, + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold, + color: Colors.grey.shade700, + ), + ), + ], + ), + ], + ), + Text( + (sentOrReceived ? plus : minus) + + ' ' + + sum.toStringAsFixed(2) + + 'лв', + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontSize: 18, + color: sentOrReceived ? colorReceived : colorSent, + fontWeight: FontWeight.bold, ), - ], - ), - Text( - (sentOrReceived? plus: minus) + ' ' + sum.toStringAsFixed(2) + 'лв', - style: TextStyle( - fontSize: 18, - color: sentOrReceived? colorReceived: colorSent, - fontWeight: FontWeight.bold, ), - ), - ],), + ], + ), ), ); } -} \ No newline at end of file +} diff --git a/flutter_bank_ui/lib/utill/session_manager.dart b/flutter_bank_ui/lib/utill/session_manager.dart new file mode 100644 index 0000000..afed4d3 --- /dev/null +++ b/flutter_bank_ui/lib/utill/session_manager.dart @@ -0,0 +1,37 @@ +import 'package:shared_preferences/shared_preferences.dart'; + +class SessionManager { + static const _sessionIdKey = 'sessionId'; + static const _userIdKey = 'userId'; + + // Store session ID + static Future setSessionId(String sessionId) async { + final prefs = await SharedPreferences.getInstance(); + await prefs.setString(_sessionIdKey, sessionId); + } + + // Retrieve session ID + static Future getSessionId() async { + final prefs = await SharedPreferences.getInstance(); + return prefs.getString(_sessionIdKey); + } + + // Store user ID + static Future setUserId(String userId) async { + final prefs = await SharedPreferences.getInstance(); + await prefs.setString(_userIdKey, userId); + } + + // Retrieve user ID + static Future getUserId() async { + final prefs = await SharedPreferences.getInstance(); + return prefs.getString(_userIdKey); + } + + // Clear session data + static Future clearSession() async { + final prefs = await SharedPreferences.getInstance(); + await prefs.remove(_sessionIdKey); + await prefs.remove(_userIdKey); + } +}