mirror of
				https://github.com/pierre42100/ComunicWeb
				synced 2025-10-30 17:54:59 +00:00 
			
		
		
		
	Perform a request over the API to fetch security information
This commit is contained in:
		| @@ -2,4 +2,29 @@ | ||||
|  * Security settings section | ||||
|  * | ||||
|  * @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 | ||||
|  */ | ||||
| @@ -43,6 +43,20 @@ ComunicWeb.components.settings.interface = { | ||||
| 			directory: directory | ||||
| 		}; | ||||
| 		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); | ||||
| 	}, | ||||
|  | ||||
| } | ||||
| @@ -41,7 +41,84 @@ ComunicWeb.pages.settings.sections.security = { | ||||
| 			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 | ||||
| 				 | ||||
| 			}); | ||||
| 		}; | ||||
| 	}, | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Pierre
					Pierre