Thursday 27 April 2017

issues with genarate password by server and sms to user

I use passport to authenticate and for sign up when I use html form there is no problem but when I try to generate a random number and put the value in passport method although the user create in data base but doesn't work!!? here is my code:

router.post("/register", function (req, res) {
    var password = Math.floor((Math.random() * 100000) + 1).toString();
    User.findOne().sort({
        field: 'asc',
        _id: -1
    }).limit(1).exec(function (err, lastQ) {
        if (err) {
            console.log(err);
        } else {
            console.log(lastQ);
            var customersNo = Number(lastQ.customerNo) + 1;
            User.register(new User({
                username: username,
                customerNo: customersNo,
                customerName: req.body.customerName,
                customerAdd: req.body.customerAdd,
                customerPhone: req.body.customerPhone
            }), req.body.password, function (err, user) { ....//here works!

in part above everything OK but if change req.body.password with my variable 'password' doesn't work:

router.post("/register", function (req, res) {
    var password = Math.floor((Math.random() * 100000) + 1).toString();
    User.findOne().sort({
        field: 'asc',
        _id: -1
    }).limit(1).exec(function (err, lastQ) {
        if (err) {
            console.log(err);
        } else {
            console.log(lastQ);
            var customersNo = Number(lastQ.customerNo) + 1;
            User.register(new User({
                username: username,
                customerNo: customersNo,
                customerName: req.body.customerName,
                customerAdd: req.body.customerAdd,
                customerPhone: req.body.customerPhone
            }), password, function (err, user) { ....//here doesn't wotk!



via milad fahimi

No comments:

Post a Comment