mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 04:49:21 +00:00
Apply new min & max name policy
This commit is contained in:
parent
ed5d48a0b9
commit
447cdac476
@ -21,10 +21,15 @@ class APIHelper {
|
|||||||
//Add API tokens
|
//Add API tokens
|
||||||
request.addString("client", config().clientName);
|
request.addString("client", config().clientName);
|
||||||
|
|
||||||
//Add user tokens (if required)
|
//Add user token (if required)
|
||||||
if (request.needLogin) {
|
if (request.needLogin) {
|
||||||
final token = (await PreferencesHelper.getInstance()).getLoginToken();
|
final token = (await PreferencesHelper.getInstance()).getLoginToken();
|
||||||
assert(token != null);
|
|
||||||
|
if (token == null) {
|
||||||
|
EventsHelper.emit(InvalidLoginTokensEvent());
|
||||||
|
throw new Exception("No login token available!");
|
||||||
|
}
|
||||||
|
|
||||||
request.addString("token", token);
|
request.addString("token", token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,59 +21,66 @@ class ServerConfigurationHelper {
|
|||||||
final passwordPolicy = response["password_policy"];
|
final passwordPolicy = response["password_policy"];
|
||||||
final dataConservationPolicy = response["data_conservation_policy"];
|
final dataConservationPolicy = response["data_conservation_policy"];
|
||||||
final conversationsPolicy = response["conversations_policy"];
|
final conversationsPolicy = response["conversations_policy"];
|
||||||
|
final accountInformationPolicy = response["account_info_policy"];
|
||||||
|
|
||||||
_config = ServerConfig(
|
_config = ServerConfig(
|
||||||
minSupportedMobileVersion:
|
minSupportedMobileVersion:
|
||||||
Version.parse(response["min_supported_mobile_version"]),
|
Version.parse(response["min_supported_mobile_version"]),
|
||||||
termsURL: response["terms_url"],
|
termsURL: response["terms_url"],
|
||||||
playStoreURL: response["play_store_url"],
|
playStoreURL: response["play_store_url"],
|
||||||
androidDirectDownloadURL: response["android_direct_download_url"],
|
androidDirectDownloadURL: response["android_direct_download_url"],
|
||||||
notificationsPolicy: NotificationsPolicy(
|
notificationsPolicy: NotificationsPolicy(
|
||||||
hasFirebase: pushNotificationsPolicy["has_firebase"],
|
hasFirebase: pushNotificationsPolicy["has_firebase"],
|
||||||
hasIndependent: pushNotificationsPolicy["has_independent"],
|
hasIndependent: pushNotificationsPolicy["has_independent"],
|
||||||
),
|
),
|
||||||
passwordPolicy: PasswordPolicy(
|
passwordPolicy: PasswordPolicy(
|
||||||
allowMailInPassword: passwordPolicy["allow_email_in_password"],
|
allowMailInPassword: passwordPolicy["allow_email_in_password"],
|
||||||
allowNameInPassword: passwordPolicy["allow_name_in_password"],
|
allowNameInPassword: passwordPolicy["allow_name_in_password"],
|
||||||
minPasswordLength: passwordPolicy["min_password_length"],
|
minPasswordLength: passwordPolicy["min_password_length"],
|
||||||
minNumberUpperCaseLetters:
|
minNumberUpperCaseLetters:
|
||||||
passwordPolicy["min_number_upper_case_letters"],
|
passwordPolicy["min_number_upper_case_letters"],
|
||||||
minNumberLowerCaseLetters:
|
minNumberLowerCaseLetters:
|
||||||
passwordPolicy["min_number_lower_case_letters"],
|
passwordPolicy["min_number_lower_case_letters"],
|
||||||
minNumberDigits: passwordPolicy["min_number_digits"],
|
minNumberDigits: passwordPolicy["min_number_digits"],
|
||||||
minNumberSpecialCharacters:
|
minNumberSpecialCharacters:
|
||||||
passwordPolicy["min_number_special_characters"],
|
passwordPolicy["min_number_special_characters"],
|
||||||
minCategoriesPresence: passwordPolicy["min_categories_presence"],
|
minCategoriesPresence: passwordPolicy["min_categories_presence"],
|
||||||
),
|
),
|
||||||
dataConservationPolicy: ServerDataConservationPolicy(
|
dataConservationPolicy: ServerDataConservationPolicy(
|
||||||
minInactiveAccountLifetime:
|
minInactiveAccountLifetime:
|
||||||
dataConservationPolicy["min_inactive_account_lifetime"],
|
dataConservationPolicy["min_inactive_account_lifetime"],
|
||||||
minNotificationLifetime:
|
minNotificationLifetime:
|
||||||
dataConservationPolicy["min_notification_lifetime"],
|
dataConservationPolicy["min_notification_lifetime"],
|
||||||
minCommentsLifetime: dataConservationPolicy["min_comments_lifetime"],
|
minCommentsLifetime: dataConservationPolicy["min_comments_lifetime"],
|
||||||
minPostsLifetime: dataConservationPolicy["min_posts_lifetime"],
|
minPostsLifetime: dataConservationPolicy["min_posts_lifetime"],
|
||||||
minConversationMessagesLifetime:
|
minConversationMessagesLifetime:
|
||||||
dataConservationPolicy["min_conversation_messages_lifetime"],
|
dataConservationPolicy["min_conversation_messages_lifetime"],
|
||||||
minLikesLifetime: dataConservationPolicy["min_likes_lifetime"],
|
minLikesLifetime: dataConservationPolicy["min_likes_lifetime"],
|
||||||
),
|
),
|
||||||
conversationsPolicy: ConversationsPolicy(
|
conversationsPolicy: ConversationsPolicy(
|
||||||
maxConversationNameLen:
|
maxConversationNameLen:
|
||||||
conversationsPolicy["max_conversation_name_len"],
|
conversationsPolicy["max_conversation_name_len"],
|
||||||
minMessageLen: conversationsPolicy["min_message_len"],
|
minMessageLen: conversationsPolicy["min_message_len"],
|
||||||
maxMessageLen: conversationsPolicy["max_message_len"],
|
maxMessageLen: conversationsPolicy["max_message_len"],
|
||||||
allowedFilesType:
|
allowedFilesType:
|
||||||
conversationsPolicy["allowed_files_type"].cast<String>(),
|
conversationsPolicy["allowed_files_type"].cast<String>(),
|
||||||
filesMaxSize: conversationsPolicy["files_max_size"],
|
filesMaxSize: conversationsPolicy["files_max_size"],
|
||||||
writingEventInterval: conversationsPolicy["writing_event_interval"],
|
writingEventInterval: conversationsPolicy["writing_event_interval"],
|
||||||
writingEventLifetime: conversationsPolicy["writing_event_lifetime"],
|
writingEventLifetime: conversationsPolicy["writing_event_lifetime"],
|
||||||
maxMessageImageWidth: conversationsPolicy["max_message_image_width"],
|
maxMessageImageWidth: conversationsPolicy["max_message_image_width"],
|
||||||
maxMessageImageHeight:
|
maxMessageImageHeight: conversationsPolicy["max_message_image_height"],
|
||||||
conversationsPolicy["max_message_image_height"],
|
maxThumbnailWidth: conversationsPolicy["max_thumbnail_width"],
|
||||||
maxThumbnailWidth: conversationsPolicy["max_thumbnail_width"],
|
maxThumbnailHeight: conversationsPolicy["max_thumbnail_height"],
|
||||||
maxThumbnailHeight: conversationsPolicy["max_thumbnail_height"],
|
maxLogoWidth: conversationsPolicy["max_logo_width"],
|
||||||
maxLogoWidth: conversationsPolicy["max_logo_width"],
|
maxLogoHeight: conversationsPolicy["max_logo_height"],
|
||||||
maxLogoHeight: conversationsPolicy["max_logo_height"],
|
),
|
||||||
));
|
accountInformationPolicy: AccountInformationPolicy(
|
||||||
|
minFirstNameLength: accountInformationPolicy["min_first_name_length"],
|
||||||
|
maxFirstNameLength: accountInformationPolicy["max_first_name_length"],
|
||||||
|
minLastNameLength: accountInformationPolicy["min_last_name_length"],
|
||||||
|
maxLastNameLength: accountInformationPolicy["max_last_name_length"],
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get current server configuration, throwing if it is not loaded yet
|
/// Get current server configuration, throwing if it is not loaded yet
|
||||||
|
@ -112,6 +112,23 @@ class ConversationsPolicy {
|
|||||||
assert(maxLogoHeight != null);
|
assert(maxLogoHeight != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class AccountInformationPolicy {
|
||||||
|
final int minFirstNameLength;
|
||||||
|
final int maxFirstNameLength;
|
||||||
|
final int minLastNameLength;
|
||||||
|
final int maxLastNameLength;
|
||||||
|
|
||||||
|
const AccountInformationPolicy({
|
||||||
|
@required this.minFirstNameLength,
|
||||||
|
@required this.maxFirstNameLength,
|
||||||
|
@required this.minLastNameLength,
|
||||||
|
@required this.maxLastNameLength,
|
||||||
|
}) : assert(minFirstNameLength != null),
|
||||||
|
assert(maxFirstNameLength != null),
|
||||||
|
assert(minLastNameLength != null),
|
||||||
|
assert(maxLastNameLength != null);
|
||||||
|
}
|
||||||
|
|
||||||
class ServerConfig {
|
class ServerConfig {
|
||||||
final Version minSupportedMobileVersion;
|
final Version minSupportedMobileVersion;
|
||||||
final String termsURL;
|
final String termsURL;
|
||||||
@ -121,6 +138,7 @@ class ServerConfig {
|
|||||||
final PasswordPolicy passwordPolicy;
|
final PasswordPolicy passwordPolicy;
|
||||||
final ServerDataConservationPolicy dataConservationPolicy;
|
final ServerDataConservationPolicy dataConservationPolicy;
|
||||||
final ConversationsPolicy conversationsPolicy;
|
final ConversationsPolicy conversationsPolicy;
|
||||||
|
final AccountInformationPolicy accountInformationPolicy;
|
||||||
|
|
||||||
const ServerConfig({
|
const ServerConfig({
|
||||||
@required this.minSupportedMobileVersion,
|
@required this.minSupportedMobileVersion,
|
||||||
@ -131,6 +149,7 @@ class ServerConfig {
|
|||||||
@required this.passwordPolicy,
|
@required this.passwordPolicy,
|
||||||
@required this.dataConservationPolicy,
|
@required this.dataConservationPolicy,
|
||||||
@required this.conversationsPolicy,
|
@required this.conversationsPolicy,
|
||||||
|
@required this.accountInformationPolicy,
|
||||||
}) : assert(minSupportedMobileVersion != null),
|
}) : assert(minSupportedMobileVersion != null),
|
||||||
assert(termsURL != null),
|
assert(termsURL != null),
|
||||||
assert(playStoreURL != null),
|
assert(playStoreURL != null),
|
||||||
@ -138,5 +157,6 @@ class ServerConfig {
|
|||||||
assert(notificationsPolicy != null),
|
assert(notificationsPolicy != null),
|
||||||
assert(passwordPolicy != null),
|
assert(passwordPolicy != null),
|
||||||
assert(dataConservationPolicy != null),
|
assert(dataConservationPolicy != null),
|
||||||
assert(conversationsPolicy != null);
|
assert(conversationsPolicy != null),
|
||||||
|
assert(accountInformationPolicy != null);
|
||||||
}
|
}
|
||||||
|
@ -44,9 +44,13 @@ class __CreateAccountRouteBodyState extends State<_CreateAccountRouteBody> {
|
|||||||
|
|
||||||
bool _showErrors = false;
|
bool _showErrors = false;
|
||||||
|
|
||||||
bool get _isFirstNameValid => _firstNameController.text.length > 3;
|
bool get _isFirstNameValid =>
|
||||||
|
_firstNameController.text.length >=
|
||||||
|
srvConfig.accountInformationPolicy.minFirstNameLength;
|
||||||
|
|
||||||
bool get _isLastNameValid => _lastNameController.text.length > 3;
|
bool get _isLastNameValid =>
|
||||||
|
_lastNameController.text.length >=
|
||||||
|
srvConfig.accountInformationPolicy.minLastNameLength;
|
||||||
|
|
||||||
bool get _isEmailValid => validateEmail(_emailController.text);
|
bool get _isEmailValid => validateEmail(_emailController.text);
|
||||||
|
|
||||||
@ -97,6 +101,8 @@ class __CreateAccountRouteBodyState extends State<_CreateAccountRouteBody> {
|
|||||||
label: tr("First name"),
|
label: tr("First name"),
|
||||||
onEdited: _updateUI,
|
onEdited: _updateUI,
|
||||||
icon: Icon(Icons.perm_identity),
|
icon: Icon(Icons.perm_identity),
|
||||||
|
maxLength:
|
||||||
|
srvConfig.accountInformationPolicy.maxFirstNameLength,
|
||||||
error: _showErrors && !_isFirstNameValid
|
error: _showErrors && !_isFirstNameValid
|
||||||
? tr("Invalid first name!")
|
? tr("Invalid first name!")
|
||||||
: null,
|
: null,
|
||||||
@ -108,6 +114,7 @@ class __CreateAccountRouteBodyState extends State<_CreateAccountRouteBody> {
|
|||||||
label: tr("Last name"),
|
label: tr("Last name"),
|
||||||
onEdited: _updateUI,
|
onEdited: _updateUI,
|
||||||
icon: Icon(Icons.perm_identity),
|
icon: Icon(Icons.perm_identity),
|
||||||
|
maxLength: srvConfig.accountInformationPolicy.maxLastNameLength,
|
||||||
error: _showErrors && !_isLastNameValid
|
error: _showErrors && !_isLastNameValid
|
||||||
? tr("Invalid last name!")
|
? tr("Invalid last name!")
|
||||||
: null,
|
: null,
|
||||||
@ -268,6 +275,7 @@ class _InputEntry extends StatelessWidget {
|
|||||||
final String error;
|
final String error;
|
||||||
final Widget icon;
|
final Widget icon;
|
||||||
final TextInputType keyboard;
|
final TextInputType keyboard;
|
||||||
|
final int maxLength;
|
||||||
|
|
||||||
const _InputEntry({
|
const _InputEntry({
|
||||||
Key key,
|
Key key,
|
||||||
@ -278,6 +286,7 @@ class _InputEntry extends StatelessWidget {
|
|||||||
this.error,
|
this.error,
|
||||||
this.icon,
|
this.icon,
|
||||||
this.keyboard,
|
this.keyboard,
|
||||||
|
this.maxLength,
|
||||||
}) : assert(controller != null),
|
}) : assert(controller != null),
|
||||||
assert(label != null),
|
assert(label != null),
|
||||||
assert(onEdited != null),
|
assert(onEdited != null),
|
||||||
@ -291,6 +300,7 @@ class _InputEntry extends StatelessWidget {
|
|||||||
onChanged: (s) => onEdited(),
|
onChanged: (s) => onEdited(),
|
||||||
keyboardType: keyboard,
|
keyboardType: keyboard,
|
||||||
obscureText: isPassword,
|
obscureText: isPassword,
|
||||||
|
maxLength: maxLength,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
alignLabelWithHint: true,
|
alignLabelWithHint: true,
|
||||||
errorText: error,
|
errorText: error,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import 'package:comunic/enums/user_page_visibility.dart';
|
import 'package:comunic/enums/user_page_visibility.dart';
|
||||||
import 'package:comunic/helpers/serialization/user_list_serialization_helper.dart';
|
import 'package:comunic/helpers/serialization/user_list_serialization_helper.dart';
|
||||||
|
import 'package:comunic/helpers/server_config_helper.dart';
|
||||||
import 'package:comunic/helpers/settings_helper.dart';
|
import 'package:comunic/helpers/settings_helper.dart';
|
||||||
import 'package:comunic/models/general_settings.dart';
|
import 'package:comunic/models/general_settings.dart';
|
||||||
import 'package:comunic/ui/dialogs/multi_choices_dialog.dart';
|
import 'package:comunic/ui/dialogs/multi_choices_dialog.dart';
|
||||||
@ -86,7 +87,9 @@ class _GeneralAccountSettingsScreenState
|
|||||||
_settings.firstName = s;
|
_settings.firstName = s;
|
||||||
_updateSettings();
|
_updateSettings();
|
||||||
},
|
},
|
||||||
checkInput: (s) => s.length >= 3,
|
maxLength: srvConfig.accountInformationPolicy.maxFirstNameLength,
|
||||||
|
checkInput: (s) =>
|
||||||
|
s.length >= srvConfig.accountInformationPolicy.minFirstNameLength,
|
||||||
),
|
),
|
||||||
|
|
||||||
// Last name
|
// Last name
|
||||||
@ -97,7 +100,9 @@ class _GeneralAccountSettingsScreenState
|
|||||||
_settings.lastName = s;
|
_settings.lastName = s;
|
||||||
_updateSettings();
|
_updateSettings();
|
||||||
},
|
},
|
||||||
checkInput: (s) => s.length >= 3,
|
maxLength: srvConfig.accountInformationPolicy.maxLastNameLength,
|
||||||
|
checkInput: (s) =>
|
||||||
|
s.length >= srvConfig.accountInformationPolicy.minLastNameLength,
|
||||||
),
|
),
|
||||||
|
|
||||||
// Emails settings
|
// Emails settings
|
||||||
|
Loading…
Reference in New Issue
Block a user