added some hint for spaces after username

This commit is contained in:
Kima 2023-09-03 22:13:39 +02:00
parent 6e06d82b1a
commit 5e650869f2
5 changed files with 69 additions and 32 deletions

View File

@ -0,0 +1,13 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/Users/kima/src/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/kima/Documents/refilc/app/naplo/filcnaplo"
export "COCOAPODS_PARALLEL_CODE_SIGN=true"
export "FLUTTER_TARGET=lib/main.dart"
export "FLUTTER_BUILD_DIR=build"
export "FLUTTER_BUILD_NAME=4.2.0"
export "FLUTTER_BUILD_NUMBER=220"
export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=true"
export "TREE_SHAKE_ICONS=false"
export "PACKAGE_CONFIG=.dart_tool/package_config.json"

View File

@ -27,7 +27,7 @@ enum LoginState {
failed,
normal,
inProgress,
success
success,
}
Nonce getNonce(String nonce, String username, String instituteCode) {
@ -39,7 +39,7 @@ Nonce getNonce(String nonce, String username, String instituteCode) {
return nonceEncoder;
}
Future loginApi({
Future loginAPI({
required String username,
required String password,
required String instituteCode,
@ -49,14 +49,14 @@ Future loginApi({
}) async {
Provider.of<KretaClient>(context, listen: false).userAgent =
Provider.of<SettingsProvider>(context, listen: false).config.userAgent;
Map<String, String> headers = {
"content-type": "application/x-www-form-urlencoded",
};
String nonceStr = await Provider.of<KretaClient>(context, listen: false)
.getAPI(KretaAPI.nonce, json: false);
Nonce nonce = getNonce(nonceStr, username, instituteCode);
headers.addAll(nonce.header());
@ -121,7 +121,7 @@ Future loginApi({
return LoginState.success;
} catch (error) {
print("ERROR: loginApi: $error");
print("ERROR: loginAPI: $error");
// maybe check debug mode
// ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text("ERROR: $error")));
return LoginState.failed;

View File

@ -235,7 +235,7 @@ class _LoginScreenState extends State<LoginScreen> {
fontWeight: FontWeight.w600,
fontSize: 15.0,
)),
onPressed: () => _loginApi(context: context),
onPressed: () => _loginAPI(context: context),
),
visible: _loginState != LoginState.inProgress,
replacement: const Padding(
@ -279,7 +279,7 @@ class _LoginScreenState extends State<LoginScreen> {
);
}
void _loginApi({required BuildContext context}) {
void _loginAPI({required BuildContext context}) {
String username = usernameController.text;
String password = passwordController.text;
@ -289,7 +289,7 @@ class _LoginScreenState extends State<LoginScreen> {
setState(() => _loginState = LoginState.inProgress);
loginApi(
loginAPI(
username: username,
password: password,
instituteCode: schoolController.selectedSchool!.instituteCode,

View File

@ -1,3 +1,4 @@
// import 'dart:async';
import 'dart:ui';
import 'package:filcnaplo/api/client.dart';
@ -42,6 +43,8 @@ class _LoginScreenState extends State<LoginScreen> {
stops: [-1.0, 0.0, 1.0],
);
late String tempUsername = '';
@override
void initState() {
super.initState();
@ -250,7 +253,7 @@ class _LoginScreenState extends State<LoginScreen> {
fontWeight: FontWeight.w600,
fontSize: 15.0,
)),
onPressed: () => _loginApi(context: context),
onPressed: () => _loginAPI(context: context),
),
visible: _loginState != LoginState.inProgress,
replacement: const Padding(
@ -288,35 +291,54 @@ class _LoginScreenState extends State<LoginScreen> {
);
}
void _loginApi({required BuildContext context}) {
void _loginAPI({required BuildContext context}) {
String username = usernameController.text;
String password = passwordController.text;
tempUsername = username;
if (username == "" ||
password == "" ||
schoolController.selectedSchool == null) {
return setState(() => _loginState = LoginState.missingFields);
}
setState(() => _loginState = LoginState.inProgress);
void _callAPI() {
loginAPI(
username: username,
password: password,
instituteCode: schoolController.selectedSchool!.instituteCode,
context: context,
onLogin: (user) {
ScaffoldMessenger.of(context).showSnackBar(CustomSnackBar(
context: context,
brightness: Brightness.light,
content: Text("welcome".i18n.fill([user.name]),
overflow: TextOverflow.ellipsis),
));
},
onSuccess: () {
ScaffoldMessenger.of(context).hideCurrentSnackBar();
setSystemChrome(context);
Navigator.of(context).pushReplacementNamed("login_to_navigation");
}).then(
(res) => setState(() {
// if (res == LoginState.invalidGrant &&
// tempUsername.replaceAll(username, '').length <= 3) {
// tempUsername = username + ' ';
// Timer(
// const Duration(milliseconds: 500),
// () => _loginAPI(context: context),
// );
// // _loginAPI(context: context);
// } else {
_loginState = res;
// }
}),
);
}
loginApi(
username: username,
password: password,
instituteCode: schoolController.selectedSchool!.instituteCode,
context: context,
onLogin: (user) {
ScaffoldMessenger.of(context).showSnackBar(CustomSnackBar(
context: context,
brightness: Brightness.light,
content: Text("welcome".i18n.fill([user.name]),
overflow: TextOverflow.ellipsis),
));
},
onSuccess: () {
ScaffoldMessenger.of(context).hideCurrentSnackBar();
setSystemChrome(context);
Navigator.of(context).pushReplacementNamed("login_to_navigation");
}).then((res) => setState(() => _loginState = res));
setState(() => _loginState = LoginState.inProgress);
_callAPI();
}
}

View File

@ -12,7 +12,8 @@ extension Localization on String {
"login": "Log in",
"welcome": "Welcome, %s!",
"missing_fields": "Missing Fields!",
"invalid_grant": "Invalid Username/Password!",
"invalid_grant":
"Invalid Username/Password! (Try adding spaces after Username)",
"error": "Failed to log in.",
"schools_error": "Failed to get schools."
},
@ -25,7 +26,8 @@ extension Localization on String {
"login": "Belépés",
"welcome": "Üdv, %s!",
"missing_fields": "Hiányzó adatok!",
"invalid_grant": "Helytelen Felhasználónév/Jelszó!",
"invalid_grant":
"Helytelen Felhasználónév/Jelszó! (Próbálj szóközöket írni a Felhasználónév után)",
"error": "Sikertelen bejelentkezés.",
"schools_error": "Nem sikerült lekérni az iskolákat."
},