44 lines
1.0 KiB
Dart
44 lines
1.0 KiB
Dart
import 'school_navigation_policy.dart';
|
|
|
|
/// Only the authenticated graduate system may advance the service handshake.
|
|
class SchoolLoginFlow {
|
|
Uri? _target;
|
|
bool _requested = false;
|
|
int _attempts = 0;
|
|
void begin(Uri target) {
|
|
_target = target;
|
|
_requested = false;
|
|
_attempts = 0;
|
|
}
|
|
|
|
void reset() {
|
|
_target = null;
|
|
_requested = false;
|
|
_attempts = 0;
|
|
}
|
|
|
|
Uri? onLoaded(Uri uri, {required bool authenticated}) {
|
|
if (_target == null || !SchoolNavigationPolicy.isSchoolPage(uri)) {
|
|
return null;
|
|
}
|
|
if (uri.host == 'idas.uestc.edu.cn') {
|
|
_requested = false;
|
|
return null;
|
|
}
|
|
final atTarget =
|
|
uri.path == _target!.path &&
|
|
(!_target!.queryParameters.containsKey('xq') ||
|
|
uri.queryParameters['xq'] == _target!.queryParameters['xq']);
|
|
if (atTarget ||
|
|
_requested ||
|
|
_attempts >= 2 ||
|
|
!authenticated ||
|
|
!SchoolNavigationPolicy.isGraduatePage(uri)) {
|
|
return null;
|
|
}
|
|
_requested = true;
|
|
_attempts++;
|
|
return _target;
|
|
}
|
|
}
|