Nodejs User Registration/Login code (MySQL) written using Coffeescript

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.