Skip to content

Commit

Permalink
added email string sanitisation using hook
Browse files Browse the repository at this point in the history
  • Loading branch information
nickangtc committed Sep 20, 2016
1 parent 17242d8 commit e45e0d8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 6 additions & 3 deletions models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ module.exports = function (sequelize, DataTypes) {

// sanitise the data: first-letter cap for firstName & lastName
// TODO: refactor into a function with 2 params
var firstName = createdUser.firstName; // sanitise firstName
// sanitise firstName
var firstName = createdUser.firstName;
firstName = firstName.split(' ');
for (var i = 0; i < firstName.length; i++) {
var elem = firstName[i];
Expand All @@ -60,8 +61,8 @@ module.exports = function (sequelize, DataTypes) {
firstName.splice(i, 1, elem);
}
firstName = firstName.join(' ');

var lastName = createdUser.lastName; // sanitise lastName
// sanitise lastName
var lastName = createdUser.lastName;
lastName = lastName.split(' ');
for (var j = 0; j < lastName.length; j++) {
var el = lastName[j];
Expand All @@ -71,6 +72,8 @@ module.exports = function (sequelize, DataTypes) {
}
lastName = lastName.join(' ');

// sanitise email to lowercase
createdUser.email = createdUser.email.toLowerCase();
// updating the createdUser obj with sanitised names
createdUser.firstName = firstName;
createdUser.lastName = lastName;
Expand Down
4 changes: 1 addition & 3 deletions views/user_starred.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
<div class="row">
<div class="col-sm-8 col-sm-offset-2">
<h2>Your saved urls</h2>




<ul>
<% for (var i = 0; i < data.length; i++) { %>
<a href="<%= data[i].dataValues.url %>" target="_blank">
Expand Down

0 comments on commit e45e0d8

Please sign in to comment.