parent
781551c95f
commit
35218c2e52
|
@ -4,7 +4,7 @@ import 'package:shared_preferences/shared_preferences.dart';
|
|||
|
||||
class LoginPage extends StatefulWidget {
|
||||
final FeverAPI api;
|
||||
const LoginPage({ super.key, required this.api });
|
||||
const LoginPage({super.key, required this.api});
|
||||
|
||||
@override
|
||||
State<LoginPage> createState() => _LoginPageState();
|
||||
|
@ -66,15 +66,16 @@ class _LoginPageState extends State<LoginPage> {
|
|||
children: [
|
||||
const Text("Fever compatible API URL"),
|
||||
TextField(
|
||||
controller: _urlController,
|
||||
focusNode: _urlFocus,
|
||||
decoration: InputDecoration(
|
||||
border: const OutlineInputBorder(),
|
||||
contentPadding: const EdgeInsets.all(8.0),
|
||||
hintText: 'https://among-us.morbius.sus/api/fever.php',
|
||||
errorText: _validAPI == false ? 'Invalid or unsupported API' : null,
|
||||
)
|
||||
),
|
||||
controller: _urlController,
|
||||
focusNode: _urlFocus,
|
||||
decoration: InputDecoration(
|
||||
border: const OutlineInputBorder(),
|
||||
contentPadding: const EdgeInsets.all(8.0),
|
||||
hintText: 'https://among-us.morbius.sus/api/fever.php',
|
||||
errorText: _validAPI == false
|
||||
? 'Invalid or unsupported API'
|
||||
: null,
|
||||
)),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
@ -87,7 +88,8 @@ class _LoginPageState extends State<LoginPage> {
|
|||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
Flexible(child: TextField(
|
||||
Flexible(
|
||||
child: TextField(
|
||||
controller: _usernameController,
|
||||
decoration: const InputDecoration(
|
||||
border: OutlineInputBorder(),
|
||||
|
@ -96,7 +98,8 @@ class _LoginPageState extends State<LoginPage> {
|
|||
),
|
||||
)),
|
||||
const SizedBox(width: 8),
|
||||
Flexible(child: TextField(
|
||||
Flexible(
|
||||
child: TextField(
|
||||
controller: _passwordController,
|
||||
decoration: const InputDecoration(
|
||||
border: OutlineInputBorder(),
|
||||
|
@ -110,43 +113,98 @@ class _LoginPageState extends State<LoginPage> {
|
|||
],
|
||||
),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
if (_urlController.text.isEmpty) return;
|
||||
_validAPI ??= await checkUrl();
|
||||
if (_validAPI != true || _usernameController.text.isEmpty || _passwordController.text.isEmpty) return;
|
||||
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");
|
||||
|
||||
var apiKey = FeverAPI.generateApiKey(_usernameController.text, _passwordController.text);
|
||||
var isAuthenticated = await FeverAPI.isAuthenticated(_urlController.text, apiKey);
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString('apiUrl', apiUrl);
|
||||
await prefs.setString('apiKey', apiKey);
|
||||
await prefs.setBool('isDemo', true);
|
||||
|
||||
if (!isAuthenticated) {
|
||||
// ignore: use_build_context_synchronously
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text('Authentication failed'),
|
||||
content: const Text('The API URL seems to be valid, but the provided credentials appear to be incorrect.'),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.of(context).pop(), child: const Text('Got it!')),
|
||||
],
|
||||
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(
|
||||
onPressed: () async {
|
||||
if (_urlController.text.isEmpty) return;
|
||||
_validAPI ??= await checkUrl();
|
||||
if (_validAPI != true ||
|
||||
_usernameController.text.isEmpty ||
|
||||
_passwordController.text.isEmpty) return;
|
||||
|
||||
return;
|
||||
}
|
||||
var apiKey = FeverAPI.generateApiKey(
|
||||
_usernameController.text, _passwordController.text);
|
||||
var isAuthenticated = await FeverAPI.isAuthenticated(
|
||||
_urlController.text, apiKey);
|
||||
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString('apiUrl', _urlController.text);
|
||||
await prefs.setString('apiKey', apiKey);
|
||||
if (!isAuthenticated) {
|
||||
// ignore: use_build_context_synchronously
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text('Authentication failed'),
|
||||
content: const Text(
|
||||
'The API URL seems to be valid, but the provided credentials appear to be incorrect.'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () =>
|
||||
Navigator.of(context).pop(),
|
||||
child: const Text('Got it!')),
|
||||
],
|
||||
);
|
||||
});
|
||||
|
||||
widget.api.apiUrl = _urlController.text;
|
||||
widget.api.apiKey = apiKey;
|
||||
// ignore: use_build_context_synchronously
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: const Text('Continue'),
|
||||
return;
|
||||
}
|
||||
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString('apiUrl', _urlController.text);
|
||||
await prefs.setString('apiKey', apiKey);
|
||||
|
||||
widget.api.apiUrl = _urlController.text;
|
||||
widget.api.apiKey = apiKey;
|
||||
// ignore: use_build_context_synchronously
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: const Text('Continue'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
|
Loading…
Reference in a new issue