login debug

This commit is contained in:
mr 2024-11-27 10:54:10 +01:00
parent e73ca6b532
commit 2c86e90b76
3 changed files with 15 additions and 12 deletions

View File

@ -3,6 +3,7 @@ import 'package:localstorage/localstorage.dart';
import 'package:oc_front/core/sections/header/header.dart';
import 'package:oc_front/core/services/api_service.dart';
import 'package:oc_front/core/services/perms_service.dart';
import 'package:oc_front/main.dart';
import 'package:oc_front/models/response.dart';
class AuthService {
static var isAuth = const bool.fromEnvironment('AUTH_MODE', defaultValue: false);
@ -60,7 +61,7 @@ class AuthService {
static Future<void> logout() async {
var token = await service.delete("/ldap/logout", null);
if (token.code == 200 && token.data != null) {
if (token.code == 200) {
localStorage.setItem('accessToken', '');
localStorage.setItem('username', '');
localStorage.setItem('expiresIn', '');

View File

@ -86,14 +86,11 @@ class MainPageState extends State<MainPage> {
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
// than having to individually change instances of widgets.i
scaffoldKey = GlobalKey<ScaffoldState>();
isCtrl = false;
return FutureBuilder(future: AuthService.init(),
builder: (e, s) {
WorkspaceLocal.init(context, false);
CollaborativeAreaLocal.init(context, false);
if (!AuthService.isConnected()) {
if (!AuthService.isConnected()) {
print("isConnected: ${AuthService.isConnected()}");
Future.delayed(const Duration(milliseconds: 500), () {
showDialog(
barrierDismissible: false,
@ -105,7 +102,12 @@ class MainPageState extends State<MainPage> {
title: LoginWidget());
});
});
}
}
return FutureBuilder(future: AuthService.init(),
builder: (e, s) {
WorkspaceLocal.init(context, false);
CollaborativeAreaLocal.init(context, false);
HeaderConstants.height = HeaderConstants.isNoHeader(AppRouter.currentRoute.route) || AppRouter.currentRoute.factory.searchFill() ? 50 : 100;
return Scaffold( key: scaffoldKey, endDrawer: EndDrawerWidget(), body:
SingleChildScrollView(

View File

@ -18,24 +18,23 @@ class LoginWidgetState extends State<LoginWidget> {
FocusNode focusNode = FocusNode();
@override Widget build(BuildContext context) {
return KeyboardListener(focusNode: focusNode,
onKeyEvent: (value) {
onKeyEvent: (value) async {
if (value is KeyDownEvent && value.logicalKey == LogicalKeyboardKey.enter) {
if (usernameCtrl.text == "" || passwordCtrl.text == "") { return; }
error = null;
setState(() {
loading = true;
});
AuthService.login(usernameCtrl.text, passwordCtrl.text).catchError( (e) {
await AuthService.login(usernameCtrl.text, passwordCtrl.text).catchError( (e) {
setState(() {
loading = false;
error = "Invalid username or password";
});
});
if (error == null) {
// ignore: use_build_context_synchronously
setState(() {
loading = true;
loading = false;
});
context.pop();
}
@ -114,6 +113,7 @@ class LoginWidgetState extends State<LoginWidget> {
loading = true;
});
context.pop();
//mainKey?.currentState!.setState(() {});
}
},
mouseCursor: SystemMouseCursors.click,