|
|
@ -38,9 +38,6 @@ class _LoginPageState extends State<LoginPage> { |
|
|
|
await launchUrlString( |
|
|
|
await launchUrlString( |
|
|
|
init.login, |
|
|
|
init.login, |
|
|
|
mode: LaunchMode.externalApplication, |
|
|
|
mode: LaunchMode.externalApplication, |
|
|
|
webViewConfiguration: WebViewConfiguration( |
|
|
|
|
|
|
|
headers: _buildHeaders(context, Provider.of<Env?>(context, listen: false)), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
); |
|
|
|
); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
@ -85,18 +82,6 @@ class _LoginPageState extends State<LoginPage> { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Map<String, String> _buildHeaders( |
|
|
|
|
|
|
|
final BuildContext context, |
|
|
|
|
|
|
|
final Env? env, |
|
|
|
|
|
|
|
) => |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
HttpHeaders.userAgentHeader: userAgent(_packageInfo), |
|
|
|
|
|
|
|
if (env != null) ...{ |
|
|
|
|
|
|
|
HttpHeaders.authorizationHeader: |
|
|
|
|
|
|
|
'Basic ${base64.encode(utf8.encode('${env.testUsername}:${env.testPassword}'))}', |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
@override |
|
|
|
void dispose() { |
|
|
|
void dispose() { |
|
|
|
_loginBloc.dispose(); |
|
|
|
_loginBloc.dispose(); |
|
|
@ -104,151 +89,143 @@ class _LoginPageState extends State<LoginPage> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
@override |
|
|
|
Widget build(final BuildContext context) { |
|
|
|
Widget build(final BuildContext context) => StreamBuilder<List<Account>>( |
|
|
|
final env = Provider.of<Env?>(context); |
|
|
|
stream: _accountsBloc.accounts, |
|
|
|
|
|
|
|
builder: (final context, final accountsSnapshot) => WillPopScope( |
|
|
|
return StreamBuilder<List<Account>>( |
|
|
|
onWillPop: () async { |
|
|
|
stream: _accountsBloc.accounts, |
|
|
|
if (accountsSnapshot.data?.isNotEmpty ?? false) { |
|
|
|
builder: (final context, final accountsSnapshot) => WillPopScope( |
|
|
|
return true; |
|
|
|
onWillPop: () async { |
|
|
|
} |
|
|
|
if (accountsSnapshot.data?.isNotEmpty ?? false) { |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((await _loginBloc.serverURL.first) == null) { |
|
|
|
if ((await _loginBloc.serverURL.first) == null) { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_loginBloc.setServerURL(null); |
|
|
|
_loginBloc.setServerURL(null); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
}, |
|
|
|
}, |
|
|
|
child: StreamBuilder<String?>( |
|
|
|
child: StreamBuilder<String?>( |
|
|
|
stream: _loginBloc.serverURL, |
|
|
|
stream: _loginBloc.serverURL, |
|
|
|
builder: (final context, final serverURLSnapshot) => StreamBuilder<ServerConnectionState?>( |
|
|
|
builder: (final context, final serverURLSnapshot) => StreamBuilder<ServerConnectionState?>( |
|
|
|
stream: _loginBloc.serverConnectionState, |
|
|
|
stream: _loginBloc.serverConnectionState, |
|
|
|
builder: (final context, final serverConnectionStateSnapshot) => Scaffold( |
|
|
|
builder: (final context, final serverConnectionStateSnapshot) => Scaffold( |
|
|
|
appBar: serverConnectionStateSnapshot.data == ServerConnectionState.success || |
|
|
|
appBar: serverConnectionStateSnapshot.data == ServerConnectionState.success || |
|
|
|
(accountsSnapshot.data?.isNotEmpty ?? false) |
|
|
|
(accountsSnapshot.data?.isNotEmpty ?? false) |
|
|
|
? AppBar( |
|
|
|
? AppBar( |
|
|
|
leading: IconButton( |
|
|
|
leading: IconButton( |
|
|
|
onPressed: () { |
|
|
|
onPressed: () { |
|
|
|
if (accountsSnapshot.data?.isNotEmpty ?? false) { |
|
|
|
if (accountsSnapshot.data?.isNotEmpty ?? false) { |
|
|
|
Navigator.of(context).pop(); |
|
|
|
Navigator.of(context).pop(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
_loginBloc.setServerURL(null); |
|
|
|
_loginBloc.setServerURL(null); |
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
icon: const Icon(Icons.arrow_back), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
actions: [ |
|
|
|
|
|
|
|
if (serverConnectionStateSnapshot.data != null) ...[ |
|
|
|
|
|
|
|
IconButton( |
|
|
|
|
|
|
|
onPressed: _loginBloc.refresh, |
|
|
|
|
|
|
|
icon: const Icon(Icons.refresh), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
: null, |
|
|
|
|
|
|
|
body: serverConnectionStateSnapshot.data == ServerConnectionState.success |
|
|
|
|
|
|
|
? Provider.of<NeonPlatform>(context).canUseWebView |
|
|
|
|
|
|
|
? WebView( |
|
|
|
|
|
|
|
javascriptMode: JavascriptMode.unrestricted, |
|
|
|
|
|
|
|
zoomEnabled: false, |
|
|
|
|
|
|
|
userAgent: userAgent(_packageInfo), |
|
|
|
|
|
|
|
onWebViewCreated: (final controller) async { |
|
|
|
|
|
|
|
_webViewController = controller; |
|
|
|
|
|
|
|
final url = |
|
|
|
|
|
|
|
(await _loginBloc.loginFlowInit.firstWhere((final init) => init != null))!.login; |
|
|
|
|
|
|
|
if (mounted) { |
|
|
|
|
|
|
|
await _webViewController!.loadUrl( |
|
|
|
|
|
|
|
url, |
|
|
|
|
|
|
|
headers: _buildHeaders(context, env), |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
) |
|
|
|
icon: const Icon(Icons.arrow_back), |
|
|
|
: Center( |
|
|
|
), |
|
|
|
child: Column( |
|
|
|
actions: [ |
|
|
|
mainAxisAlignment: MainAxisAlignment.center, |
|
|
|
if (serverConnectionStateSnapshot.data != null) ...[ |
|
|
|
children: [ |
|
|
|
IconButton( |
|
|
|
Text(AppLocalizations.of(context).loginSwitchToBrowserWindow), |
|
|
|
onPressed: _loginBloc.refresh, |
|
|
|
const SizedBox( |
|
|
|
icon: const Icon(Icons.refresh), |
|
|
|
height: 10, |
|
|
|
), |
|
|
|
), |
|
|
|
], |
|
|
|
ElevatedButton( |
|
|
|
], |
|
|
|
onPressed: _loginBloc.refresh, |
|
|
|
) |
|
|
|
child: Text(AppLocalizations.of(context).loginOpenAgain), |
|
|
|
: null, |
|
|
|
), |
|
|
|
body: serverConnectionStateSnapshot.data == ServerConnectionState.success |
|
|
|
], |
|
|
|
? Provider.of<NeonPlatform>(context).canUseWebView |
|
|
|
), |
|
|
|
? WebView( |
|
|
|
) |
|
|
|
javascriptMode: JavascriptMode.unrestricted, |
|
|
|
: Center( |
|
|
|
zoomEnabled: false, |
|
|
|
child: ListView( |
|
|
|
userAgent: userAgent(_packageInfo), |
|
|
|
shrinkWrap: true, |
|
|
|
onWebViewCreated: (final controller) async { |
|
|
|
padding: const EdgeInsets.symmetric(vertical: 40, horizontal: 20), |
|
|
|
_webViewController = controller; |
|
|
|
children: [ |
|
|
|
final url = |
|
|
|
SizedBox( |
|
|
|
(await _loginBloc.loginFlowInit.firstWhere((final init) => init != null))!.login; |
|
|
|
height: MediaQuery.of(context).size.height / 2, |
|
|
|
if (mounted) { |
|
|
|
|
|
|
|
await _webViewController!.loadUrl(url); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
: Center( |
|
|
|
child: Column( |
|
|
|
child: Column( |
|
|
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center, |
|
|
|
children: [ |
|
|
|
children: [ |
|
|
|
const NeonLogo(), |
|
|
|
Text(AppLocalizations.of(context).loginSwitchToBrowserWindow), |
|
|
|
const SizedBox( |
|
|
|
const SizedBox( |
|
|
|
height: 30, |
|
|
|
height: 10, |
|
|
|
), |
|
|
|
), |
|
|
|
Text(AppLocalizations.of(context).loginWorksWith), |
|
|
|
ElevatedButton( |
|
|
|
const SizedBox( |
|
|
|
onPressed: _loginBloc.refresh, |
|
|
|
height: 20, |
|
|
|
child: Text(AppLocalizations.of(context).loginOpenAgain), |
|
|
|
), |
|
|
|
), |
|
|
|
const NextcloudLogo(), |
|
|
|
|
|
|
|
], |
|
|
|
], |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
) |
|
|
|
Form( |
|
|
|
: Center( |
|
|
|
key: _formKey, |
|
|
|
child: ListView( |
|
|
|
child: TextFormField( |
|
|
|
shrinkWrap: true, |
|
|
|
focusNode: _focusNode, |
|
|
|
padding: const EdgeInsets.symmetric(vertical: 40, horizontal: 20), |
|
|
|
decoration: const InputDecoration( |
|
|
|
children: [ |
|
|
|
hintText: 'https://...', |
|
|
|
SizedBox( |
|
|
|
|
|
|
|
height: MediaQuery.of(context).size.height / 2, |
|
|
|
|
|
|
|
child: Column( |
|
|
|
|
|
|
|
children: [ |
|
|
|
|
|
|
|
const NeonLogo(), |
|
|
|
|
|
|
|
const SizedBox( |
|
|
|
|
|
|
|
height: 30, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
Text(AppLocalizations.of(context).loginWorksWith), |
|
|
|
|
|
|
|
const SizedBox( |
|
|
|
|
|
|
|
height: 20, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
const NextcloudLogo(), |
|
|
|
|
|
|
|
], |
|
|
|
), |
|
|
|
), |
|
|
|
initialValue: |
|
|
|
|
|
|
|
widget.serverURL ?? (env?.testHost != null ? 'http://${env!.testHost}' : null), |
|
|
|
|
|
|
|
validator: (final input) => validateHttpUrl(context, input), |
|
|
|
|
|
|
|
onFieldSubmitted: (final input) { |
|
|
|
|
|
|
|
if (_formKey.currentState!.validate()) { |
|
|
|
|
|
|
|
_loginBloc.setServerURL(input); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
_focusNode.requestFocus(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
Form( |
|
|
|
Column( |
|
|
|
key: _formKey, |
|
|
|
children: [ |
|
|
|
child: TextFormField( |
|
|
|
CustomLinearProgressIndicator( |
|
|
|
focusNode: _focusNode, |
|
|
|
visible: serverConnectionStateSnapshot.data == ServerConnectionState.loading, |
|
|
|
decoration: const InputDecoration( |
|
|
|
), |
|
|
|
hintText: 'https://...', |
|
|
|
if (serverConnectionStateSnapshot.data == ServerConnectionState.unreachable) ...[ |
|
|
|
|
|
|
|
ExceptionWidget( |
|
|
|
|
|
|
|
AppLocalizations.of(context).errorUnableToReachServer, |
|
|
|
|
|
|
|
onRetry: _loginBloc.refresh, |
|
|
|
|
|
|
|
), |
|
|
|
), |
|
|
|
], |
|
|
|
initialValue: widget.serverURL, |
|
|
|
if (serverConnectionStateSnapshot.data == ServerConnectionState.maintenanceMode) ...[ |
|
|
|
validator: (final input) => validateHttpUrl(context, input), |
|
|
|
ExceptionWidget( |
|
|
|
onFieldSubmitted: (final input) { |
|
|
|
AppLocalizations.of(context).errorServerInMaintenanceMode, |
|
|
|
if (_formKey.currentState!.validate()) { |
|
|
|
onRetry: _loginBloc.refresh, |
|
|
|
_loginBloc.setServerURL(input); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
_focusNode.requestFocus(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
Column( |
|
|
|
|
|
|
|
children: [ |
|
|
|
|
|
|
|
CustomLinearProgressIndicator( |
|
|
|
|
|
|
|
visible: serverConnectionStateSnapshot.data == ServerConnectionState.loading, |
|
|
|
), |
|
|
|
), |
|
|
|
|
|
|
|
if (serverConnectionStateSnapshot.data == ServerConnectionState.unreachable) ...[ |
|
|
|
|
|
|
|
ExceptionWidget( |
|
|
|
|
|
|
|
AppLocalizations.of(context).errorUnableToReachServer, |
|
|
|
|
|
|
|
onRetry: _loginBloc.refresh, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
if (serverConnectionStateSnapshot.data == ServerConnectionState.maintenanceMode) ...[ |
|
|
|
|
|
|
|
ExceptionWidget( |
|
|
|
|
|
|
|
AppLocalizations.of(context).errorServerInMaintenanceMode, |
|
|
|
|
|
|
|
onRetry: _loginBloc.refresh, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
], |
|
|
|
], |
|
|
|
], |
|
|
|
], |
|
|
|
), |
|
|
|
), |
|
|
|
], |
|
|
|
], |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|