Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add password confirmation to sign-up action #39

Open
raq929 opened this issue Dec 16, 2016 · 1 comment
Open

Add password confirmation to sign-up action #39

raq929 opened this issue Dec 16, 2016 · 1 comment

Comments

@raq929
Copy link
Contributor

raq929 commented Dec 16, 2016

Currently it doesn't check if the password and password confirmation match.

@cob0910
Copy link

cob0910 commented Mar 30, 2017

I used this template for my capstone and found a solution for this. I was about to open an issue when I found yours.

controllers/users.js

const signup = (req, res, next) => {
  let credentials = req.body.credentials;
  let user = { email: credentials.email, password: credentials.password};
  getToken()
    .then(token => user.token = token)
    // needed to add ternary to ensure new and old passwords match before saving new user
    .then(() =>
      req.body.credentials.password !== req.body.credentials.password_confirmation ?
        Promise.reject(new HttpError(404)) : new User(user).save())
    .then(user =>
      res.status(201).json({ user }))
    .catch(makeErrorHandler(res, next));
};

scripts/sign-up.sh

API="http://localhost:4741"
URL_PATH="/sign-up"

curl "${API}${URL_PATH}" \
  --include \
  --request POST \
  --header "Content-Type: application/json" \
  --data '{
    "credentials": {
      "email": "'"${EMAIL}"'",
      "password": "'"${PASS}"'",
      "password_confirmation": "'"${PASS_CON}"'"
    }
  }'

echo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants