2018-04-11 08:52:06 +00:00
|
|
|
/**
|
|
|
|
* Account interface
|
|
|
|
*
|
|
|
|
* @author Pierre HUBERT
|
|
|
|
*/
|
|
|
|
|
|
|
|
ComunicWeb.components.account.interface = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a request on the server to create an account
|
|
|
|
*
|
|
|
|
* @param {string} firstName The first name of the user
|
|
|
|
* @param {string} lastName The last name of the user
|
|
|
|
* @param {email} emailAddress The email adress of the user
|
|
|
|
* @param {password} password The password of the user
|
|
|
|
* @param {callback} callback The callback function
|
|
|
|
*/
|
|
|
|
createAccount: function(firstName, lastName, emailAddress, password, callback){
|
|
|
|
|
|
|
|
//Make an API request
|
|
|
|
var apiURI = "account/create";
|
|
|
|
var params = {
|
|
|
|
"firstName": firstName,
|
|
|
|
"lastName": lastName,
|
|
|
|
"emailAddress": emailAddress,
|
|
|
|
"password": password
|
|
|
|
};
|
|
|
|
|
|
|
|
//Perform an API request
|
|
|
|
ComunicWeb.common.api.makeAPIrequest(apiURI, params, false, callback);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2018-05-21 08:40:44 +00:00
|
|
|
/**
|
|
|
|
* Check whether an email address is linked to an account or not
|
|
|
|
*
|
|
|
|
* @param {String} email The email address to check
|
|
|
|
* @param {function} callback
|
|
|
|
*/
|
|
|
|
existsMail: function(email, callback){
|
|
|
|
var apiURI = "account/exists_email";
|
|
|
|
var params = {
|
|
|
|
email: email
|
|
|
|
};
|
|
|
|
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
|
|
|
|
},
|
|
|
|
|
2018-05-22 20:48:48 +00:00
|
|
|
/**
|
|
|
|
* Check whether the security questions have been set for an account
|
|
|
|
* with an email address or not
|
|
|
|
*
|
|
|
|
* @param {String} email The email address of the account
|
|
|
|
* @param {function} callback
|
|
|
|
*/
|
|
|
|
checkSecurityQuestionsExistence: function(email, callback){
|
|
|
|
var apiURI = "account/has_security_questions";
|
|
|
|
var params = {
|
|
|
|
email: email
|
|
|
|
};
|
|
|
|
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
|
|
|
|
},
|
|
|
|
|
2018-05-23 19:41:02 +00:00
|
|
|
/**
|
|
|
|
* Given an email address, returns the security questions of a user
|
|
|
|
*
|
|
|
|
* @param {String} email The email address of the account
|
|
|
|
* @param {function} callback
|
|
|
|
*/
|
|
|
|
getSecurityQuestions: function(email, callback){
|
|
|
|
var apiURI = "account/get_security_questions";
|
|
|
|
var params = {
|
|
|
|
email: email
|
|
|
|
};
|
|
|
|
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
|
|
|
|
},
|
|
|
|
|
2018-05-26 05:30:02 +00:00
|
|
|
/**
|
|
|
|
* Get passowrd reset token using security answer
|
|
|
|
*
|
|
|
|
* @param {String} email The email address of the account
|
|
|
|
* @param {Array} answers The answers to the security questions
|
|
|
|
* @param {Function} callback
|
|
|
|
*/
|
|
|
|
resetPasswordWithSecurityAnswers: function(email, answers, callback){
|
|
|
|
|
|
|
|
//Prepare answers
|
|
|
|
answersText = "";
|
|
|
|
answers.forEach(function(answer){
|
|
|
|
|
|
|
|
if(answersText != "")
|
|
|
|
answersText += "&";
|
|
|
|
|
|
|
|
answersText += encodeURIComponent(answer);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
//Perform the request
|
|
|
|
var apiURI = "account/check_security_answers";
|
|
|
|
var params = {
|
|
|
|
email: email,
|
|
|
|
answers: answersText
|
|
|
|
};
|
|
|
|
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2018-05-26 13:50:33 +00:00
|
|
|
/**
|
|
|
|
* Check the validity of a reset password token
|
|
|
|
*
|
|
|
|
* @param {String} token The token to check
|
|
|
|
* @param {Function} callback
|
|
|
|
*/
|
|
|
|
checkPasswordResetToken: function(token, callback){
|
|
|
|
var apiURI = "account/check_password_reset_token";
|
|
|
|
var params = {
|
|
|
|
token: token
|
|
|
|
};
|
|
|
|
ComunicWeb.common.api.makeAPIrequest(apiURI, params, false, callback);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset user password
|
|
|
|
*
|
|
|
|
* @param {String} token The token to check
|
|
|
|
* @param {String} passwd The new password for the user
|
|
|
|
* @param {Function} callback
|
|
|
|
*/
|
|
|
|
resetUserPassword: function(token, passwd, callback){
|
|
|
|
var apiURI = "account/reset_user_passwd";
|
|
|
|
var params = {
|
|
|
|
token: token,
|
|
|
|
password: passwd
|
|
|
|
};
|
|
|
|
ComunicWeb.common.api.makeAPIrequest(apiURI, params, false, callback);
|
|
|
|
},
|
2018-05-26 05:30:02 +00:00
|
|
|
|
2018-05-13 14:52:19 +00:00
|
|
|
/**
|
|
|
|
* Request the export of all the data of the user
|
|
|
|
*
|
|
|
|
* @param {String} password The password of the user
|
|
|
|
* @param {function} callback
|
|
|
|
*/
|
|
|
|
exportData: function(password, callback){
|
|
|
|
var apiURI = "account/export_data";
|
|
|
|
var params = {
|
|
|
|
password: password
|
|
|
|
};
|
|
|
|
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
|
|
|
|
},
|
|
|
|
|
2018-05-09 12:57:46 +00:00
|
|
|
/**
|
|
|
|
* Request the deletion of the account
|
|
|
|
*
|
|
|
|
* @param {string} password The password of the account
|
|
|
|
* @param {function} callback
|
|
|
|
*/
|
|
|
|
deleteAccount: function(password, callback){
|
|
|
|
var apiURI = "account/delete";
|
|
|
|
var params = {
|
|
|
|
password: password
|
|
|
|
};
|
|
|
|
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
|
|
|
|
},
|
|
|
|
|
2018-04-11 08:52:06 +00:00
|
|
|
}
|