fix: separate server setup page, fix already-logged-in precondition error
This commit is contained in:
@@ -12,22 +12,26 @@ class LoginPage extends ConsumerStatefulWidget {
|
||||
|
||||
class _LoginPageState extends ConsumerState<LoginPage> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final _userIdCtrl = TextEditingController();
|
||||
final _passwordCtrl = TextEditingController();
|
||||
bool _obscurePassword = true;
|
||||
final _userCtrl = TextEditingController();
|
||||
final _passCtrl = TextEditingController();
|
||||
bool _obscure = true;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_userIdCtrl.dispose();
|
||||
_passwordCtrl.dispose();
|
||||
_userCtrl.dispose();
|
||||
_passCtrl.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _submit() async {
|
||||
if (!_formKey.currentState!.validate()) return;
|
||||
|
||||
final homeserver = ref.read(homeserverProvider).valueOrNull ?? 'matrix.org';
|
||||
|
||||
await ref.read(loginNotifierProvider.notifier).login(
|
||||
userId: _userIdCtrl.text.trim(),
|
||||
password: _passwordCtrl.text,
|
||||
username: _userCtrl.text.trim(),
|
||||
password: _passCtrl.text,
|
||||
homeserver: homeserver,
|
||||
);
|
||||
|
||||
final state = ref.read(loginNotifierProvider);
|
||||
@@ -38,8 +42,10 @@ class _LoginPageState extends ConsumerState<LoginPage> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final state = ref.watch(loginNotifierProvider);
|
||||
final loading = state.status == LoginStatus.loading;
|
||||
final theme = Theme.of(context);
|
||||
final loginState = ref.watch(loginNotifierProvider);
|
||||
final loading = loginState.status == LoginStatus.loading;
|
||||
final homeserver = ref.watch(homeserverProvider).valueOrNull ?? 'matrix.org';
|
||||
|
||||
return Scaffold(
|
||||
body: Center(
|
||||
@@ -53,43 +59,73 @@ class _LoginPageState extends ConsumerState<LoginPage> {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const _PyramidLogo(),
|
||||
Icon(
|
||||
Icons.change_history_rounded,
|
||||
size: 72,
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'Pyramid',
|
||||
textAlign: TextAlign.center,
|
||||
style: theme.textTheme.headlineMedium
|
||||
?.copyWith(fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
// Server-Anzeige mit Wechsel-Link
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.dns_outlined,
|
||||
size: 14,
|
||||
color: theme.colorScheme.onSurfaceVariant),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
homeserver,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
GestureDetector(
|
||||
onTap: () => context.go('/server'),
|
||||
child: Text(
|
||||
'ändern',
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.primary,
|
||||
decoration: TextDecoration.underline,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
TextFormField(
|
||||
controller: _userIdCtrl,
|
||||
controller: _userCtrl,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Matrix ID',
|
||||
hintText: '@name:server.de',
|
||||
labelText: 'Nutzername',
|
||||
hintText: 'dein_name',
|
||||
prefixIcon: Icon(Icons.person_outline),
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
autofillHints: const [AutofillHints.username],
|
||||
validator: (v) {
|
||||
if (v == null || v.trim().isEmpty) {
|
||||
return 'Matrix ID eingeben';
|
||||
}
|
||||
if (!v.trim().startsWith('@') ||
|
||||
!v.trim().contains(':')) {
|
||||
return 'Format: @name:server.de';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
validator: (v) => (v == null || v.trim().isEmpty)
|
||||
? 'Nutzername eingeben'
|
||||
: null,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextFormField(
|
||||
controller: _passwordCtrl,
|
||||
obscureText: _obscurePassword,
|
||||
controller: _passCtrl,
|
||||
obscureText: _obscure,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Passwort',
|
||||
prefixIcon: const Icon(Icons.lock_outline),
|
||||
border: const OutlineInputBorder(),
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(_obscurePassword
|
||||
icon: Icon(_obscure
|
||||
? Icons.visibility_outlined
|
||||
: Icons.visibility_off_outlined),
|
||||
onPressed: () => setState(
|
||||
() => _obscurePassword = !_obscurePassword),
|
||||
onPressed: () => setState(() => _obscure = !_obscure),
|
||||
),
|
||||
),
|
||||
autofillHints: const [AutofillHints.password],
|
||||
@@ -97,12 +133,11 @@ class _LoginPageState extends ConsumerState<LoginPage> {
|
||||
(v == null || v.isEmpty) ? 'Passwort eingeben' : null,
|
||||
onFieldSubmitted: (_) => _submit(),
|
||||
),
|
||||
if (state.errorMessage != null) ...[
|
||||
if (loginState.errorMessage != null) ...[
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
state.errorMessage!,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.error),
|
||||
loginState.errorMessage!,
|
||||
style: TextStyle(color: theme.colorScheme.error),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
@@ -126,28 +161,3 @@ class _LoginPageState extends ConsumerState<LoginPage> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _PyramidLogo extends StatelessWidget {
|
||||
const _PyramidLogo();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.change_history_rounded,
|
||||
size: 72,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'Pyramid',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.headlineMedium
|
||||
?.copyWith(fontWeight: FontWeight.bold),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user