mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-06-19 08:15:16 +00:00
Apply password policy on all forms
This commit is contained in:
@ -1,6 +1,5 @@
|
||||
import 'package:comunic/helpers/server_config_helper.dart';
|
||||
import 'package:comunic/models/server_config.dart';
|
||||
import 'package:comunic/models/user.dart';
|
||||
import 'package:comunic/utils/intl_utils.dart';
|
||||
import 'package:comunic/utils/ui_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@ -9,26 +8,38 @@ import 'package:flutter/material.dart';
|
||||
///
|
||||
/// @author Pierre Hubert
|
||||
|
||||
class NewPasswordInputWidget extends StatefulWidget {
|
||||
final Widget icon;
|
||||
final VoidCallback onEdited;
|
||||
final String label;
|
||||
|
||||
final User user;
|
||||
class UserInfoForPassword {
|
||||
final String firstName;
|
||||
final String lastName;
|
||||
final String email;
|
||||
|
||||
const UserInfoForPassword({
|
||||
@required this.firstName,
|
||||
@required this.lastName,
|
||||
@required this.email,
|
||||
});
|
||||
}
|
||||
|
||||
class NewPasswordInputWidget extends StatefulWidget {
|
||||
final Widget icon;
|
||||
final VoidCallback onEdited;
|
||||
final VoidCallback onSubmitted;
|
||||
final TextInputAction textInputAction;
|
||||
final String label;
|
||||
|
||||
final UserInfoForPassword user;
|
||||
|
||||
const NewPasswordInputWidget({
|
||||
Key key,
|
||||
this.icon,
|
||||
this.onEdited,
|
||||
this.onSubmitted,
|
||||
this.textInputAction,
|
||||
@required this.label,
|
||||
this.user,
|
||||
this.firstName,
|
||||
this.lastName,
|
||||
this.email,
|
||||
}) : super(key: key);
|
||||
@required this.user,
|
||||
}) : assert(label != null),
|
||||
assert(user != null),
|
||||
super(key: key);
|
||||
|
||||
@override
|
||||
NewPasswordInputWidgetState createState() => NewPasswordInputWidgetState();
|
||||
@ -73,6 +84,9 @@ class NewPasswordInputWidgetState extends State<NewPasswordInputWidget> {
|
||||
controller: _controller,
|
||||
obscureText: true,
|
||||
onChanged: (s) => _onChanged(),
|
||||
onSubmitted:
|
||||
widget.onSubmitted == null ? null : (s) => widget.onSubmitted(),
|
||||
textInputAction: widget.textInputAction,
|
||||
decoration: InputDecoration(
|
||||
errorText: _errorMessage,
|
||||
errorMaxLines: 3,
|
||||
@ -92,28 +106,21 @@ class NewPasswordInputWidgetState extends State<NewPasswordInputWidget> {
|
||||
|
||||
// Mandatory checks
|
||||
if (!_policy.allowMailInPassword &&
|
||||
(widget.email ?? "").isNotEmpty &&
|
||||
(widget.email.toLowerCase().contains(value.toLowerCase()) ||
|
||||
value.toLowerCase().contains(widget.email.toLowerCase()))) {
|
||||
return tr("Your password must not contains part of your email address!");
|
||||
}
|
||||
|
||||
if (!_policy.allowMailInPassword &&
|
||||
(widget.email ?? "").isNotEmpty &&
|
||||
(widget.email.toLowerCase().contains(value.toLowerCase()) ||
|
||||
value.toLowerCase().contains(widget.email.toLowerCase()))) {
|
||||
(widget.user.email ?? "").isNotEmpty &&
|
||||
(widget.user.email.toLowerCase().contains(value.toLowerCase()) ||
|
||||
value.toLowerCase().contains(widget.user.email.toLowerCase()))) {
|
||||
return tr("Your password must not contains part of your email address!");
|
||||
}
|
||||
|
||||
if (!_policy.allowNameInPassword &&
|
||||
(widget.firstName ?? "").isNotEmpty &&
|
||||
value.toLowerCase().contains(widget.firstName.toLowerCase())) {
|
||||
(widget.user.firstName ?? "").isNotEmpty &&
|
||||
value.toLowerCase().contains(widget.user.firstName.toLowerCase())) {
|
||||
return tr("Your password must not contains your first name!");
|
||||
}
|
||||
|
||||
if (!_policy.allowNameInPassword &&
|
||||
(widget.lastName ?? "").isNotEmpty &&
|
||||
value.toLowerCase().contains(widget.lastName.toLowerCase())) {
|
||||
(widget.user.lastName ?? "").isNotEmpty &&
|
||||
value.toLowerCase().contains(widget.user.lastName.toLowerCase())) {
|
||||
return tr("Your password must not contains your last name!");
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user