register app in ui
This commit is contained in:
parent
bc8d31ccbc
commit
4baacc751d
3 changed files with 101 additions and 10 deletions
|
@ -1,7 +1,11 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart';
|
||||
import 'package:slothmu/business_logic/user.dart';
|
||||
import 'package:localization/localization.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import '../business_logic/auth/oauth.dart' as oauth;
|
||||
import '../business_logic/settings.dart' as settings;
|
||||
import '../business_logic/user.dart' as user;
|
||||
|
||||
class Login extends StatefulWidget {
|
||||
const Login({Key? key}) : super(key: key);
|
||||
|
@ -44,6 +48,11 @@ class _LoginFormState extends State<LoginForm> {
|
|||
children: [
|
||||
Text("greeting".i18n(), style: const TextStyle(fontSize: 64)),
|
||||
TextFormField(
|
||||
onSaved: (value) async {
|
||||
await settings
|
||||
.saveInstanceUrl(user.urlFromUsername(name: value!));
|
||||
await settings.saveUsername(user.userFromUsername(name: value));
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
labelText: "user-id".i18n(),
|
||||
hintText: "user-id-example".i18n(),
|
||||
|
@ -54,8 +63,6 @@ class _LoginFormState extends State<LoginForm> {
|
|||
validator: (value) {
|
||||
if (value!.isEmpty || !isValidUsername(name: value)) {
|
||||
return "user-id-not-valid".i18n();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
),
|
||||
|
@ -66,6 +73,7 @@ class _LoginFormState extends State<LoginForm> {
|
|||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text("login-failed-snackbar-text".i18n())));
|
||||
} else {
|
||||
formKey.currentState?.save();
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
|
@ -82,6 +90,9 @@ class _LoginFormState extends State<LoginForm> {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
page that handles authenticating user
|
||||
*/
|
||||
class AuthPage extends StatefulWidget {
|
||||
const AuthPage({Key? key, required String baseurl}) : super(key: key);
|
||||
|
||||
|
@ -94,7 +105,7 @@ class _AuthPageState extends State<AuthPage> {
|
|||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
|
@ -103,7 +114,43 @@ class _AuthPageState extends State<AuthPage> {
|
|||
decoration: InputDecoration(
|
||||
hintText: "123-ABC",
|
||||
icon: const Icon(Icons.password),
|
||||
labelText: "code-hint".i18n()))
|
||||
labelText: "code-hint".i18n())),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
TextButton.icon(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
label: Text("back-button".i18n())),
|
||||
FutureBuilder<http.Response>(
|
||||
future: oauth.askKnownServerForAppRegistration(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasError) {
|
||||
return Text("login-failed-snackbar-text".i18n());
|
||||
} else if (snapshot.hasData) {
|
||||
if (snapshot.data?.statusCode != null) {
|
||||
print(snapshot.data?.body);
|
||||
if (snapshot.data?.statusCode != 200) {
|
||||
return Row(
|
||||
children: [
|
||||
Text("error ${snapshot.data!.statusCode}")
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
return TextButton.icon(
|
||||
onPressed: null,
|
||||
icon: const Icon(Icons.check),
|
||||
label: Text("confirm-button".i18n()));
|
||||
} else {
|
||||
return const CircularProgressIndicator();
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue