Perform a request over the API to fetch security information

This commit is contained in:
Pierre 2018-04-18 18:33:18 +02:00
parent 7726145a63
commit 9b32ee19e8
3 changed files with 118 additions and 2 deletions

View File

@ -2,4 +2,29 @@
* Security settings section * Security settings section
* *
* @author Pierre HUBERT * @author Pierre HUBERT
*/
/**
* Prompt user password box
*/
.box-security-settings .prompt-user-password h4,
.box-security-settings .prompt-user-password p {
text-align: center;
}
.box-security-settings .prompt-user-password label {
display: none;
}
.box-security-settings .prompt-user-password .submit-form {
width: 100px;
margin: auto;
display: block;
}
/**
* Global box rules
*/ */

View File

@ -43,6 +43,20 @@ ComunicWeb.components.settings.interface = {
directory: directory directory: directory
}; };
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback); ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
} },
/**
* Get security account settings
*
* @param {string} password The password of the user
* @param {function} callback Callback function
*/
getSecurity: function(password, callback){
var apiURI = "settings/get_security";
var params = {
password: password
};
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
},
} }

View File

@ -41,7 +41,84 @@ ComunicWeb.pages.settings.sections.security = {
class: "box-body" class: "box-body"
}); });
//Append the form to query user password
this._append_form_prompt_user_password(boxBody);
}, },
/**
* Append a form to prompt user password
*
* @param {HMTLElement} target The target for the form
*/
_append_form_prompt_user_password: function(target){
//Create form contener (allows easier manipulations then)
var formContener = createElem2({
appendTo: target,
type: "div",
class: "prompt-user-password"
});
//Add title
createElem2({
appendTo: formContener,
type: "h4",
innerHTML: "Password required"
});
//Add explanation
createElem2({
appendTo: formContener,
type: "p",
innerHTML: "In order to protect these sensitive information, your password is required to access this page."
});
//User password form
var passwordInput = createFormGroup({
target: formContener,
label: "Your password",
placeholder: "Your password",
type: "password"
});
//Add submit button
var sendButton = createElem2({
appendTo: formContener,
type: "div",
class: "btn btn-primary submit-form",
innerHTML: "Submit"
});
//Make submit button lives
sendButton.onclick = function(){
//Check the validity of the input
if(!ComunicWeb.common.formChecker.checkInput(passwordInput, true)){
notify("Please input your password !", "danger");
return;
}
//Hide send button
sendButton.style.visibility = "hide";
//Perform a request over the server to fetch security settings
ComunicWeb.components.settings.interface.getSecurity(passwordInput.value, function(result){
//Show send button
sendButton.style.visibility = "visible";
//Check for errors
if(result.error){
notify("An error occured while retrieving security settings! Please check your password...", "danger");
return;
}
//Remove password input form
emptyElem(formContener);
//Show security information update form
});
};
},
} }