Fix fail connection
This commit is contained in:
parent
a3a62d1903
commit
5fadf3943f
@ -30,7 +30,7 @@ class LoginScreen extends StatefulWidget {
|
||||
class _LoginScreenState extends State<LoginScreen> {
|
||||
String email = ""; // DEV "test@email.be"
|
||||
String password = ""; // DEV = "kljqsdkljqsd"
|
||||
String? host; // DEV = "http://192.168.31.96"
|
||||
String? host = "https://api.mymuseum.be"; // DEV = "http://192.168.31.96"
|
||||
Client? clientAPI;
|
||||
bool isLoading = false;
|
||||
bool isRememberMe = false;
|
||||
@ -46,9 +46,7 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
this.email = "test@email.be";
|
||||
this.password = "kljqsdkljqsd";*/
|
||||
|
||||
if(this.host != null) {
|
||||
clientAPI = Client(this.host!);
|
||||
}
|
||||
clientAPI = Client(this.host!);
|
||||
|
||||
if (this.email != null && this.password != null || this.token != null) {
|
||||
|
||||
@ -64,77 +62,80 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
|
||||
var accessToken = this.token;
|
||||
var instanceId = this.instanceId;
|
||||
print("accessToken");
|
||||
print(accessToken);
|
||||
if(accessToken == null) {
|
||||
LoginDTO loginDTO = new LoginDTO(email: email, password: password);
|
||||
TokenDTO? token = await clientAPI!.authenticationApi!.authenticationAuthenticateWithJson(loginDTO);
|
||||
print(email);
|
||||
print(password);
|
||||
|
||||
TokenDTO? token = await clientAPI!.authenticationApi!
|
||||
.authenticationAuthenticateWithJson(loginDTO);
|
||||
|
||||
print("TOKENNN");
|
||||
print(token);
|
||||
|
||||
if(token != null) {
|
||||
accessToken = token.accessToken!;
|
||||
instanceId = token.instanceId!;
|
||||
|
||||
showNotification(kSuccess, kWhite, 'Connexion réussie', context, null);
|
||||
showNotification(
|
||||
kSuccess, kWhite, 'Connexion réussie', context, null);
|
||||
|
||||
if(isRememberMe) {
|
||||
if(!localStorage.containsKey("remember")) {
|
||||
if (isRememberMe) {
|
||||
if (!localStorage.containsKey("remember")) {
|
||||
localStorage.addEntries({"remember": "true"}.entries);
|
||||
}
|
||||
|
||||
if(!localStorage.containsKey("email") && !localStorage.containsKey("token")) {
|
||||
localStorage.addEntries({"email": email!}.entries);
|
||||
if (!localStorage.containsKey("email") &&
|
||||
!localStorage.containsKey("token")) {
|
||||
localStorage.addEntries({"email": email}.entries);
|
||||
localStorage.addEntries({"token": token.accessToken!}.entries);
|
||||
localStorage.addEntries({"instanceId": token.instanceId!}.entries);
|
||||
localStorage.addEntries(
|
||||
{"instanceId": token.instanceId!}.entries);
|
||||
}
|
||||
} else {
|
||||
localStorage.clear();
|
||||
}
|
||||
// Desktop
|
||||
/*if (isRememberMe) {
|
||||
Session updatedSession = new Session(rememberMe: isRememberMe, host: host, email: email, password: password);
|
||||
// update JSON FILE
|
||||
FileHelper().writeSession(updatedSession);
|
||||
}*/
|
||||
|
||||
ManagerAppContext? managerAppContext = appContext.getContext();
|
||||
// Set the appContext
|
||||
if (managerAppContext == null) {
|
||||
managerAppContext = new ManagerAppContext();
|
||||
}
|
||||
|
||||
// store user info locally
|
||||
managerAppContext.email = email;
|
||||
managerAppContext.host = host;
|
||||
managerAppContext.instanceId = instanceId;
|
||||
managerAppContext.accessToken = accessToken;
|
||||
managerAppContext.clientAPI = clientAPI;
|
||||
setAccessToken(accessToken);
|
||||
//print(managerAppContext);
|
||||
|
||||
appContext.setContext(managerAppContext);
|
||||
|
||||
if(fromClick) {
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
});
|
||||
}
|
||||
|
||||
//Navigator.pushNamed(context, '/main');
|
||||
|
||||
/*Navigator.pushNamedAndRemoveUntil(
|
||||
context,
|
||||
'/main',
|
||||
(Route<dynamic> route) => false // For pushAndRemoveUntil
|
||||
);*/
|
||||
|
||||
Navigator.pushAndRemoveUntil(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) {
|
||||
return MainScreen();
|
||||
},
|
||||
),
|
||||
(Route<dynamic> route) => false // For pushAndRemoveUntil
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(accessToken != null) {
|
||||
ManagerAppContext? managerAppContext = appContext.getContext();
|
||||
// Set the appContext
|
||||
if (managerAppContext == null) {
|
||||
managerAppContext = new ManagerAppContext();
|
||||
}
|
||||
|
||||
// store user info locally
|
||||
managerAppContext.email = email;
|
||||
managerAppContext.host = host;
|
||||
managerAppContext.instanceId = instanceId;
|
||||
managerAppContext.accessToken = accessToken;
|
||||
managerAppContext.clientAPI = clientAPI;
|
||||
setAccessToken(accessToken);
|
||||
appContext.setContext(managerAppContext);
|
||||
|
||||
if(fromClick) {
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
});
|
||||
}
|
||||
Navigator.pushAndRemoveUntil(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) {
|
||||
return MainScreen();
|
||||
},
|
||||
),
|
||||
(Route<dynamic> route) => false // For pushAndRemoveUntil
|
||||
);
|
||||
} else {
|
||||
showNotification(Colors.orange, kWhite, 'Un problème est survenu lors de la connexion', context, null);
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user