Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

169
Vistas
issues with generate 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 work!
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

What error it gives? By viewing I figured out you might missing on the scope of this.

over 4 years ago · Santiago Trujillo Denunciar

0

my assumption, that your password has not been generated yet is already used, maybe you can handle it with the async function,

or to be sure, try console the password, whether the password has been generated or not.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda