mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-03 19:54:12 +00:00 
			
		
		
		
	Apply password policy on all forms
This commit is contained in:
		@@ -1,5 +1,5 @@
 | 
			
		||||
import 'package:comunic/ui/widgets/dialogs/auto_sized_dialog_content_widget.dart';
 | 
			
		||||
import 'package:comunic/utils/input_utils.dart';
 | 
			
		||||
import 'package:comunic/ui/widgets/new_password_input_widget.dart';
 | 
			
		||||
import 'package:comunic/utils/intl_utils.dart';
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
 | 
			
		||||
@@ -8,27 +8,44 @@ import 'package:flutter/material.dart';
 | 
			
		||||
/// @author Pierre HUBERT
 | 
			
		||||
 | 
			
		||||
/// Ask the user to enter a new password
 | 
			
		||||
Future<String> showInputNewPassword(BuildContext context) async {
 | 
			
		||||
Future<String> showInputNewPassword({
 | 
			
		||||
  @required BuildContext context,
 | 
			
		||||
  @required UserInfoForPassword userInfo,
 | 
			
		||||
}) async {
 | 
			
		||||
  assert(context != null);
 | 
			
		||||
  assert(userInfo != null);
 | 
			
		||||
  return await showDialog(
 | 
			
		||||
      context: context, builder: (c) => _InputNewPasswordDialog());
 | 
			
		||||
      context: context,
 | 
			
		||||
      builder: (c) => _InputNewPasswordDialog(
 | 
			
		||||
            userInfo: userInfo,
 | 
			
		||||
          ));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class _InputNewPasswordDialog extends StatefulWidget {
 | 
			
		||||
  final UserInfoForPassword userInfo;
 | 
			
		||||
 | 
			
		||||
  const _InputNewPasswordDialog({
 | 
			
		||||
    Key key,
 | 
			
		||||
    @required this.userInfo,
 | 
			
		||||
  })  : assert(userInfo != null),
 | 
			
		||||
        super(key: key);
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  __InputNewPasswordDialogState createState() =>
 | 
			
		||||
      __InputNewPasswordDialogState();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class __InputNewPasswordDialogState extends State<_InputNewPasswordDialog> {
 | 
			
		||||
  final _controller1 = TextEditingController();
 | 
			
		||||
  final _controller1 = GlobalKey<NewPasswordInputWidgetState>();
 | 
			
		||||
  final _controller2 = TextEditingController();
 | 
			
		||||
  final _focusScopeNode = FocusScopeNode();
 | 
			
		||||
 | 
			
		||||
  String get _password => _controller1.text;
 | 
			
		||||
  String get _password => _controller1.currentState.value;
 | 
			
		||||
 | 
			
		||||
  bool get _input1Valid => validatePassword(_password);
 | 
			
		||||
  bool get _input1Valid =>
 | 
			
		||||
      _controller1.currentState != null && _controller1.currentState.valid;
 | 
			
		||||
 | 
			
		||||
  bool get _input2Valid => _controller1.text == _controller2.text;
 | 
			
		||||
  bool get _input2Valid => _controller1.currentState.value == _controller2.text;
 | 
			
		||||
 | 
			
		||||
  bool get _isValid => _input1Valid && _input2Valid;
 | 
			
		||||
 | 
			
		||||
@@ -65,12 +82,10 @@ class __InputNewPasswordDialogState extends State<_InputNewPasswordDialog> {
 | 
			
		||||
      child: Column(
 | 
			
		||||
        children: <Widget>[
 | 
			
		||||
          // Input 1
 | 
			
		||||
          _buildPasswordField(
 | 
			
		||||
            controller: _controller1,
 | 
			
		||||
          NewPasswordInputWidget(
 | 
			
		||||
            key: _controller1,
 | 
			
		||||
            user: widget.userInfo,
 | 
			
		||||
            label: tr("Your new password"),
 | 
			
		||||
            errorText: _controller1.text.isNotEmpty && !_input1Valid
 | 
			
		||||
                ? tr("Invalid password!")
 | 
			
		||||
                : null,
 | 
			
		||||
            textInputAction: TextInputAction.next,
 | 
			
		||||
            onSubmitted: () => _focusScopeNode.nextFocus(),
 | 
			
		||||
          ),
 | 
			
		||||
 
 | 
			
		||||
@@ -30,7 +30,7 @@ class __InputUserPasswordDialogState
 | 
			
		||||
  String get _currPass => _controller.text;
 | 
			
		||||
 | 
			
		||||
  bool get _canSubmit =>
 | 
			
		||||
      validatePassword(_controller.text) && _status != _Status.CHECKING;
 | 
			
		||||
      legacyValidatePassword(_controller.text) && _status != _Status.CHECKING;
 | 
			
		||||
 | 
			
		||||
  void _setStatus(_Status s) => setState(() => _status = s);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user