Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version
Go to top

Writing ASP Chat using JavaScript and XML (Part 4)

, 21 Jan 2004
The last part of the ASP chat series. This article explains how to provide a chat with multiple rooms.
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.

License

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

Share

About the Author

Alexander Fedorenko
Web Developer
Ukraine Ukraine
Alexander Fedorenko is a professional C++ developer since 1996. He completed many custom and shareware projects. One of the successful projects is DevPlanner - tool for personal planning and time management.

| Advertise | Privacy | Mobile
Web01 | 2.8.140905.1 | Last Updated 22 Jan 2004
Article Copyright 2004 by Alexander Fedorenko
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid