121 lines
3.3 KiB
Dart
121 lines
3.3 KiB
Dart
|
|
import 'dart:developer';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_login/flutter_login.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
import '../../api/apiError.dart';
|
|
import '../../api/webuntis/queries/authenticate/authenticateParams.dart';
|
|
import '../../api/webuntis/queries/authenticate/authenticate.dart';
|
|
import '../../api/webuntis/webuntisError.dart';
|
|
import '../../model/accountModel.dart';
|
|
|
|
class Login extends StatefulWidget {
|
|
const Login({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<Login> createState() => _LoginState();
|
|
}
|
|
|
|
class _LoginState extends State<Login> {
|
|
bool displayDisclaimerText = true;
|
|
|
|
String? _checkInput(value){
|
|
return (value ?? "").length == 0 ? "Eingabe erforderlich" : null;
|
|
}
|
|
|
|
Future<String?> _login(LoginData data) async {
|
|
SharedPreferences preferences = await SharedPreferences.getInstance();
|
|
preferences.setBool("loggedIn", false);
|
|
|
|
try {
|
|
await Authenticate(
|
|
AuthenticateParams(
|
|
user: data.name,
|
|
password: data.password,
|
|
)
|
|
).run().then((value) => {
|
|
log(value.sessionId)
|
|
});
|
|
} on WebuntisError catch(e) {
|
|
return e.toString();
|
|
} on ApiError catch(e) {
|
|
return e.toString();
|
|
}
|
|
|
|
setState(() {
|
|
displayDisclaimerText = false;
|
|
});
|
|
|
|
preferences.setBool("loggedIn", true);
|
|
preferences.setString("username", data.name);
|
|
preferences.setString("password", data.password);
|
|
|
|
return null;
|
|
}
|
|
|
|
Future<String> _resetPassword(String name) {
|
|
return Future.delayed(Duration.zero).then((_) {
|
|
return "Diese Funktion steht nicht zur Verfügung!";
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return FlutterLogin(
|
|
logo: Image.asset("assets/logo/icon.png").image,
|
|
|
|
userValidator: _checkInput,
|
|
passwordValidator: _checkInput,
|
|
onSubmitAnimationCompleted: () => Provider.of<AccountModel>(context, listen: false).login(),
|
|
|
|
onLogin: _login,
|
|
onSignup: null,
|
|
|
|
onRecoverPassword: _resetPassword,
|
|
hideForgotPasswordButton: true,
|
|
|
|
theme: LoginTheme(
|
|
primaryColor: Theme.of(context).primaryColor,
|
|
accentColor: Colors.white,
|
|
errorColor: Theme.of(context).primaryColor,
|
|
footerBottomPadding: 10,
|
|
textFieldStyle: const TextStyle(
|
|
fontWeight: FontWeight.w500
|
|
),
|
|
cardTheme: const CardTheme(
|
|
elevation: 10,
|
|
),
|
|
),
|
|
|
|
messages: LoginMessages(
|
|
loginButton: "Anmelden",
|
|
userHint: "Nutzername",
|
|
passwordHint: "Passwort",
|
|
),
|
|
|
|
disableCustomPageTransformer: true,
|
|
|
|
headerWidget: Padding(
|
|
padding: const EdgeInsets.only(bottom: 30),
|
|
child: Center(
|
|
child: Visibility(
|
|
visible: displayDisclaimerText,
|
|
child: const Text(
|
|
"Dies ist ein Inoffizieller Nextcloud & Webuntis Client und wird nicht vom Marianum selbst betrieben.\nKeinerlei Gewähr für Vollständigkeit, Richtigkeit und Aktualität!",
|
|
textAlign: TextAlign.center,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
|
|
footer: "Marianum Fulda - Die persönliche Schule",
|
|
title: "Marianum Fulda",
|
|
|
|
userType: LoginUserType.name,
|
|
);
|
|
}
|
|
}
|