Enforce first name & last name policies

This commit is contained in:
Pierre HUBERT 2021-04-16 07:54:03 +02:00
parent fd03975508
commit 437b4cba1b
5 changed files with 41 additions and 24 deletions

View File

@ -10,9 +10,10 @@ const FormChecker = {
* *
* @param {elem} input The input element to check * @param {elem} input The input element to check
* @param {Boolean} inFormGroup Specify wether the input is in a formgroup or not * @param {Boolean} inFormGroup Specify wether the input is in a formgroup or not
* @param {number} minLength Minimum length of input
* @return {Boolean} True or false depending of the validity of the field * @return {Boolean} True or false depending of the validity of the field
*/ */
checkInput: function(input, inFormGroup){ checkInput: function(input, inFormGroup, minLength = 3){
//Check input existence //Check input existence
if(!input){ if(!input){
//Error message //Error message
@ -28,7 +29,7 @@ const FormChecker = {
//TextInput //TextInput
if(inputType == "text"){ if(inputType == "text"){
inputOK = (input.value.length < 3 ? false:true); inputOK = (input.value.length < minLength ? false:true);
} }
//MailInput //MailInput

View File

@ -228,6 +228,7 @@ function checkMail(emailAddress){
* * @info {string} value The default value of the input * * @info {string} value The default value of the input
* * @info {boolean} disabled Set whether the field should be disabled or not * * @info {boolean} disabled Set whether the field should be disabled or not
* * @info {string} additionalGroupClasses Additionnal form group class names * * @info {string} additionalGroupClasses Additionnal form group class names
* * @info {number} maxLength Maximum allowed length for input
* @return {HTMLElement} The input * @return {HTMLElement} The input
*/ */
function createFormGroup(infos){ function createFormGroup(infos){
@ -364,6 +365,9 @@ function createFormGroup(infos){
input.placeholder = infos.placeholder; input.placeholder = infos.placeholder;
input.value = value; input.value = value;
input.disabled = disabled; input.disabled = disabled;
if (infos.maxLength)
input.maxLength = infos.maxLength;
} }
//Return input //Return input

View File

@ -58,7 +58,8 @@ ComunicWeb.pages.createAccount = {
target: formRoot, target: formRoot,
label: lang("form_create_account_first_name_label"), label: lang("form_create_account_first_name_label"),
placeholder: lang("form_create_account_first_name_placeholder"), placeholder: lang("form_create_account_first_name_placeholder"),
type: "text" type: "text",
maxLength: ServerConfig.conf.account_info_policy.max_first_name_length,
}); });
//Input user last name //Input user last name
@ -66,7 +67,8 @@ ComunicWeb.pages.createAccount = {
target: formRoot, target: formRoot,
label: lang("form_create_account_last_name_label"), label: lang("form_create_account_last_name_label"),
placeholder: lang("form_create_account_last_name_placeholder"), placeholder: lang("form_create_account_last_name_placeholder"),
type: "text" type: "text",
maxLength: ServerConfig.conf.account_info_policy.max_last_name_length,
}); });
//Input user email //Input user email
@ -145,11 +147,11 @@ ComunicWeb.pages.createAccount = {
return notify(lang("form_create_account_err_need_accept_terms"), "danger"); return notify(lang("form_create_account_err_need_accept_terms"), "danger");
//Check the first name //Check the first name
if(!FormChecker.checkInput(firstNameInput, true)) if(!FormChecker.checkInput(firstNameInput, true, ServerConfig.conf.account_info_policy.min_first_name_length))
return notify(lang("form_create_account_err_need_first_name"), "danger"); return notify(lang("form_create_account_err_need_first_name"), "danger");
//Check the last name //Check the last name
if(!FormChecker.checkInput(lastNameInput, true)) if(!FormChecker.checkInput(lastNameInput, true, ServerConfig.conf.account_info_policy.min_last_name_length))
return notify(lang("form_create_account_err_check_last_name"), "danger"); return notify(lang("form_create_account_err_check_last_name"), "danger");
//Check the email address //Check the email address

View File

@ -113,26 +113,28 @@ ComunicWeb.pages.settings.sections.general = {
// Display user first name // Display user first name
var firstName = createFormGroup({ var firstName = createFormGroup({
target: target, target: target,
label: "First name", label: tr("First name"),
placeholder: "Your first name", placeholder: tr("Your first name"),
type: "text", type: "text",
value: infos.firstName, value: infos.firstName,
maxLength: ServerConfig.conf.account_info_policy.max_first_name_length
}); });
// Last name // Last name
var lastName = createFormGroup({ var lastName = createFormGroup({
target: target, target: target,
label: "Last name", label: tr("Last name"),
placeholder: "Your last name", placeholder: tr("Your last name"),
type: "text", type: "text",
value: infos.lastName value: infos.lastName,
maxLength: ServerConfig.conf.account_info_policy.max_last_name_length
}); });
//Allow mails from Comunic //Allow mails from Comunic
var allowEmails = createFormGroup({ var allowEmails = createFormGroup({
target: target, target: target,
type: "checkbox", type: "checkbox",
label: "Allow Comunic to send you emails", label: tr("Allow Comunic to send you emails"),
checked: infos.allow_comunic_mails checked: infos.allow_comunic_mails
}); });
@ -148,7 +150,7 @@ ComunicWeb.pages.settings.sections.general = {
var publicPage = createFormGroup({ var publicPage = createFormGroup({
target: target, target: target,
type: "checkbox", type: "checkbox",
label: "Make your page public (available to every Comunic users)", label: tr("Make your page public (available to every Comunic users)"),
checked: infos.is_public checked: infos.is_public
}); });
@ -177,7 +179,7 @@ ComunicWeb.pages.settings.sections.general = {
var allowComments = createFormGroup({ var allowComments = createFormGroup({
target: target, target: target,
type: "checkbox", type: "checkbox",
label: "Allow the comments on your page", label: tr("Allow comments on your page"),
checked: infos.allow_comments checked: infos.allow_comments
}); });
@ -185,7 +187,7 @@ ComunicWeb.pages.settings.sections.general = {
var allowPostsFromFriends = createFormGroup({ var allowPostsFromFriends = createFormGroup({
target: target, target: target,
type: "checkbox", type: "checkbox",
label: "Allow the posts from your friends on your page", label: tr("Allow the creation of posts from your friends on your page"),
checked: infos.allow_posts_from_friends checked: infos.allow_posts_from_friends
}); });
@ -193,14 +195,14 @@ ComunicWeb.pages.settings.sections.general = {
var publicFriendsList = createFormGroup({ var publicFriendsList = createFormGroup({
target: target, target: target,
type: "checkbox", type: "checkbox",
label: "Make your friend list public", label: tr("Make your friend list public"),
checked: infos.public_friends_list checked: infos.public_friends_list
}); });
//Personnal website //Personnal website
var personnalWebsite = createFormGroup({ var personnalWebsite = createFormGroup({
target: target, target: target,
label: "Personnal website (optionnal)", label: tr("Personnal website (optionnal)"),
type: "text", type: "text",
placeholder: "https://...", placeholder: "https://...",
value: infos.personnal_website != "null" ? infos.personnal_website : "" value: infos.personnal_website != "null" ? infos.personnal_website : ""
@ -263,15 +265,15 @@ ComunicWeb.pages.settings.sections.general = {
sendButton.onclick = function(){ sendButton.onclick = function(){
//Check the given values //Check the given values
if(!ComunicWeb.common.formChecker.checkInput(firstName, true)) if(!ComunicWeb.common.formChecker.checkInput(firstName, true, ServerConfig.conf.account_info_policy.min_first_name_length))
return notify("Please check your first name!", "danger"); return notify(tr("Please check your first name!"), "danger");
if(!ComunicWeb.common.formChecker.checkInput(lastName, true)) if(!ComunicWeb.common.formChecker.checkInput(lastName, true, ServerConfig.conf.account_info_policy.min_last_name_length))
return notify("Please check your last name!", "danger"); return notify(tr("Please check your last name!"), "danger");
if(personnalWebsite.value != ""){ if(personnalWebsite.value != ""){
if(!check_url(personnalWebsite.value)) if(!check_url(personnalWebsite.value))
return notify("Please check the given URL !", "danger"); return notify(tr("Please check the given URL !"), "danger");
} }
//Pack all the values in an object //Pack all the values in an object

View File

@ -33,6 +33,13 @@ declare interface ConversationPolicy {
writing_event_lifetime: number, writing_event_lifetime: number,
} }
declare interface AccountInformationPolicy {
min_first_name_length: number,
max_first_name_length: number,
min_last_name_length: number,
max_last_name_length: number,
}
declare interface StaticServerConfig { declare interface StaticServerConfig {
terms_url: string, terms_url: string,
privacy_policy_url: string, privacy_policy_url: string,
@ -41,4 +48,5 @@ declare interface StaticServerConfig {
password_policy: PasswordPolicy, password_policy: PasswordPolicy,
data_conservation_policy: DataConservationPolicySettings, data_conservation_policy: DataConservationPolicySettings,
conversations_policy: ConversationPolicy, conversations_policy: ConversationPolicy,
account_info_policy: AccountInformationPolicy,
} }