X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=profile.js;h=5cdc399097b237e6fb99d5973a18e7967c83ebc5;hb=6c6339c91ef5bbc9f39384b3027930c9183fe225;hp=55d247c82f04cccf532333793cc3ea601d172f5e;hpb=47c7f1d2581b15024a61ac15f2c6b8741c15aa05;p=webchat%2FWebChat.git diff --git a/profile.js b/profile.js index 55d247c..5cdc399 100644 --- a/profile.js +++ b/profile.js @@ -196,15 +196,12 @@ function edit_postproc(req, res) var validator = new Validator(); if(validator.Validate(req.body,config.alias)) { - RenderMessage(validator.Message,req.session.items); + RenderMessage(res,validator.Message,req.session.items); return; } async.waterfall([ function(cb){ - if(req.body.updatepassword == false) - collection.UpdatAsync(req.body.name,req.body,null,cb); - else - collection.UpdatAsync(req.body.name,req.body,req.body.password,cb); + collection.UpdatAsync(req.body.name,req.body,cb); }, ],function(err,result){ if(err != null) @@ -252,6 +249,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 @@ -275,7 +274,7 @@ function ProfileCollection() this.AuthAsync = function(name,password,cb){ async.waterfall([ function(next){ - pool.query("SELECT password FROM list WHERE name_hash = ? and name = ?",[murmurhash.v3(name),name],next); + pool.query("SELECT password FROM profilelist WHERE name_hash = ? and name = ?",[murmurhash.v3(name),name],next); }, function(result,next){ if(result[0].password == md5_hex(password)) @@ -286,32 +285,30 @@ function ProfileCollection() ],cb); } this.GetAsync = function(name,cb){ - pool.query("SELECT * FROM list WHERE name_hash = ? and name = ?",[murmurhash.v3(name),name],cb); + pool.query("SELECT * FROM profilelist WHERE name_hash = ? and name = ?",[murmurhash.v3(name),name],cb); } this.AddAsync = function(data,cb){ - var item = GetItem(data); - pool.query("INSERT INTO list SET ?",[item],cb); + var item = GetItem(data);; + pool.query("INSERT INTO profilelist SET ?",[item],cb); } - this.UpdatAsync = function(name,data,newpassword,cb){ + this.UpdatAsync = function(name,data,cb){ var item = GetItem(data); - if(newpassword != null) - item.password = md5_hex(newpassword); - pool.query("UPDATE list SET ? WHERE name = ?",[item,name],cb); + pool.query("UPDATE profilelist SET ? WHERE name = ?",[item,name],cb); } this.ClearAsync = function(cb){ - pool.query("TRUNCATE TABLE list",null,cb); + pool.query("TRUNCATE TABLE profilelist",null,cb); } this.RemoveRangeAsync = function(names,cb){ - pool.query("DELETE FROM list WHERE name IN (?)",[names],cb); + pool.query("DELETE FROM profilelist WHERE name IN (?)",[names],cb); } this.RemoveAsync = function(name,cb){ - pool.query("DELETE FROM list WHERE name_hash = ? and name = ?",[murmurhash.v3(name),name],cb); + pool.query("DELETE FROM profilelist WHERE name_hash = ? and name = ?",[murmurhash.v3(name),name],cb); } this.FindByNameAsync = function(pattern,start,count,cb){ - pool.query("SELECT * FROM list WHERE name LIKE ? LIMIT ?,?",[pattern+"%",start,count],cb); + pool.query("SELECT * FROM profilelist WHERE name LIKE ? LIMIT ?,?",[pattern+"%",start,count],cb); } this.ToArrayAsync = function(start,count,cb){ - pool.query("SELECT name,lastmodified FROM list LIMIT ?,?",[start,count],cb); + pool.query("SELECT name,lastmodified FROM profilelist LIMIT ?,?",[start,count],cb); } var crypto = require("crypto"); @@ -322,7 +319,7 @@ function ProfileCollection() return md5.digest('hex'); } - function GetItem(data) + function GetItem(data,newpw) { var item = { name_hash:murmurhash.v3(data.name), @@ -330,10 +327,18 @@ function ProfileCollection() }; for(var key in config.alias) { - if(key == "password") - item[key] = md5_hex(data[key]); - else - item[key] = data[key]; + if(typeof(config.alias[key].nodefinetable) != "undefined" && + config.alias[key].nodefinetable) + continue; + if(config.alias[key].visible_edit) + { + if(config.alias[key].type == "password") + 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; } @@ -352,13 +357,23 @@ function Validator() // @alias バリテーションを行う要素のリスト this.Validate = function(body,alias){ var result = false; - this.Message = ""; + this.Message = new Array(); for(var key in alias) { - var message = IsValidate(body[key],alias[key].type,alias[key].rule); + if(alias[key].visible_edit == false) + continue; + var message; + if(typeof(alias[key].isnotempty) != "undefined" && + alias[key].isnotempty && body[key] == "") + 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) { - this.Message += "

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

\n"; + this.Message.push(alias[key].name + ":" + message); result = true; } } @@ -374,10 +389,6 @@ function Validator() var result = null; - if(typeof(rule) != "undefined" && typeof(rule.isnotempty) != "undefined" - && rule.isnotempty && data == "") - return resource.is_not_empty; - switch(type) { case "text": @@ -401,4 +412,4 @@ function Validator() return result; } -} \ No newline at end of file +}