问一个提交表单的问题……
发布于 8个月前 作者 yohnz 368 次浏览

最近在看这个:https://github.com/nswbmw/N-blog/wiki/%E7%AC%AC1%E7%AB%A0–%E4%B8%80%E4%B8%AA%E7%AE%80%E5%8D%95%E7%9A%84%E5%8D%9A%E5%AE%A2, 然后,照着写了下,发现注册提交表单时,要提交好久,且最终会失败。但是没有报错,求指点迷津。。。

app.post('/reg',function(req,res){
        var name=req.body.name,
            password=req.body.password,
            password_re=req.body['password-repeat'];
        //校验两次输入的密码是否一致
        if(password!=password_re){
            req.flash('error','两次输入的密码不一致!');
            return res.redirect('/reg');    //返回注册页
        }
        //生成密码的md5值 
        var md5=crypto.createHash('md5'),
            password=md5.update(req.body.password).digest('hex');
        var newUser=new User({
            name:name,
            password:password,
            email:req.body.email
        });
    //检查用户名是否已存在
    User.get(newUser.name,function(err,user){
        if(user){
            req.flash('error','用户已存在'); 
            return res.redirect('/reg');    //返回注册页
        }
        //如果不存在则是新增用户
        newUser.save(function(err,user){
            if(err){
                req.flash("error",err);
                return res.redirect('/reg');    //注册失败返回主页
            }
            req.session.user = user;    //用户信息存入session
            req.flash('success',"注册成功!");
            return res.redirect('/');  注册成功返回主页
        });         
    });
res.end();
});
3 回复

问题不够详细啊,这样叫大家怎么解答

哦,代码略多: https://github.com/nswbmw/N-blog/wiki/第1章–一个简单的博客 数据库用的是mongodb: 2014-06-05T16:04:35.449+0800 [initandlisten] connection accepted from 127.0.0.1: 62375 #3 (3 connections now open) 2014-06-05T16:04:35.452+0800 [initandlisten] connection accepted from 127.0.0.1: 62376 #4 (4 connections now open) 2014-06-05T16:04:35.453+0800 [initandlisten] connection accepted from 127.0.0.1: 62377 #5 (5 connections now open) 2014-06-05T16:09:26.521+0800 [clientcursormon] mem (MB) res:56 virt:468 2014-06-05T16:09:26.523+0800 [clientcursormon] mapped (incl journal view):320 2014-06-05T16:09:26.527+0800 [clientcursormon] connections:5 2014-06-05T16:14:26.620+0800 [clientcursormon] mem (MB) res:56 virt:468 2014-06-05T16:14:26.620+0800 [clientcursormon] mapped (incl journal view):320 2014-06-05T16:14:26.621+0800 [clientcursormon] connections:5 2014-06-05T16:19:26.724+0800 [clientcursormon] mem (MB) res:56 virt:468 2014-06-05T16:19:26.724+0800 [clientcursormon] mapped (incl journal view):320 2014-06-05T16:19:26.725+0800 [clientcursormon] connections:5

已找到原因,谢谢

回到顶部