Fix duplicate login bug

Fixes Issue #1
This commit is contained in:
calzoneman 2013-03-17 09:39:22 -05:00
parent bee58b421d
commit 92d73026be
2 changed files with 24 additions and 0 deletions

View file

@ -201,6 +201,19 @@ Channel.prototype.searchLibrary = function(query) {
// Called when a new user enters the channel
Channel.prototype.userJoin = function(user) {
// Prevent duplicate login
if(user.name != "") {
for(var i = 0; i < this.users.length; i++) {
if(this.users[i].name == user.name) {
user.name = "";
user.loggedIn = false;
user.socket.emit('login', {
success: false,
error: "The username " + user.name + " is already in use on this channel"
});
}
}
}
// If the channel is empty and isn't registered, the first person
// gets ownership of the channel (temporarily)
if(this.users.length == 0 && !this.registered) {

11
user.js
View file

@ -226,6 +226,17 @@ User.prototype.handleAdm = function(data) {
// Attempt to login
User.prototype.login = function(name, sha256) {
if(this.channel != null && name != "") {
for(var i = 0; i < this.channel.users.length; i++) {
if(this.channel.users[i].name == name) {
this.socket.emit('login', {
success: false,
error: "The username " + name + " is already in use on this channel"
});
return false;
}
}
}
// No password => try guest login
if(sha256 == "") {
// Sorry bud, can't take that name