X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;ds=sidebyside;f=profile.js;h=20a069b251d8ca5552c1a47e34023c388f38923d;hb=1be6ea0fbb0fd661c1d589add81b3423c1eb9ecc;hp=5dfa9039da8d7a63630c8d6d226ff9940cecad71;hpb=7f49353b9dc73cf56467c9bf1e69fb021e8d7df3;p=webchat%2FWebChat.git diff --git a/profile.js b/profile.js index 5dfa903..20a069b 100644 --- a/profile.js +++ b/profile.js @@ -194,9 +194,10 @@ function edit_postproc(req, res) return; }else if(typeof(req.body.edit) != "undefined"){ var validator = new Validator(); - if(validator.Validate(req.body,config.alias)) + var result = validator.Validate(req.body,config.alias,true); + if(result.length > 0) { - RenderMessage(res,validator.Message,req.session.items); + RenderMessage(res,result,req.session.items); return; } async.waterfall([ @@ -218,9 +219,10 @@ function registor_postproc(req, res) { if(typeof(req.body.registor) != "undefined"){ var validator = new Validator(); - if(validator.Validate(req.body,config.alias)) + var result = validator.Validate(req.body,config.alias,false); + if(result.length > 0) { - RenderMessage(res,validator.Message,req.session.items); + RenderMessage(res,result,req.session.items); return; } async.waterfall([ @@ -249,6 +251,8 @@ function registor_proc(req, res) function RenderMessage(res,msg,info) { + if(typeof(msg) == "string") + msg = new Array(msg); if(typeof(info) == "undefined" || typeof(info.admin) == "undefined") res.render("profile/message",{message:msg,admin:false}); else @@ -267,7 +271,7 @@ function ProfileCollection() user : config.db_user, password : config.db_password, port : config.db_port, - database : "webchat", + database : config.db_name, }); this.AuthAsync = function(name,password,cb){ async.waterfall([ @@ -291,7 +295,7 @@ function ProfileCollection() } this.UpdatAsync = function(name,data,cb){ var item = GetItem(data); - pool.query("UPDATE profilelist SET ? WHERE name = ?",[item,name],cb); + pool.query("UPDATE profilelist SET ? WHERE name_hash = ? and name = ?",[item,murmurhash.v3(name),name],cb); } this.ClearAsync = function(cb){ pool.query("TRUNCATE TABLE profilelist",null,cb); @@ -331,11 +335,18 @@ function ProfileCollection() if(config.alias[key].visible_edit) { if(config.alias[key].type == "password") - item[key] = md5_hex(data[key]); + { + if(data[key] != "") + item[key] = md5_hex(data[key]); + } else if(data[key] == "" && typeof(config.alias[key].defaultvalue) != "undefined") + { item[key] = config.alias[key].defaultvalue; + } else + { item[key] = data[key]; + } } } return item; @@ -353,9 +364,9 @@ function Validator() // // @body バリテーションの対象となる連想配列 // @alias バリテーションを行う要素のリスト - this.Validate = function(body,alias){ - var result = false; - this.Message = ""; + // @editflag 編集時なら真 + this.Validate = function(body,alias,editflag){ + var result = new Array(); for(var key in alias) { if(alias[key].visible_edit == false) @@ -364,24 +375,20 @@ function Validator() if(typeof(alias[key].isnotempty) != "undefined" && alias[key].isnotempty && body[key] == "") message = resource.is_not_empty; + else if(typeof(alias[key].isnotemptyonregistor) != "undefined" && + alias[key].isnotemptyonregistor && body[key] == "" && + !editflag) + message = resource.is_not_empty; else if(typeof(alias[key].mustmatchitem) != "undefined" && body[key] != body[alias[key].mustmatchitem]) message = util.format(resource.must_match_item,alias[alias[key].mustmatchitem].name); else message = IsValidate(body[key],alias[key].type,alias[key].rule); if(message != null) - { - if(alias[key].name == "") - this.Message += "

" + message + "

\n"; - else - this.Message += "

" + alias[key].name + ":" + message + "

\n"; - result = true; - } + result.push(alias[key].name + ":" + message); } return result; } - // バリテーション時にエラーがあった場合、メッセージが記録される - this.Message = ""; function IsValidate(data,type,rule){ if(typeof(data) == "undefined") throw "data is undefined";