138 lines
4.9 KiB
Dart
138 lines
4.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import '../../../providers/auth_provider.dart';
|
|
import '../../../core/utils/validators.dart';
|
|
import '../../../core/theme/app_theme.dart';
|
|
|
|
class ResetPasswordScreen extends ConsumerStatefulWidget {
|
|
const ResetPasswordScreen({super.key});
|
|
|
|
@override
|
|
ConsumerState<ResetPasswordScreen> createState() =>
|
|
_ResetPasswordScreenState();
|
|
}
|
|
|
|
class _ResetPasswordScreenState extends ConsumerState<ResetPasswordScreen> {
|
|
final _formKey = GlobalKey<FormState>();
|
|
final _tokenController = TextEditingController();
|
|
final _passwordController = TextEditingController();
|
|
final _confirmController = TextEditingController();
|
|
bool _success = false;
|
|
|
|
@override
|
|
void dispose() {
|
|
_tokenController.dispose();
|
|
_passwordController.dispose();
|
|
_confirmController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final authState = ref.watch(authProvider);
|
|
final authNotifier = ref.read(authProvider.notifier);
|
|
|
|
return Scaffold(
|
|
appBar: AppBar(title: const Text('Новый пароль')),
|
|
body: Padding(
|
|
padding: const EdgeInsets.all(24),
|
|
child: Form(
|
|
key: _formKey,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
const SizedBox(height: 48),
|
|
const Icon(
|
|
Icons.lock_reset,
|
|
size: 64,
|
|
color: VoIdeaColors.primary,
|
|
),
|
|
const SizedBox(height: 24),
|
|
if (!_success) ...[
|
|
Text(
|
|
'Введите код из письма и новый пароль',
|
|
textAlign: TextAlign.center,
|
|
style: Theme.of(context).textTheme.bodyLarge,
|
|
),
|
|
const SizedBox(height: 32),
|
|
TextFormField(
|
|
controller: _tokenController,
|
|
decoration: const InputDecoration(
|
|
labelText: 'Код из письма',
|
|
prefixIcon: Icon(Icons.vpn_key_outlined),
|
|
),
|
|
validator: (v) => Validators.required(v, 'Код'),
|
|
),
|
|
const SizedBox(height: 16),
|
|
TextFormField(
|
|
controller: _passwordController,
|
|
obscureText: true,
|
|
decoration: const InputDecoration(
|
|
labelText: 'Новый пароль',
|
|
prefixIcon: Icon(Icons.lock_outlined),
|
|
),
|
|
validator: Validators.password,
|
|
),
|
|
const SizedBox(height: 16),
|
|
TextFormField(
|
|
controller: _confirmController,
|
|
obscureText: true,
|
|
decoration: const InputDecoration(
|
|
labelText: 'Подтвердите пароль',
|
|
prefixIcon: Icon(Icons.lock_outlined),
|
|
),
|
|
validator: (v) =>
|
|
Validators.confirmPassword(v, _passwordController.text),
|
|
),
|
|
const SizedBox(height: 24),
|
|
if (authState.error != null)
|
|
Padding(
|
|
padding: const EdgeInsets.only(bottom: 16),
|
|
child: Text(
|
|
authState.error!,
|
|
style: const TextStyle(color: VoIdeaColors.error),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
),
|
|
ElevatedButton(
|
|
onPressed: authState.status == AuthStatus.loading
|
|
? null
|
|
: () {
|
|
if (_formKey.currentState!.validate()) {
|
|
authNotifier
|
|
.resetPassword(
|
|
_tokenController.text.trim(),
|
|
_passwordController.text,
|
|
)
|
|
.then((_) => setState(() => _success = true));
|
|
}
|
|
},
|
|
child: const Text('Сохранить'),
|
|
),
|
|
] else ...[
|
|
const Icon(
|
|
Icons.check_circle,
|
|
size: 64,
|
|
color: VoIdeaColors.success,
|
|
),
|
|
const SizedBox(height: 16),
|
|
Text(
|
|
'Пароль изменён',
|
|
textAlign: TextAlign.center,
|
|
style: Theme.of(context).textTheme.titleLarge,
|
|
),
|
|
const SizedBox(height: 24),
|
|
ElevatedButton(
|
|
onPressed: () => context.go('/auth/login'),
|
|
child: const Text('Войти'),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|