diff --git a/lib/bbw.dart b/lib/bbw.dart index a94da1a..d110759 100644 --- a/lib/bbw.dart +++ b/lib/bbw.dart @@ -357,6 +357,13 @@ class _BBWPageState extends State { ), ) : ListView(children: [ + Container( + padding: const EdgeInsets.only(left: 20, right: 20), + child: const Text( + "BBW Stundenplan aller Klassen.", + style: TextStyle(color: Colors.white), + ), + ), Container( padding: const EdgeInsets.only(left: 20, right: 20), child: const Text( diff --git a/lib/data_seed.dart b/lib/data_seed.dart index a2d8a98..dfbaa44 100644 --- a/lib/data_seed.dart +++ b/lib/data_seed.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; class DataSeed { - String title = "2I Stundenplan"; + String title = "Intranet Stundenplan"; String api = "https://kbw.senpai.one/api/api.php"; String teacherApi = "https://kbw.senpai.one/api/teacher.php?teacher="; diff --git a/lib/home.dart b/lib/home.dart index 75871d0..267c218 100644 --- a/lib/home.dart +++ b/lib/home.dart @@ -115,7 +115,7 @@ class _HomePageState extends State { }); //update cache only if loggedin - if (username != null && password != null) { + if (username != null && password != null && school != null) { updateApiData(prefs, apiOldData); } } @@ -392,7 +392,7 @@ class _HomePageState extends State { .toUpperCase(); return ElevatedButton( onPressed: () { - openTeacher(teacherId!, teachersFullName); + // openTeacher(teacherId!, teachersFullName); }, child: Row( children: [ diff --git a/lib/login.dart b/lib/login.dart index 7429322..ff8d168 100644 --- a/lib/login.dart +++ b/lib/login.dart @@ -56,186 +56,189 @@ class _LoginState extends State { Widget build(BuildContext context) { return Container( alignment: Alignment.topCenter, - child: SingleChildScrollView( - scrollDirection: Axis.vertical, - child: Container( - constraints: const BoxConstraints(maxWidth: 500), - padding: const EdgeInsets.all(10), - child: Column( - children: [ - (!isAuth) - ? Column( - children: [ - const Padding( - padding: EdgeInsets.only(bottom: 20), - child: Text( - textAlign: TextAlign.center, - "Login to you intranet.tam.ch Account", - style: TextStyle( - color: Colors.white, - fontWeight: FontWeight.bold, - fontSize: 20, + child: SafeArea( + child: SingleChildScrollView( + scrollDirection: Axis.vertical, + child: Container( + constraints: const BoxConstraints(maxWidth: 500), + padding: const EdgeInsets.only( + left: 10, top: 10, right: 10, bottom: 200), + child: Column( + children: [ + (!isAuth) + ? Column( + children: [ + const Padding( + padding: EdgeInsets.only(bottom: 20), + child: Text( + textAlign: TextAlign.center, + "Login to you intranet.tam.ch Account", + style: TextStyle( + color: Colors.white, + fontWeight: FontWeight.bold, + fontSize: 20, + ), ), ), - ), - TextFormField( - initialValue: username, - onChanged: (value) { - username = value.toString(); - }, - style: const TextStyle(color: Colors.white), - decoration: const InputDecoration( - border: OutlineInputBorder(), - enabledBorder: OutlineInputBorder( - borderSide: BorderSide( - color: Colors.grey, - )), - labelStyle: TextStyle(color: Colors.white), - labelText: - 'Intranet Benutzername (vorname.nachname)', - ), - ), - Padding( - padding: const EdgeInsets.only(top: 20), - child: TextField( + TextFormField( + initialValue: username, onChanged: (value) { - password = value.toString(); + username = value.toString(); }, - obscureText: true, - enableSuggestions: false, - autocorrect: false, style: const TextStyle(color: Colors.white), decoration: const InputDecoration( - border: OutlineInputBorder(), - enabledBorder: OutlineInputBorder( - borderSide: BorderSide( - color: Colors.grey, - )), - labelStyle: TextStyle(color: Colors.white), - labelText: 'Intranet Passwort', - focusColor: Colors.white), + border: OutlineInputBorder(), + enabledBorder: OutlineInputBorder( + borderSide: BorderSide( + color: Colors.grey, + )), + labelStyle: TextStyle(color: Colors.white), + labelText: + 'Intranet Benutzername (vorname.nachname)', + ), ), - ), - Padding( - padding: const EdgeInsets.only(top: 20), - child: TextField( - onChanged: (value) { - school = value.toString(); - }, - enableSuggestions: true, - autocorrect: false, - style: const TextStyle(color: Colors.white), - decoration: const InputDecoration( - border: OutlineInputBorder(), - enabledBorder: OutlineInputBorder( - borderSide: BorderSide( - color: Colors.grey, - )), - labelStyle: TextStyle(color: Colors.white), - labelText: 'Schule kürzel (leer = kbw)', - focusColor: Colors.white), + Padding( + padding: const EdgeInsets.only(top: 20), + child: TextField( + onChanged: (value) { + password = value.toString(); + }, + obscureText: true, + enableSuggestions: false, + autocorrect: false, + style: const TextStyle(color: Colors.white), + decoration: const InputDecoration( + border: OutlineInputBorder(), + enabledBorder: OutlineInputBorder( + borderSide: BorderSide( + color: Colors.grey, + )), + labelStyle: TextStyle(color: Colors.white), + labelText: 'Intranet Passwort', + focusColor: Colors.white), + ), ), - ), - errorMessage != null - ? Text( - errorMessage.toString(), - style: const TextStyle(color: Colors.red), - ) - : const SizedBox.shrink(), - Padding( - padding: const EdgeInsets.only( - top: 20, left: 20, right: 20), - child: Column( - children: const [ - Text( - textAlign: TextAlign.center, - "This application is not associated with intranet.tam.ch!", - style: TextStyle( - color: Colors.blue, - ), - ), - Text( - textAlign: TextAlign.center, - "Your login details will be sent to kbw.senpai.one so that this website can log in to your account and load the timetable data. Your login data is not stored on the server. Your timetable data is temporarily cached on the server. Your login data is stored locally on this device until you log out.", - style: TextStyle( - color: Colors.white, - ), - ) - ], + Padding( + padding: const EdgeInsets.only(top: 20), + child: TextField( + onChanged: (value) { + school = value.toString(); + }, + enableSuggestions: true, + autocorrect: false, + style: const TextStyle(color: Colors.white), + decoration: const InputDecoration( + border: OutlineInputBorder(), + enabledBorder: OutlineInputBorder( + borderSide: BorderSide( + color: Colors.grey, + )), + labelStyle: TextStyle(color: Colors.white), + labelText: 'Schule kürzel (leer = kbw)', + focusColor: Colors.white), + ), ), - ), - Padding( - padding: const EdgeInsets.fromLTRB(0, 40, 0, 20), - child: isLoading - ? const Center( - child: CircularProgressIndicator(), + errorMessage != null + ? Text( + errorMessage.toString(), + style: const TextStyle(color: Colors.red), ) - : ElevatedButton( - onPressed: () { - setState(() { - errorMessage = null; - isLoading = true; - }); - fetchLoginApi().then((http.Response res) { + : const SizedBox.shrink(), + Padding( + padding: const EdgeInsets.only( + top: 20, left: 20, right: 20), + child: Column( + children: const [ + Text( + textAlign: TextAlign.center, + "This application is not associated with intranet.tam.ch!", + style: TextStyle( + color: Colors.blue, + ), + ), + Text( + textAlign: TextAlign.center, + "Your login details will be sent to kbw.senpai.one so that this website can log in to your account and load the timetable data. Your login data is not stored on the server. Your timetable data is temporarily cached on the server. Your login data is stored locally on this device until you log out.", + style: TextStyle( + color: Colors.white, + ), + ) + ], + ), + ), + Padding( + padding: const EdgeInsets.fromLTRB(0, 40, 0, 20), + child: isLoading + ? const Center( + child: CircularProgressIndicator(), + ) + : ElevatedButton( + onPressed: () { setState(() { - isLoading = false; + errorMessage = null; + isLoading = true; }); - if (res.statusCode == 200) { + fetchLoginApi().then((http.Response res) { setState(() { - errorMessage = null; + isLoading = false; }); - SharedPreferences.getInstance() - .then((prefs) { - prefs.setString( - 'username', username.toString()); - prefs.setString( - 'password', password.toString()); - prefs.setString( - 'school', school.toString()); + if (res.statusCode == 200) { setState(() { - isAuth = true; + errorMessage = null; }); - }); - } else { - setState(() { - errorMessage = "Error: ${res.body}"; - isAuth = false; - }); - } - }); - }, - child: const Text( - "Anmelden", - style: TextStyle(color: Colors.white), + SharedPreferences.getInstance() + .then((prefs) { + prefs.setString('username', + username.toString()); + prefs.setString('password', + password.toString()); + prefs.setString( + 'school', school.toString()); + setState(() { + isAuth = true; + }); + }); + } else { + setState(() { + errorMessage = "Error: ${res.body}"; + isAuth = false; + }); + } + }); + }, + child: const Text( + "Anmelden", + style: TextStyle(color: Colors.white), + ), ), - ), - ) - ], - ) - : Center( - child: ElevatedButton( - style: const ButtonStyle( - backgroundColor: - MaterialStatePropertyAll(Colors.red), - ), - onPressed: () { - setState(() { - username = null; - password = null; - isAuth = false; - }); - SharedPreferences.getInstance().then((prefs) { - prefs.setString('username', ""); - prefs.setString('password', ""); - }); - }, - child: Text( - "Abmelden", - style: TextStyle(color: Colors.white), + ) + ], + ) + : Center( + child: ElevatedButton( + style: const ButtonStyle( + backgroundColor: + MaterialStatePropertyAll(Colors.red), + ), + onPressed: () { + setState(() { + username = null; + password = null; + isAuth = false; + }); + SharedPreferences.getInstance().then((prefs) { + prefs.setString('username', ""); + prefs.setString('password', ""); + }); + }, + child: Text( + "Abmelden", + style: TextStyle(color: Colors.white), + ), ), ), - ), - ], + ], + ), ), ), ), diff --git a/lib/router.dart b/lib/router.dart index 80d4d81..abca274 100644 --- a/lib/router.dart +++ b/lib/router.dart @@ -40,8 +40,8 @@ class _LocalRouterState extends State { name: 'Home', obj: const HomePage(), icon: Icons.home_rounded), - LocalRouterItem( - loc: '/bbw', name: 'BBW', obj: const BBWPage(), icon: Icons.computer), + // LocalRouterItem( + // loc: '/bbw', name: 'BBW', obj: const BBWPage(), icon: Icons.computer), LocalRouterItem( loc: '/login', name: 'Login', obj: const Login(), icon: Icons.login), LocalRouterItem( @@ -122,25 +122,23 @@ class _LocalRouterState extends State { child: VersionChecker(), ), ]), - bottomNavigationBar: new Theme( + bottomNavigationBar: Theme( data: Theme.of(context).copyWith( canvasColor: Colors.black54, ), child: BottomNavigationBar( - backgroundColor: Colors.grey, + // backgroundColor: Color.fromARGB(255, 12, 12, 12), currentIndex: index, - // unselectedItemColor: Colors.white, + unselectedItemColor: Colors.white, // selectedItemColor: Colors.white, - onTap: (newIndex) { - setState(() { - index = newIndex; - }); - }, + onTap: (newIndex) => setState(() { + index = newIndex; + }), items: localRouter .map((item) => BottomNavigationBarItem( icon: Icon( item.icon, - color: Color.fromARGB(255, 255, 255, 255), + color: const Color.fromARGB(255, 255, 255, 255), ), label: item.name)) .toList()), diff --git a/lib/teacher.dart b/lib/teacher.dart index 1afc8fd..db545a9 100644 --- a/lib/teacher.dart +++ b/lib/teacher.dart @@ -44,9 +44,14 @@ class _TeacherState extends State { _TeacherState(this.teacherId, this.title); - Future fetchTeacherApi(int teacherId, String? school) { - return http - .get(Uri.parse("${data.teacherApi}$teacherId&school=${school!}")); + Future fetchTeacherApi( + int teacherId, String? school, String? username, String? password) { + return http.post( + Uri.parse("${data.teacherApi}$teacherId&school=${school!}"), + body: { + 'username': username.toString(), + 'password': password.toString() + }); } DateTime parseTime(String input, String date) => DateTime.parse( @@ -74,6 +79,8 @@ class _TeacherState extends State { }); final prefs = await SharedPreferences.getInstance(); final school = prefs.getString('school'); + final username = prefs.getString('username'); + final password = prefs.getString('password'); final apiOldData = prefs.getString('apiDataTeacher$teacherId'); if (apiOldData != null) { Api tmpCacheApi = Api.fromRawJson(apiOldData); @@ -83,7 +90,8 @@ class _TeacherState extends State { }); } - http.Response res = await fetchTeacherApi(teacherId, school); + http.Response res = + await fetchTeacherApi(teacherId, school, username, password); if (res.statusCode == 200) { Api tmpApi = Api.fromRawJson(res.body); if (tmpApi.status == 1) {