Record it for later use
Settings = Require '. /.. /settings.js ' Exports.register = (req, res), nick_name = req.body.nick_name email = Req.body.email Password = req.b Ody.password # config Variable table_name = ' user_info ' database = Settings.mysql.database # Gets the current time Dateobj = new Date () year = Dateobj.getfullyear () month = Dateobj.getmonth () + 1 day = Dateobj.getdate () hour = dateobj.gethours () min = dateobj. Getminutes () sec = Dateobj.getseconds () console.log month.length date_str = year + '-' + month + '-' + day + ' + hour + ': ' + min + ': ' + sec #console. Log date_str # Select the database used Mysqldb.query (' use ' + databases) # To determine the mailbox, register sql = "Select * FROM "+ table_name +" where email = ' "+ email +" ' "Console.log SQL Mysqldb.query (SQL, (err, data) and if (err Return Res.jsonp ({"Status":-1, "message": "Database Error"}) else if (Data.length > 0) return Res.jsonp ({"s Tatus ": -2," "Message": "Mailbox already exists"}) Else sql = "SELECT * FROM" + table_name + "where Nick_name = '" + nick_name + "'" Mysqldb.query (SQL, (err, data), if (Data.length > 0) return Res.jsonp ({"Status": -3, "message": "Nickname already exists"}) Else Mysqldb.query (' INSERT into ' + table_name + ' SET nick_name =?, email =?, CTime =?, Password =? ', [Nick_name, email, date_str, password]) return Res.json P ({"status": 0, "message": "Registration Succeeded"}))) Exports.login = (req, res)-e-mail = req.body.email Password = req.body . Password # config variable table_name = ' user_info ' database = Settings.mysql.database # Select the databases used Mysqldb.query (' use ' + Databa SE) # Determine mailbox, register SQL = "SELECT * FROM" + table_name + "where email = '" + email + "'" Console.log SQL Mysqldb.query (s QL, (err, data), if (err) return Res.jsonp ({"Status":-1, "message": "Database Error"}) else if (data.length = = 0) return Res.jsonp ({"Status": -2, "message": "User does not exist"}) else if (Data[0].password = = password) r Eturn Res.jsonp ({"Status": 0," "Message": "Login Successful"}) else return Res.jsonp ({"Status": -3, "message": "Username or password Error"}))
Nodejs User Registration/Login code (MySQL) written using Coffeescript