Skip to content

Commit

Permalink
change name to username and validate it #58
Browse files Browse the repository at this point in the history
  • Loading branch information
jwld committed Jun 3, 2017
1 parent 211d9c9 commit 8aadbd5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
8 changes: 7 additions & 1 deletion public/scripts/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
e.preventDefault();

var data = {
name: e.target.elements.name.value,
username: e.target.elements.username.value,
email: e.target.elements.email.value,
password: e.target.elements.password.value,
confirmation: e.target.elements.confirm.value
Expand All @@ -27,6 +27,12 @@
}
}

// check username for spaces
if (/\s/.test(data.username)) {
indexModule.showMessage('Username can\'t contain spaces');
return false;
}

// check email address
if (!/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(data.email)) {
indexModule.showMessage('Email address is invalid');
Expand Down
2 changes: 1 addition & 1 deletion src/routes/add_user.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const bcrypt = require('bcrypt');

module.exports = (req, res) => {
const data = {
name: req.body.name,
username: req.body.username,
email: req.body.email,
password: bcrypt.hashSync(req.body.password, 10)
};
Expand Down
4 changes: 2 additions & 2 deletions views/register.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<div class="page-content">
<form class="registration-form" id="register-form" autocomplete="off">
<div class="form-input-wrap">
<label>Name
<input type="text" name="name">
<label>Username
<input type="text" name="username">
</label>

<label>Email Address
Expand Down

0 comments on commit 8aadbd5

Please sign in to comment.