Created
July 24, 2017 11:24
-
-
Save montyanderson/2b858af424d20a6326e5e245bc753a1e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* previous code */ | |
app.post("/signup", (req, res) => { | |
var check = client.exists(req.body.username); | |
if(check == 0) { | |
res.send("sorry that name already exists"); | |
//res.render("exists", { | |
// name : req.body.username | |
// }); | |
} else if(check == 1) { | |
var username = req.body.username; | |
var password = sha256(req.body.password); | |
var first_name = req.body.first_name; | |
var last_name = req.body.last_name; | |
var email = req.body.email; | |
client.hmset("Meet:User:" + username, [ | |
"username", username, | |
"password", password, | |
"first_name", first_name, | |
"last_name", last_name, | |
"email", email | |
], (err, reply) => { | |
if(err != undefined) { | |
console.log("An error occured during registration: " + err); | |
} else { | |
console.log(reply); | |
res.redirect("/registrationSuccess"); | |
} | |
}); | |
} | |
}); | |
/* with promises, koa instead of express, ioredis instead of redis */ | |
app.post("/signup", async (req, res) => { | |
/* await pauses the function while it's doing asyncronous stuff */ | |
const check = await client.exists(`Meet:User:${username}`); | |
if(!check) { | |
res.body = "No user found!"; | |
return; | |
} | |
/* destructuring - allows getting lots of things out of an object */ | |
const { | |
username, | |
first_name, | |
last_name, | |
} = req.body; | |
const password = sha256(req.body.password); | |
await client.hmset(`Meet:User:${username}`, { | |
username, | |
password, | |
first_name, | |
last_name, | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment