Change behavior for MySQL fail

This commit is contained in:
calzoneman 2013-02-16 11:23:51 -06:00
parent e902a8074a
commit 728f23a05b
4 changed files with 16 additions and 8 deletions

Binary file not shown.

Binary file not shown.

View file

@ -15,7 +15,8 @@ exports.isRegistered = function(name) {
db.connectSync(Config.MYSQL_SERVER, Config.MYSQL_USER,
Config.MYSQL_PASSWORD, Config.MYSQL_DB);
if(!db.connectedSync()) {
throw "[](/abchaos) MySQL Connection Failed";
console.log("MySQL Connection Failed");
return true;
}
var query = 'SELECT * FROM registrations WHERE uname="{}"'
.replace(/\{\}/, name);
@ -44,7 +45,8 @@ exports.register = function(name, sha256) {
db.connectSync(Config.MYSQL_SERVER, Config.MYSQL_USER,
Config.MYSQL_PASSWORD, Config.MYSQL_DB);
if(!db.connectedSync()) {
throw "[](/abchaos) MySQL Connection Failed";
console.log("MySQL Connection Failed");
return false;
}
var query = 'INSERT INTO registrations VALUES (NULL, "{1}", "{2}", 0)'
.replace(/\{1\}/, name)
@ -60,7 +62,8 @@ exports.login = function(name, sha256) {
db.connectSync(Config.MYSQL_SERVER, Config.MYSQL_USER,
Config.MYSQL_PASSWORD, Config.MYSQL_DB);
if(!db.connectedSync()) {
throw "[](/abchaos) MySQL Connection Failed";
console.log("MySQL Connection Failed");
return false;
}
var query = 'SELECT * FROM registrations WHERE uname="{1}" AND pw="{2}"'
.replace(/\{1\}/, name)

View file

@ -35,7 +35,8 @@ Channel.prototype.loadMysql = function() {
db.connectSync(Config.MYSQL_SERVER, Config.MYSQL_USER,
Config.MYSQL_PASSWORD, Config.MYSQL_DB);
if(!db.connectedSync()) {
throw "[](/abchaos) MySQL Connection Failed";
console.log("MySQL Connection Failed");
return false;
}
// Check if channel exists
var query = 'SELECT * FROM channels WHERE name="{}"'
@ -67,7 +68,8 @@ Channel.prototype.createTables = function() {
db.connectSync(Config.MYSQL_SERVER, Config.MYSQL_USER,
Config.MYSQL_PASSWORD, Config.MYSQL_DB);
if(!db.connectedSync()) {
throw "[](/abchaos) MySQL Connection Failed";
console.log("MySQL Connection Failed");
return false;
}
// Create library table
var query= "CREATE TABLE `chan_{}_library` \
@ -107,7 +109,8 @@ Channel.prototype.getRank = function(name) {
db.connectSync(Config.MYSQL_SERVER, Config.MYSQL_USER,
Config.MYSQL_PASSWORD, Config.MYSQL_DB);
if(!db.connectedSync()) {
throw "[](/abchaos) MySQL Connection Failed";
console.log("MySQL Connection Failed");
return Rank.Guest;
}
var query = 'SELECT * FROM chan_{1}_ranks WHERE name="{2}"'
.replace(/\{1\}/, this.name)
@ -130,7 +133,8 @@ Channel.prototype.saveRank = function(user) {
db.connectSync(Config.MYSQL_SERVER, Config.MYSQL_USER,
Config.MYSQL_PASSWORD, Config.MYSQL_DB);
if(!db.connectedSync()) {
throw "[](/abchaos) MySQL Connection Failed";
console.log("MySQL Connection Failed");
return false;
}
var query = 'UPDATE chan_{1}_ranks SET rank={2} WHERE name={3}'
.replace(/\{1\}/, this.name)
@ -159,7 +163,8 @@ Channel.prototype.addToLibrary = function(media) {
db.connectSync(Config.MYSQL_SERVER, Config.MYSQL_USER,
Config.MYSQL_PASSWORD, Config.MYSQL_DB);
if(!db.connectedSync()) {
throw "[](/abchaos) MySQL Connection Failed";
console.log("MySQL Connection Failed");
return false;
}
var query = 'INSERT INTO chan_{1}_library VALUES ("{2}", "{3}", {4}, "{5}", "{6}")'
.replace(/\{1\}/, this.name)