parent
781551c95f
commit
35218c2e52
|
@ -4,7 +4,7 @@ import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
class LoginPage extends StatefulWidget {
|
class LoginPage extends StatefulWidget {
|
||||||
final FeverAPI api;
|
final FeverAPI api;
|
||||||
const LoginPage({ super.key, required this.api });
|
const LoginPage({super.key, required this.api});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<LoginPage> createState() => _LoginPageState();
|
State<LoginPage> createState() => _LoginPageState();
|
||||||
|
@ -66,15 +66,16 @@ class _LoginPageState extends State<LoginPage> {
|
||||||
children: [
|
children: [
|
||||||
const Text("Fever compatible API URL"),
|
const Text("Fever compatible API URL"),
|
||||||
TextField(
|
TextField(
|
||||||
controller: _urlController,
|
controller: _urlController,
|
||||||
focusNode: _urlFocus,
|
focusNode: _urlFocus,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
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,43 +113,98 @@ class _LoginPageState extends State<LoginPage> {
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
ElevatedButton(
|
Container(
|
||||||
onPressed: () async {
|
margin: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 4.0),
|
||||||
if (_urlController.text.isEmpty) return;
|
child: Row(
|
||||||
_validAPI ??= await checkUrl();
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
if (_validAPI != true || _usernameController.text.isEmpty || _passwordController.text.isEmpty) return;
|
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);
|
final prefs = await SharedPreferences.getInstance();
|
||||||
var isAuthenticated = await FeverAPI.isAuthenticated(_urlController.text, apiKey);
|
await prefs.setString('apiUrl', apiUrl);
|
||||||
|
await prefs.setString('apiKey', apiKey);
|
||||||
|
await prefs.setBool('isDemo', true);
|
||||||
|
|
||||||
if (!isAuthenticated) {
|
widget.api.apiUrl = apiUrl;
|
||||||
// ignore: use_build_context_synchronously
|
widget.api.apiKey = apiKey;
|
||||||
showDialog(
|
// ignore: use_build_context_synchronously
|
||||||
context: context,
|
Navigator.of(context).popUntil((route) => route.isFirst);
|
||||||
builder: (BuildContext context) {
|
},
|
||||||
return AlertDialog(
|
child: const Text("Connect!"),
|
||||||
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!')),
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
);
|
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();
|
if (!isAuthenticated) {
|
||||||
await prefs.setString('apiUrl', _urlController.text);
|
// ignore: use_build_context_synchronously
|
||||||
await prefs.setString('apiKey', apiKey);
|
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;
|
return;
|
||||||
widget.api.apiKey = apiKey;
|
}
|
||||||
// ignore: use_build_context_synchronously
|
|
||||||
Navigator.of(context).pop();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
},
|
await prefs.setString('apiUrl', _urlController.text);
|
||||||
child: const Text('Continue'),
|
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