Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

173
Visualizações
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 Respostas
Responde à pergunta

0

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

over 4 years ago · Santiago Trujillo Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda