Sunday 28 May 2017

pass the credentials of user to all views node.js

I'm trying to build an android application using node.js web services,the first interface allow the user to connect to a host using ip address,login and password, so he can get all the databases,i want to save the object credentials to use in all other routes,i tried express-session but it didnt worked. Any solution?

app.post('/connect',function(req,res){
    sess=req.session;
    sess.user=req.body.user;
    sess.password=req.body.password;
    sess.server=req.body.server;
    sess.database=req.body.database;
    console.log(sess)
    user = req.body.user;
    password = req.body.password;
    server = req.body.server;
    database = req.body.database;

    var config = {
        user: user,
        password: password,
        server: server,
        database: database
    };



    // connect to your database
    sql.connect(config, function (err) {

        if (err)  {res.json({success: false, message: "error connexion to SQL Server"});
            sql.close()}
        else{

            res.json({success: true, message: "connexion established to SQL Server"});

            sql.close();
        }
    });
});



via Laamiri Oussema

No comments:

Post a Comment