Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async function registerForm(req, res) {
- await User.findOne({
- where: {
- username: req.body.username
- }
- }).then(async function(user) {
- res.status(401).send("Username already exists.");
- }).catch(function() {
- /* create user */
- if (req.body.password !== req.body.confirmPassword) {
- res.status(401).send("Passwords do not match.");
- }
- if (req.body.username == "" || req.body.password == "" || req.body.confirmPassword == "") {
- res.status(401).send("One or more fields are empty.");
- }
- var hashedPassword = hash.generate(req.body.password);
- User.create({
- username: req.body.username,
- password: hashedPassword,
- avatar: "",
- ip: req.ip
- }).then(async function(createdUser) {
- Profile.create({
- userId: createdUser.id
- });
- console.log("profile created");
- }).catch(function() {
- res.status(500).send();
- });
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement