|
function UsersDataXML() {
this.authenticateUser = UsersDataXML_authenticateUser;
this.save = UsersDataXML_save;
this.initialize = UsersDataXML_initialize;
this.autoSave = UsersDataXML_autoSave;
this.registerUser = UsersDataXML_registerUser;
this.findUser = UsersDataXML_findUser;
this.filePath = getUsersDataPath();
this.autoSaveInterval = getAutoSaveInterval();// In seconds.
this.identifier = "UsersStore";
}
/**
* Cheks user name and password combination.
* @return true if valid user, overvise false.
*/
function UsersDataXML_authenticateUser(userName, password) {
var usersStore = new SharedXML(this.identifier);
var xmlNode = usersStore.findNodeByName(userName);
if(xmlNode != null) {
var user = new UserInfo(xmlNode);
return user.checkPassword(password);
}
return false;
}
/**
* Searching for an existing user by nick.
* @param strNick user nick.
* @return Found user object or undefined, if not exists.
*/
function UsersDataXML_findUser(strNick) {
var usersStore = new SharedXML(this.identifier);
var xmlNode = usersStore.findNodeByName(strNick);
if(xmlNode != null)
{
var user = new UserInfo(xmlNode);
return user;
}
}
/**
* Saves data to disk.
*/
function UsersDataXML_save() {
var usersStore = new SharedXML(this.identifier);
usersStore.save(this.filePath);
}
/**
* Initial data load.
*/
function UsersDataXML_initialize() {
var usersStore = new SharedXML(this.identifier);
usersStore.load(this.filePath);
}
/**
* Checking for autosave timeout elapsed. If true, saves data.
*/
function UsersDataXML_autoSave() {
this.save();
}
/**
* Adds new user to store.
* @return New user id or -1 if already exists.
*/
function UsersDataXML_registerUser(nick, password, firstName,
lastName, email) {
var user = this.findUser(nick);
if(typeof(user) != "undefined") {
// User already exists.
return -1;
}
var usersStore = new SharedXML(this.identifier);
var xmlNode = usersStore.addNode();
var newUser = new UserInfo(xmlNode);
newUser.setUserNick(nick);
newUser.setPassword(password);
newUser.setFirstName(firstName);
newUser.setLastName(lastName);
newUser.setEmail(email);
var id = newUser.getUserID();
this.autoSave();
return id;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here