Fix session not working
This commit is contained in:
parent
2b0ac1ed0b
commit
61fd4a44a1
@ -9,6 +9,8 @@ import 'package:manager_app/client.dart';
|
|||||||
import 'package:manager_app/constants.dart';
|
import 'package:manager_app/constants.dart';
|
||||||
import 'package:manager_api_new/api.dart';
|
import 'package:manager_api_new/api.dart';
|
||||||
|
|
||||||
|
import 'dart:html' as html;
|
||||||
|
|
||||||
class FileHelper {
|
class FileHelper {
|
||||||
final key = Key.fromUtf8('aVs:ZMe3EK-yS<y:;k>vCGrj3T8]yG6E');
|
final key = Key.fromUtf8('aVs:ZMe3EK-yS<y:;k>vCGrj3T8]yG6E');
|
||||||
final iv = IV.fromLength(16);
|
final iv = IV.fromLength(16);
|
||||||
@ -25,17 +27,14 @@ class FileHelper {
|
|||||||
return File('$path/session.json');
|
return File('$path/session.json');
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<File> writeSession(Session session) async {
|
Future<void> writeSession(Session session) async {
|
||||||
final file = await _localFile;
|
|
||||||
|
|
||||||
if (session.password != null) {
|
if (session.password != null) {
|
||||||
var encrypter = Encrypter(AES(key));
|
var encrypter = Encrypter(AES(key));
|
||||||
var encrypted = encrypter.encrypt(session.password!, iv: iv);
|
var encrypted = encrypter.encrypt(session.password!, iv: iv);
|
||||||
|
|
||||||
session.password = encrypted.base64;
|
session.password = encrypted.base64;
|
||||||
}
|
}
|
||||||
// Write the file
|
|
||||||
return file.writeAsString(jsonEncode(session.toMap()));
|
html.window.localStorage['session'] = jsonEncode(session.toMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<File> storeConfiguration(ExportConfigurationDTO exportConfigurationDTO) async {
|
Future<File> storeConfiguration(ExportConfigurationDTO exportConfigurationDTO) async {
|
||||||
@ -65,7 +64,7 @@ class FileHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Session> readSession() async {
|
/*Future<Session> readSessionWeb() async {
|
||||||
try {
|
try {
|
||||||
final file = await _localFile;
|
final file = await _localFile;
|
||||||
// Read the file
|
// Read the file
|
||||||
@ -89,5 +88,24 @@ class FileHelper {
|
|||||||
// If encountering an error, return 0
|
// If encountering an error, return 0
|
||||||
return Session(rememberMe: false);
|
return Session(rememberMe: false);
|
||||||
}
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
Future<Session> readSessionWeb() async {
|
||||||
|
try {
|
||||||
|
final jsonString = html.window.localStorage['session'];
|
||||||
|
if (jsonString != null) {
|
||||||
|
return Session.fromJson(jsonDecode(jsonString));
|
||||||
|
} else {
|
||||||
|
final newSession = Session(rememberMe: false);
|
||||||
|
html.window.localStorage['session'] = jsonEncode(newSession.toMap());
|
||||||
|
return newSession;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return Session(rememberMe: false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> writeSessionWeb(Session session) async {
|
||||||
|
html.window.localStorage['session'] = jsonEncode(session.toMap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,4 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:manager_app/Models/session.dart';
|
||||||
import 'package:manager_app/client.dart';
|
import 'package:manager_app/client.dart';
|
||||||
import 'package:manager_api_new/api.dart';
|
import 'package:manager_api_new/api.dart';
|
||||||
|
|
||||||
|
|||||||
@ -2,16 +2,20 @@ class Session {
|
|||||||
bool rememberMe;
|
bool rememberMe;
|
||||||
String? host;
|
String? host;
|
||||||
String? email;
|
String? email;
|
||||||
|
String? token;
|
||||||
String? password;
|
String? password;
|
||||||
|
String? instanceId;
|
||||||
|
|
||||||
Session({required this.rememberMe, this.host, this.email, this.password});
|
Session({required this.rememberMe, this.host, this.email, this.token, this.password, this.instanceId});
|
||||||
|
|
||||||
factory Session.fromJson(Map<String, dynamic> json) {
|
factory Session.fromJson(Map<String, dynamic> json) {
|
||||||
return new Session(
|
return new Session(
|
||||||
rememberMe: json['rememberMe'] as bool,
|
rememberMe: json['rememberMe'] as bool,
|
||||||
host: json['host'] as String,
|
host: json['host'] as String,
|
||||||
email: json['email'] as String,
|
email: json['email'] as String,
|
||||||
password: json['password'] as String
|
token: json['token'] as String,
|
||||||
|
password: json['password'] as String,
|
||||||
|
instanceId: json['instanceId'] as String,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,12 +24,14 @@ class Session {
|
|||||||
'rememberMe': rememberMe,
|
'rememberMe': rememberMe,
|
||||||
'host': host,
|
'host': host,
|
||||||
'email': email,
|
'email': email,
|
||||||
'password': password
|
'token': token,
|
||||||
|
'password': password,
|
||||||
|
'instanceId': instanceId
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return '{rememberMe: $rememberMe, host: $host, email: $email, password: $password}';
|
return '{rememberMe: $rememberMe, host: $host, email: $email, token: $token, password: $password, instanceId: $instanceId}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -29,14 +29,11 @@ class _AppConfigurationLinkScreenState extends State<AppConfigurationLinkScreen>
|
|||||||
return FutureBuilder(
|
return FutureBuilder(
|
||||||
future: getAppConfigurationLink(appContext, widget.applicationInstanceDTO),
|
future: getAppConfigurationLink(appContext, widget.applicationInstanceDTO),
|
||||||
builder: (context, AsyncSnapshot<dynamic> snapshot) {
|
builder: (context, AsyncSnapshot<dynamic> snapshot) {
|
||||||
|
|
||||||
var test = snapshot.data;
|
|
||||||
|
|
||||||
List<AppConfigurationLinkDTO>? appConfigurationLinks = snapshot.data;
|
List<AppConfigurationLinkDTO>? appConfigurationLinks = snapshot.data;
|
||||||
|
|
||||||
if (snapshot.connectionState == ConnectionState.done) {
|
if (snapshot.connectionState == ConnectionState.done) {
|
||||||
final screenWidth = MediaQuery.of(context).size.width;
|
final screenWidth = MediaQuery.of(context).size.width;
|
||||||
final itemWidth = 150; // largeur idéale d'une cellule
|
final itemWidth = 175;
|
||||||
|
|
||||||
final crossAxisCount = (screenWidth / itemWidth).floor().clamp(1, 6);
|
final crossAxisCount = (screenWidth / itemWidth).floor().clamp(1, 6);
|
||||||
return Container(
|
return Container(
|
||||||
|
|||||||
@ -147,11 +147,16 @@ class _BodyState extends State<Body> {
|
|||||||
ManagerAppContext managerAppContext = appContext.getContext();
|
ManagerAppContext managerAppContext = appContext.getContext();
|
||||||
managerAppContext.accessToken = null;
|
managerAppContext.accessToken = null;
|
||||||
appContext.setContext(managerAppContext);
|
appContext.setContext(managerAppContext);
|
||||||
Navigator.pushAndRemoveUntil(
|
Navigator.pushNamedAndRemoveUntil(
|
||||||
|
context,
|
||||||
|
'/login',
|
||||||
|
(Route<dynamic> route) => false,
|
||||||
|
);
|
||||||
|
/*Navigator.pushAndRemoveUntil(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(builder: (context) => LoginScreen(session: session)),
|
MaterialPageRoute(builder: (context) => LoginScreen(session: session)),
|
||||||
(route) => false,
|
(route) => false,
|
||||||
);
|
);*/
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
@ -6,7 +6,9 @@ import 'package:manager_app/Models/menu.dart';
|
|||||||
import 'package:manager_app/Models/menuSection.dart';
|
import 'package:manager_app/Models/menuSection.dart';
|
||||||
import 'package:manager_app/Screens/Main/components/body.dart';
|
import 'package:manager_app/Screens/Main/components/body.dart';
|
||||||
import 'package:manager_app/app_context.dart';
|
import 'package:manager_app/app_context.dart';
|
||||||
|
import 'package:manager_app/client.dart';
|
||||||
import 'package:manager_app/constants.dart';
|
import 'package:manager_app/constants.dart';
|
||||||
|
import 'package:manager_app/main.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:responsive_framework/responsive_framework.dart';
|
import 'package:responsive_framework/responsive_framework.dart';
|
||||||
|
|
||||||
@ -24,8 +26,6 @@ class _MainScreenState extends State<MainScreen> {
|
|||||||
final appContext = Provider.of<AppContext>(context);
|
final appContext = Provider.of<AppContext>(context);
|
||||||
Size size = MediaQuery.of(context).size;
|
Size size = MediaQuery.of(context).size;
|
||||||
|
|
||||||
ManagerAppContext managerAppContext = appContext.getContext() as ManagerAppContext;
|
|
||||||
|
|
||||||
//var isFortSt = managerAppContext.instanceId == "633ee379d9405f32f166f047";
|
//var isFortSt = managerAppContext.instanceId == "633ee379d9405f32f166f047";
|
||||||
|
|
||||||
return FutureBuilder(
|
return FutureBuilder(
|
||||||
@ -56,10 +56,32 @@ class _MainScreenState extends State<MainScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<InstanceDTO?> getInstanceInfo(AppContext appContext) async {
|
Future<InstanceDTO?> getInstanceInfo(AppContext appContext) async {
|
||||||
|
|
||||||
|
var session = await loadJsonSessionFile();
|
||||||
|
|
||||||
|
try {
|
||||||
ManagerAppContext managerAppContext = appContext.getContext() as ManagerAppContext;
|
ManagerAppContext managerAppContext = appContext.getContext() as ManagerAppContext;
|
||||||
|
managerAppContext.instanceId = managerAppContext.instanceId ?? session.instanceId;
|
||||||
|
managerAppContext.host = managerAppContext.host ?? session.host;
|
||||||
|
managerAppContext.accessToken = managerAppContext.accessToken ?? session.token;
|
||||||
|
managerAppContext.email = managerAppContext.email ?? session.email;
|
||||||
|
|
||||||
|
if(managerAppContext.clientAPI == null) {
|
||||||
|
managerAppContext.clientAPI = Client(session.host!);
|
||||||
|
managerAppContext.clientAPI!.apiApi!.addDefaultHeader('authorization', 'Bearer '+ managerAppContext.accessToken!);
|
||||||
|
}
|
||||||
|
|
||||||
InstanceDTO? instance = await managerAppContext.clientAPI!.instanceApi!.instanceGetDetail(managerAppContext.instanceId!);
|
InstanceDTO? instance = await managerAppContext.clientAPI!.instanceApi!.instanceGetDetail(managerAppContext.instanceId!);
|
||||||
managerAppContext.instanceDTO = instance;
|
managerAppContext.instanceDTO = instance;
|
||||||
return instance;
|
return instance;
|
||||||
|
} catch(e) {
|
||||||
|
Navigator.pushNamedAndRemoveUntil(
|
||||||
|
context,
|
||||||
|
'/login',
|
||||||
|
(Route<dynamic> route) => false,
|
||||||
|
);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import 'package:manager_app/Components/message_notification.dart';
|
|||||||
import 'package:manager_app/Components/rounded_button.dart';
|
import 'package:manager_app/Components/rounded_button.dart';
|
||||||
import 'package:manager_app/Components/rounded_input_field.dart';
|
import 'package:manager_app/Components/rounded_input_field.dart';
|
||||||
import 'package:manager_app/Components/rounded_password_field.dart';
|
import 'package:manager_app/Components/rounded_password_field.dart';
|
||||||
|
import 'package:manager_app/Helpers/FileHelper.dart';
|
||||||
import 'package:manager_app/Models/managerContext.dart';
|
import 'package:manager_app/Models/managerContext.dart';
|
||||||
import 'package:manager_app/Models/session.dart';
|
import 'package:manager_app/Models/session.dart';
|
||||||
import 'package:manager_app/Screens/Main/main_screen.dart';
|
import 'package:manager_app/Screens/Main/main_screen.dart';
|
||||||
@ -121,6 +122,7 @@ class _LoginScreenState extends State<LoginScreen> {
|
|||||||
managerAppContext.accessToken = accessToken;
|
managerAppContext.accessToken = accessToken;
|
||||||
managerAppContext.clientAPI = clientAPI;
|
managerAppContext.clientAPI = clientAPI;
|
||||||
setAccessToken(accessToken);
|
setAccessToken(accessToken);
|
||||||
|
FileHelper().writeSession(new Session(rememberMe: true, instanceId: instanceId, host: host, token: accessToken, password: password, email: email));
|
||||||
appContext.setContext(managerAppContext);
|
appContext.setContext(managerAppContext);
|
||||||
|
|
||||||
if(fromClick) {
|
if(fromClick) {
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import 'Screens/login_screen.dart';
|
|||||||
import 'Screens/Policy/policy_screen.dart';
|
import 'Screens/Policy/policy_screen.dart';
|
||||||
import 'app_context.dart';
|
import 'app_context.dart';
|
||||||
import 'constants.dart';
|
import 'constants.dart';
|
||||||
|
import 'package:flutter_web_plugins/url_strategy.dart';
|
||||||
//import 'package:window_size/window_size.dart';
|
//import 'package:window_size/window_size.dart';
|
||||||
|
|
||||||
Future<void> main() async {
|
Future<void> main() async {
|
||||||
@ -23,7 +24,8 @@ Future<void> main() async {
|
|||||||
|
|
||||||
var session = await loadJsonSessionFile();
|
var session = await loadJsonSessionFile();
|
||||||
|
|
||||||
ManagerAppContext managerAppContext = new ManagerAppContext();
|
ManagerAppContext managerAppContext = ManagerAppContext();
|
||||||
|
managerAppContext.instanceId = session.instanceId;
|
||||||
|
|
||||||
final MyApp myApp = MyApp(
|
final MyApp myApp = MyApp(
|
||||||
initialRoute: initialRoute,
|
initialRoute: initialRoute,
|
||||||
@ -45,6 +47,8 @@ Future<void> main() async {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
usePathUrlStrategy();
|
||||||
|
|
||||||
runApp(myApp);
|
runApp(myApp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +113,7 @@ class _MyAppState extends State<MyApp> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<Session> loadJsonSessionFile() async {
|
Future<Session> loadJsonSessionFile() async {
|
||||||
Session session = await FileHelper().readSession();
|
Session session = await FileHelper().readSessionWeb();
|
||||||
//print(session);
|
//print(session);
|
||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -492,7 +492,7 @@ packages:
|
|||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
version: "0.0.0"
|
||||||
flutter_web_plugins:
|
flutter_web_plugins:
|
||||||
dependency: transitive
|
dependency: "direct dev"
|
||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
version: "0.0.0"
|
||||||
|
|||||||
@ -78,6 +78,8 @@ dev_dependencies:
|
|||||||
sdk: flutter
|
sdk: flutter
|
||||||
build_runner:
|
build_runner:
|
||||||
openapi_generator: ^6.1.0
|
openapi_generator: ^6.1.0
|
||||||
|
flutter_web_plugins:
|
||||||
|
sdk: flutter
|
||||||
|
|
||||||
# For information on the generic Dart part of this file, see the
|
# For information on the generic Dart part of this file, see the
|
||||||
# following page: https://dart.dev/tools/pub/pubspec
|
# following page: https://dart.dev/tools/pub/pubspec
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user