I take this sample Node.ACS project I've made and run it via Node.js command line to test run the sample login program. Everything went fine from the start until I got this error:
TypeError: Cannot set property 'uid' of undefined at login (/controllers/log_session.js:9:19) at callbacks (C:\Users\OpenovateLabsUser\AppData\Roaming\npm\node_modules\acs\node_modules\express\lib\router\index.js:162:37) at param (C:\Users\OpenovateLabsUser\AppData\Roaming\npm\node_modules\acs\node_modules\express\lib\router\index.js:136:11) at pass (C:\Users\OpenovateLabsUser\AppData\Roaming\npm\node_modules\acs\node_modules\express\lib\router\index.js:143:5) at Router._dispatch (C:\Users\OpenovateLabsUser\AppData\Roaming\npm\node_modules\acs\node_modules\express\lib\router\index.js:171:5) at Object.router (C:\Users\OpenovateLabsUser\AppData\Roaming\npm\node_modules\acs\node_modules\express\lib\router\index.js:33:10) at next (C:\Users\OpenovateLabsUser\AppData\Roaming\npm\node_modules\acs\node_modules\express\node_modules\connect\lib\proto.js:190:15) at Object.favicon [as handle] (C:\Users\OpenovateLabsUser\AppData\Roaming\npm\node_modules\acs\node_modules\express\node_modules\connect\lib\middleware\favicon.js:78:7) at next (C:\Users\OpenovateLabsUser\AppData\Roaming\npm\node_modules\acs\node_modules\express\node_modules\connect\lib\proto.js:190:15) at Object.logger (C:\Users\OpenovateLabsUser\AppData\Roaming\npm\node_modules\acs\node_modules\express\node_modules\connect\lib\middleware\logger.js:156:5)The error stops here:
function login(req, res) { var uid = req.body.uid; // --> This code can still read and obtained from the textfield. var pwd = req.body.pwd; var name = req.body.name; if((uid == 'Last') && (pwd == 'Ride')) { req.session.uid = uid; // --> However, this code does not recognized. same thing for the rest. req.session.pwd = pwd; req.session.name = name; res.redirect('/home/account'); console.log('REALNAME: ' + req.session.name); console.log('PASSWORD: ' + req.session.pwd); console.log('USERNAME: ' + req.session.uid); console.log('Login complete!'); } else { res.send(500, { error: 'Invalid account. Try again. ' + req.body.uid }); res.redirect('/home/account'); } }I check at index.ejs, the value seems valid I believed and I set the name for each <input> tag:
<body> <h2>Test Project 2 - Enter your Account:</h2> <form action='/home/login' method='post'> <div> Name: <input type='text' name='name'/> </div> <div> Username: <input type='text' name='uid'/> </div> <div> Password: <input type='password' name='pwd'/> </div> <div> <input type='submit' value='LOGIN'/> </div> </form> </body>Here's the config.json file where I set the path name and the correct functions from their respective Javascript file:
{ "routes": [ { "path": "/home", "callback": "application#index" }, { "path": "/home/account", "callback": "application#loadAccount" }, { "path": "/home/login", "method": "post", "callback": "log_session#login" }, { "path": "/home/logout", "callback": "log_session#logout" } ], "filters": [ { "path": "/home/account", "callback": "filter#validate" } ], "websockets": [ { "event": "", "callback": ""} ] }