Skip to content

Commit

Permalink
feat: add backend validation for age
Browse files Browse the repository at this point in the history
  • Loading branch information
hady44 committed Apr 29, 2017
1 parent 4649ced commit 0fdeb4f
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions app/routes/api/v1/client/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,13 @@ router.post('/signup', (req, res, next) => {

req.getValidationResult()
.then((result) => {
if (result.isEmpty()) {
new Client(userInfo)
const date = new Date(Date.now());
date.setFullYear(date.getFullYear() - 13);
if (req.body.birthdate) {
if (new Date(req.body.birthdate) > date) {
next("You must be 13 years or older to register to our system'");
} else if (result.isEmpty()) {
new Client(userInfo)
.save()
.then(() => {
ClientAuthenticator.generateConfirmationToken(req.body.email)
Expand All @@ -88,8 +93,9 @@ router.post('/signup', (req, res, next) => {
.catch(e => next(e));
})
.catch(() => next([Strings.clientValidationErrors.userExists]));
} else {
next(result.array());
} else {
next(result.array());
}
}
});
});
Expand Down

1 comment on commit 0fdeb4f

@melzareix
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Connected to #248.

Please sign in to comment.