Node.js realize Login Register function

Login using Node.js + registration function Navicat for mysql to achieve

There exists in the database "user_id, user_name, password, user_img, user_number" fields, wherein "user_id, user_img, user_number" nullable

// Register 
app.all ( '/ XCDoor / RESET', (REQ, RES) => {
     // account number and password is not empty 
    IF (req.query.user_name! == '' req.query.password &&! = = '' ) { 
    // database to find the user name of the user name distal pass over conn.query (
"SELECT * WHERE USER_NAME user_info` from` = ' "+ req.query.user_name +"' ", (E, R & lt) => { // is 0 for a user not found IF (r.length == 0 ) {
          // insert a record into the database, stored in the front end pass over the user name and password, the remainder may be an empty field to '' represents conn.query (
"the INSERT the INTO` user_info` the VALUES ( '', ' "+ req.query.user_name +"', ' "+ req.query.password +"', '', '') ")
          // returns to the front end "successfully registered" conn.query (
"SELECT * WHERE USER_NAME user_info` from` = ' "+ req.query.user_name +"' ", (E, R & lt) => res.json ( new new the Result ({MSG: '! registration success' , Data: R & lt} ))) } the else { // otherwise found user information
          // returns to the front end, "user name"
       conn.query ( "SELECT * WHERE USER_NAME user_info` from` = ' "+ req.query.user_name +"' ", (E, R & lt) => res.json ( new new the Result ({MSG: 'username exists!' , Data: R & lt}))) } }) } the else {
     // returned to the front end "user name or password is not blank " conn.query (
" SELECT * WHERE USER_NAME user_info` from `= '" + req.query.user_name + "'",(E, R & lt) => res.json ( new new the Result ({MSG: 'user name or password is not blank!',data:r}))) } })
// Log 
app.all ( '/ XCDoor / Login', (REQ, RES) => { 
  // pass over the front end determines whether the value is null, if empty, prompt "the user name or password is not blank"
IF ( == req.query.user_name '' || req.query.password == '' ) { conn.query ( "SELECT * WHERE USER_NAME user_info` from` = ' "+ req.query.user_name +"' ", ( E, R & lt) => res.json ( new new the Result ({MSG: '! user name or password is not blank' }))) }
  // find the user name in the database according to the user name distal pass over conn.query (
"SELECT * WHERE USER_NAME user_info` from` = ' "+ req.query.user_name +"' ", (E, R & lt) => { // is 0 for a user not found IF (r.length == 0 ) { conn.query("SELECT * WHERE USER_NAME user_info` from` = ' "+ req.query.user_name +"' ", (E, R & lt) => res.json ( new new the Result ({MSG: 'you entered is not registered account!' } ))) } the else {
       // pass over the front end determines the user name and password are found in the database consistent
iF (R & lt req.query.user_name == [0] == R & lt .user_name && req.query.password [0 ] .password) {
          // return to the same front end, "Login successful" conn.query (
"SELECT * WHERE USER_NAME user_info` from` = ' "+ req.query.user_name +"' ", (E, R & lt) => res.json ( new new the Result ({msg: 'login is successful!' , the Data: r}))) } the else {
          // otherwise return to the front-end "user name and password error" conn.query(
"SELECT * WHERE USER_NAME user_info` from` = ' "+ req.query.user_name +"' ", (E, R & lt) => res.json ( new new the Result ({MSG: 'username or password!' }) )) } } }) })

 

Guess you like

Origin www.cnblogs.com/xue-shuai/p/11727816.html