0
I’m having trouble getting it working or checking if the user already exists dynamically.
Basically I want that when typing the user name says whether or not I am using the nodejs with express and mysql
code controller/login
const usermameverica = async (connection, req, res) => {
// req.body.password = await hashpass(req.body.password)
const user= await User.verificauser(connection, req.body.user.username)
if(user){
return res.render('login/create',{error: true})
}else{
return res.render('login/create',{error: false})
}
}
route login
const express = require('express')
const router = express.Router()
const controllerLogin = require('../controllers/login')
const controllernews = require('../controllers/newscontroler')
const connection = require('../Config/database')
const controllerAdmin = require('../controllers/Administration')
router.get('/login', controllerLogin.login)
router.post('/login', controllerLogin.authenticateUser.bind(null, connection))
router.get('/createUser', controllerLogin.FormUser)
router.post('/createUser', controllerLogin.createUser.bind(null, connection))
router.post('/usermameverica', controllerLogin.usermameverica.bind(null, connection))
router.get('/logout', controllerLogin.logoutUser)
router.get('/news', controllernews.news)
//
/*************************/
module.exports = app => app.use('/', router)
models/user
const verificauser = (connection, username) => {
return new Promise ((resolve, reject) => {
connection.query(`SELECT * FROM user WHERE username = '${username}' `, (err, result) =>{
if(err){
reject(err)
}else{
if(result.length>0){
resolve(false)
}
else{
resolve(true)
}
}
})
})
}
validator
rules : {
username : {
minlength : 3,
required : true,
remote : {
url : '../controllers/login',
message : 'Utilizador ja existe',
data: JSON.stringify('Username'),
type : 'POST',
contentType: 'application/json',
},
}
what’s the matter, some mistake happens?
– Ricardo Pontual
no error simply does not show which user exists or not
– Rsrd
checked if you are mounting the command
sql
correctly? if you pick up the commandsql
that was generated and run directly in the bank works?– Ricardo Pontual
in the sql part works I think the problem is in jquery
– Rsrd
You’ve seen what the service returns?
– Sorack
already solved topical problem can be closed
– Rsrd