mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-12-24 18:08:50 +00:00
Enforce first name & last name policies
This commit is contained in:
parent
fd03975508
commit
437b4cba1b
@ -10,9 +10,10 @@ const FormChecker = {
|
||||
*
|
||||
* @param {elem} input The input element to check
|
||||
* @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
|
||||
*/
|
||||
checkInput: function(input, inFormGroup){
|
||||
checkInput: function(input, inFormGroup, minLength = 3){
|
||||
//Check input existence
|
||||
if(!input){
|
||||
//Error message
|
||||
@ -28,7 +29,7 @@ const FormChecker = {
|
||||
|
||||
//TextInput
|
||||
if(inputType == "text"){
|
||||
inputOK = (input.value.length < 3 ? false:true);
|
||||
inputOK = (input.value.length < minLength ? false:true);
|
||||
}
|
||||
|
||||
//MailInput
|
||||
|
@ -228,6 +228,7 @@ function checkMail(emailAddress){
|
||||
* * @info {string} value The default value of the input
|
||||
* * @info {boolean} disabled Set whether the field should be disabled or not
|
||||
* * @info {string} additionalGroupClasses Additionnal form group class names
|
||||
* * @info {number} maxLength Maximum allowed length for input
|
||||
* @return {HTMLElement} The input
|
||||
*/
|
||||
function createFormGroup(infos){
|
||||
@ -364,6 +365,9 @@ function createFormGroup(infos){
|
||||
input.placeholder = infos.placeholder;
|
||||
input.value = value;
|
||||
input.disabled = disabled;
|
||||
|
||||
if (infos.maxLength)
|
||||
input.maxLength = infos.maxLength;
|
||||
}
|
||||
|
||||
//Return input
|
||||
|
@ -58,7 +58,8 @@ ComunicWeb.pages.createAccount = {
|
||||
target: formRoot,
|
||||
label: lang("form_create_account_first_name_label"),
|
||||
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
|
||||
@ -66,7 +67,8 @@ ComunicWeb.pages.createAccount = {
|
||||
target: formRoot,
|
||||
label: lang("form_create_account_last_name_label"),
|
||||
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
|
||||
@ -145,11 +147,11 @@ ComunicWeb.pages.createAccount = {
|
||||
return notify(lang("form_create_account_err_need_accept_terms"), "danger");
|
||||
|
||||
//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");
|
||||
|
||||
//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");
|
||||
|
||||
//Check the email address
|
||||
|
@ -110,29 +110,31 @@ ComunicWeb.pages.settings.sections.general = {
|
||||
additionalGroupClasses: "input-user-email"
|
||||
});
|
||||
|
||||
//Display user first name
|
||||
// Display user first name
|
||||
var firstName = createFormGroup({
|
||||
target: target,
|
||||
label: "First name",
|
||||
placeholder: "Your first name",
|
||||
label: tr("First name"),
|
||||
placeholder: tr("Your first name"),
|
||||
type: "text",
|
||||
value: infos.firstName,
|
||||
maxLength: ServerConfig.conf.account_info_policy.max_first_name_length
|
||||
});
|
||||
|
||||
//Last name
|
||||
// Last name
|
||||
var lastName = createFormGroup({
|
||||
target: target,
|
||||
label: "Last name",
|
||||
placeholder: "Your last name",
|
||||
label: tr("Last name"),
|
||||
placeholder: tr("Your last name"),
|
||||
type: "text",
|
||||
value: infos.lastName
|
||||
value: infos.lastName,
|
||||
maxLength: ServerConfig.conf.account_info_policy.max_last_name_length
|
||||
});
|
||||
|
||||
//Allow mails from Comunic
|
||||
var allowEmails = createFormGroup({
|
||||
target: target,
|
||||
type: "checkbox",
|
||||
label: "Allow Comunic to send you emails",
|
||||
label: tr("Allow Comunic to send you emails"),
|
||||
checked: infos.allow_comunic_mails
|
||||
});
|
||||
|
||||
@ -148,7 +150,7 @@ ComunicWeb.pages.settings.sections.general = {
|
||||
var publicPage = createFormGroup({
|
||||
target: target,
|
||||
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
|
||||
});
|
||||
|
||||
@ -177,7 +179,7 @@ ComunicWeb.pages.settings.sections.general = {
|
||||
var allowComments = createFormGroup({
|
||||
target: target,
|
||||
type: "checkbox",
|
||||
label: "Allow the comments on your page",
|
||||
label: tr("Allow comments on your page"),
|
||||
checked: infos.allow_comments
|
||||
});
|
||||
|
||||
@ -185,7 +187,7 @@ ComunicWeb.pages.settings.sections.general = {
|
||||
var allowPostsFromFriends = createFormGroup({
|
||||
target: target,
|
||||
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
|
||||
});
|
||||
|
||||
@ -193,14 +195,14 @@ ComunicWeb.pages.settings.sections.general = {
|
||||
var publicFriendsList = createFormGroup({
|
||||
target: target,
|
||||
type: "checkbox",
|
||||
label: "Make your friend list public",
|
||||
label: tr("Make your friend list public"),
|
||||
checked: infos.public_friends_list
|
||||
});
|
||||
|
||||
//Personnal website
|
||||
var personnalWebsite = createFormGroup({
|
||||
target: target,
|
||||
label: "Personnal website (optionnal)",
|
||||
label: tr("Personnal website (optionnal)"),
|
||||
type: "text",
|
||||
placeholder: "https://...",
|
||||
value: infos.personnal_website != "null" ? infos.personnal_website : ""
|
||||
@ -263,15 +265,15 @@ ComunicWeb.pages.settings.sections.general = {
|
||||
sendButton.onclick = function(){
|
||||
|
||||
//Check the given values
|
||||
if(!ComunicWeb.common.formChecker.checkInput(firstName, true))
|
||||
return notify("Please check your first name!", "danger");
|
||||
if(!ComunicWeb.common.formChecker.checkInput(firstName, true, ServerConfig.conf.account_info_policy.min_first_name_length))
|
||||
return notify(tr("Please check your first name!"), "danger");
|
||||
|
||||
if(!ComunicWeb.common.formChecker.checkInput(lastName, true))
|
||||
return notify("Please check your last name!", "danger");
|
||||
if(!ComunicWeb.common.formChecker.checkInput(lastName, true, ServerConfig.conf.account_info_policy.min_last_name_length))
|
||||
return notify(tr("Please check your last name!"), "danger");
|
||||
|
||||
if(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
|
||||
|
8
assets/js/typings/ServerConfig.d.ts
vendored
8
assets/js/typings/ServerConfig.d.ts
vendored
@ -33,6 +33,13 @@ declare interface ConversationPolicy {
|
||||
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 {
|
||||
terms_url: string,
|
||||
privacy_policy_url: string,
|
||||
@ -41,4 +48,5 @@ declare interface StaticServerConfig {
|
||||
password_policy: PasswordPolicy,
|
||||
data_conservation_policy: DataConservationPolicySettings,
|
||||
conversations_policy: ConversationPolicy,
|
||||
account_info_policy: AccountInformationPolicy,
|
||||
}
|
Loading…
Reference in New Issue
Block a user