Skip to content

Commit

Permalink
Merge pull request #130 from refilc/dev
Browse files Browse the repository at this point in the history
dev to master
  • Loading branch information
kimaah committed Aug 22, 2024
2 parents 2c1bde9 + 51b2539 commit d642f19
Show file tree
Hide file tree
Showing 10 changed files with 269 additions and 137 deletions.
Binary file modified refilc/assets/images/showcase1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified refilc/assets/images/showcase2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified refilc/assets/images/showcase3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified refilc/assets/images/showcase4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion refilc/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: "Egy nem hivatalos e-KRÉTA kliens, diákoktól diákoknak."
homepage: https://refilc.hu
publish_to: "none"

version: 5.0.4+272
version: 5.0.4+274

environment:
sdk: ">=3.3.2 <=3.4.3"
Expand Down
16 changes: 9 additions & 7 deletions refilc_kreta_api/lib/client/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -257,26 +257,28 @@ class KretaClient {

refreshToken ??= loginUser.refreshToken;

print("REFRESH TOKEN BELOW");
print(refreshToken);
// print("REFRESH TOKEN BELOW");
// print(refreshToken);

if (refreshToken != null) {
print("REFRESHING LOGIN");
// print("REFRESHING LOGIN");
Map? res = await postAPI(KretaAPI.login,
headers: headers,
body: User.refreshBody(
refreshToken: loginUser.refreshToken,
instituteCode: loginUser.instituteCode,
));
print("REFRESH RESPONSE BELOW");
print(res);
// print("REFRESH RESPONSE BELOW");
// print(res);
if (res != null) {
if (res.containsKey("error")) {
// remove user if refresh token expired
if (res["error"] == "invalid_grant") {
// remove user from app
_user.removeUser(loginUser.id);
await _database.store.removeUser(loginUser.id);
// _user.removeUser(loginUser.id);
// await _database.store.removeUser(loginUser.id);

print("invalid refresh token (invalid_grant)");

// return error
return "refresh_token_expired";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ActiveSponsorCard extends StatelessWidget {
return const SizedBox();
}

Color? glow = Colors.white; //TODO: only temp fix kima (idk what but die)
Color? glow = Colors.white;

switch (level) {
case PremiumFeatureLevel.cap:
Expand Down
166 changes: 122 additions & 44 deletions refilc_mobile_ui/lib/screens/login/kreten_login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,101 @@
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';

class KretenLoginScreen extends StatefulWidget {
const KretenLoginScreen({super.key, required this.onLogin});
class KretenLoginWidget extends StatefulWidget {
const KretenLoginWidget({super.key, required this.onLogin});

// final String selectedSchool;
final void Function(String code) onLogin;

@override
State<KretenLoginScreen> createState() => _KretenLoginScreenState();
State<KretenLoginWidget> createState() => _KretenLoginWidgetState();
}

class _KretenLoginScreenState extends State<KretenLoginScreen> {
class _KretenLoginWidgetState extends State<KretenLoginWidget>
with TickerProviderStateMixin {
late final WebViewController controller;
late AnimationController _animationController;
var loadingPercentage = 0;
var currentUrl = '';
bool _hasFadedIn = false;

@override
void initState() {
super.initState();

_animationController = AnimationController(
vsync: this, // Use the TickerProviderStateMixin
duration: const Duration(milliseconds: 350),
);

controller = WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setNavigationDelegate(NavigationDelegate(
onPageStarted: (url) async {
setState(() {
loadingPercentage = 0;
currentUrl = url;
});
onNavigationRequest: (n) async {
if (n.url.startsWith('https://mobil.e-kreta.hu')) {
setState(() {
loadingPercentage = 0;
currentUrl = n.url;
});

// final String instituteCode = widget.selectedSchool;
if (!url.startsWith(
'https://mobil.e-kreta.hu/ellenorzo-student/prod/oauthredirect?code=')) {
return;
}
// final String instituteCode = widget.selectedSchool;
// if (!n.url.startsWith(
// 'https://mobil.e-kreta.hu/ellenorzo-student/prod/oauthredirect?code=')) {
// return;
// }

List<String> requiredThings = url
.replaceAll(
'https://mobil.e-kreta.hu/ellenorzo-student/prod/oauthredirect?code=',
'')
.replaceAll(
'&scope=openid%20email%20offline_access%20kreta-ellenorzo-webapi.public%20kreta-eugyintezes-webapi.public%20kreta-fileservice-webapi.public%20kreta-mobile-global-webapi.public%20kreta-dkt-webapi.public%20kreta-ier-webapi.public&state=refilc_student_mobile&session_state=',
':')
.split(':');

String code = requiredThings[0];
// String sessionState = requiredThings[1];

widget.onLogin(code);
// Future.delayed(const Duration(milliseconds: 500), () {
// Navigator.of(context).pop();
List<String> requiredThings = n.url
.replaceAll(
'https://mobil.e-kreta.hu/ellenorzo-student/prod/oauthredirect?code=',
'')
.replaceAll(
'&scope=openid%20email%20offline_access%20kreta-ellenorzo-webapi.public%20kreta-eugyintezes-webapi.public%20kreta-fileservice-webapi.public%20kreta-mobile-global-webapi.public%20kreta-dkt-webapi.public%20kreta-ier-webapi.public&state=refilc_student_mobile&session_state=',
':')
.split(':');

String code = requiredThings[0];
// String sessionState = requiredThings[1];

widget.onLogin(code);
// Future.delayed(const Duration(milliseconds: 500), () {
// Navigator.of(context).pop();
// });
// Navigator.of(context).pop();

return NavigationDecision.prevent;
} else {
return NavigationDecision.navigate;
}
},
onPageStarted: (url) async {
// setState(() {
// loadingPercentage = 0;
// currentUrl = url;
// });
// Navigator.of(context).pop();

// // final String instituteCode = widget.selectedSchool;
// if (!url.startsWith(
// 'https://mobil.e-kreta.hu/ellenorzo-student/prod/oauthredirect?code=')) {
// return;
// }

// List<String> requiredThings = url
// .replaceAll(
// 'https://mobil.e-kreta.hu/ellenorzo-student/prod/oauthredirect?code=',
// '')
// .replaceAll(
// '&scope=openid%20email%20offline_access%20kreta-ellenorzo-webapi.public%20kreta-eugyintezes-webapi.public%20kreta-fileservice-webapi.public%20kreta-mobile-global-webapi.public%20kreta-dkt-webapi.public%20kreta-ier-webapi.public&state=refilc_student_mobile&session_state=',
// ':')
// .split(':');

// String code = requiredThings[0];
// // String sessionState = requiredThings[1];

// widget.onLogin(code);
// // Future.delayed(const Duration(milliseconds: 500), () {
// // Navigator.of(context).pop();
// // });
// // Navigator.of(context).pop();
},
onProgress: (progress) {
setState(() {
Expand All @@ -78,24 +123,57 @@ class _KretenLoginScreenState extends State<KretenLoginScreen> {
// Nonce nonce = getNonce(nonceStr, );
// }

@override
void dispose() {
// Step 3: Dispose of the animation controller
_animationController.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: const BackButton(),
title: const Text('e-KRÉTA Bejelentkezés'),
),
body: Stack(
children: [
WebViewWidget(
controller: controller,
// Trigger the fade-in animation only once when loading reaches 100%
if (loadingPercentage == 100 && !_hasFadedIn) {
_animationController.forward(); // Play the animation
_hasFadedIn =
true; // Set the flag to true, so the animation is not replayed
}

return Stack(
children: [
// Webview that will be displayed only when the loading is 100%
if (loadingPercentage == 100)
FadeTransition(
opacity: Tween<double>(begin: 0, end: 1).animate(
CurvedAnimation(
parent: _animationController,
curve: Curves.easeIn,
),
),
child: WebViewWidget(
controller: controller,
),
),
if (loadingPercentage < 100)
LinearProgressIndicator(
value: loadingPercentage / 100.0,

// Show the CircularProgressIndicator while loading is not 100%
if (loadingPercentage < 100)
Center(
child: TweenAnimationBuilder(
tween: Tween<double>(begin: 0, end: loadingPercentage / 100.0),
duration: const Duration(milliseconds: 300),
builder: (context, double value, child) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircularProgressIndicator(
value: value, // Smoothly animates the progress
),
],
);
},
),
],
),
),
],
);
}
}
Loading

0 comments on commit d642f19

Please sign in to comment.