parent
781551c95f
commit
35218c2e52
|
@ -72,9 +72,10 @@ class _LoginPageState extends State<LoginPage> {
|
||||||
border: const OutlineInputBorder(),
|
border: const OutlineInputBorder(),
|
||||||
contentPadding: const EdgeInsets.all(8.0),
|
contentPadding: const EdgeInsets.all(8.0),
|
||||||
hintText: 'https://among-us.morbius.sus/api/fever.php',
|
hintText: 'https://among-us.morbius.sus/api/fever.php',
|
||||||
errorText: _validAPI == false ? 'Invalid or unsupported API' : null,
|
errorText: _validAPI == false
|
||||||
)
|
? 'Invalid or unsupported API'
|
||||||
),
|
: null,
|
||||||
|
)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -87,7 +88,8 @@ class _LoginPageState extends State<LoginPage> {
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
children: [
|
children: [
|
||||||
Flexible(child: TextField(
|
Flexible(
|
||||||
|
child: TextField(
|
||||||
controller: _usernameController,
|
controller: _usernameController,
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
border: OutlineInputBorder(),
|
border: OutlineInputBorder(),
|
||||||
|
@ -96,7 +98,8 @@ class _LoginPageState extends State<LoginPage> {
|
||||||
),
|
),
|
||||||
)),
|
)),
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
Flexible(child: TextField(
|
Flexible(
|
||||||
|
child: TextField(
|
||||||
controller: _passwordController,
|
controller: _passwordController,
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
border: OutlineInputBorder(),
|
border: OutlineInputBorder(),
|
||||||
|
@ -110,14 +113,63 @@ class _LoginPageState extends State<LoginPage> {
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
Container(
|
||||||
|
margin: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 4.0),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
ElevatedButton(
|
||||||
|
onPressed: () {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) => AlertDialog(
|
||||||
|
title: const Text("Connect to demo instance"),
|
||||||
|
content: const Text(
|
||||||
|
"If you want to try out this application before setting "
|
||||||
|
"up your own RSS aggregator, you can connect to our demo instance.\n\n"
|
||||||
|
"Please note that the demo server is not intended "
|
||||||
|
"for normal usage. If you intend to use this app, "
|
||||||
|
"please set up your own server."),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.of(context).pop(),
|
||||||
|
child: const Text("Cancel"),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () async {
|
||||||
|
var apiUrl = "https://rss.amogus.cloud/api/fever.php";
|
||||||
|
var apiKey = FeverAPI.generateApiKey("demo", "PF6bdYLH");
|
||||||
|
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
await prefs.setString('apiUrl', apiUrl);
|
||||||
|
await prefs.setString('apiKey', apiKey);
|
||||||
|
await prefs.setBool('isDemo', true);
|
||||||
|
|
||||||
|
widget.api.apiUrl = apiUrl;
|
||||||
|
widget.api.apiKey = apiKey;
|
||||||
|
// ignore: use_build_context_synchronously
|
||||||
|
Navigator.of(context).popUntil((route) => route.isFirst);
|
||||||
|
},
|
||||||
|
child: const Text("Connect!"),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: const Text("Demo"),
|
||||||
|
),
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
if (_urlController.text.isEmpty) return;
|
if (_urlController.text.isEmpty) return;
|
||||||
_validAPI ??= await checkUrl();
|
_validAPI ??= await checkUrl();
|
||||||
if (_validAPI != true || _usernameController.text.isEmpty || _passwordController.text.isEmpty) return;
|
if (_validAPI != true ||
|
||||||
|
_usernameController.text.isEmpty ||
|
||||||
|
_passwordController.text.isEmpty) return;
|
||||||
|
|
||||||
var apiKey = FeverAPI.generateApiKey(_usernameController.text, _passwordController.text);
|
var apiKey = FeverAPI.generateApiKey(
|
||||||
var isAuthenticated = await FeverAPI.isAuthenticated(_urlController.text, apiKey);
|
_usernameController.text, _passwordController.text);
|
||||||
|
var isAuthenticated = await FeverAPI.isAuthenticated(
|
||||||
|
_urlController.text, apiKey);
|
||||||
|
|
||||||
if (!isAuthenticated) {
|
if (!isAuthenticated) {
|
||||||
// ignore: use_build_context_synchronously
|
// ignore: use_build_context_synchronously
|
||||||
|
@ -126,13 +178,16 @@ class _LoginPageState extends State<LoginPage> {
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
title: const Text('Authentication failed'),
|
title: const Text('Authentication failed'),
|
||||||
content: const Text('The API URL seems to be valid, but the provided credentials appear to be incorrect.'),
|
content: const Text(
|
||||||
|
'The API URL seems to be valid, but the provided credentials appear to be incorrect.'),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(onPressed: () => Navigator.of(context).pop(), child: const Text('Got it!')),
|
TextButton(
|
||||||
|
onPressed: () =>
|
||||||
|
Navigator.of(context).pop(),
|
||||||
|
child: const Text('Got it!')),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -150,6 +205,9 @@ class _LoginPageState extends State<LoginPage> {
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue