-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
300 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
{ | ||
"reporter": [ | ||
"lcov", | ||
"text" | ||
], | ||
"exclude": [ | ||
"src/migartions", | ||
"src/helpers" | ||
] | ||
"reporter": [ | ||
"lcov", | ||
"text" | ||
], | ||
"exclude": [ | ||
"src/migrations", | ||
"src/tests" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* @param {string} input | ||
* @param {string} required | ||
* @returns {array} an array of errors or an empty array if no error | ||
*/ | ||
export default (input, required = '') => { | ||
const errors = []; | ||
const re = /[A-Z]+@[A-Z-]+\.[A-Z]{2,4}/gim; | ||
const reUsername = /[\\ ,;:"!#$%&'*+/=?^`{|}~]/g; | ||
const reDomainSLD = /[\d+ \\,;:"!#$%&'*+/=?^`{|}~]/g; | ||
const reDomainTLD = /[\d+ \\,;:"!#$%&'*+-/=?^_`{|}~]/g; | ||
|
||
if (!input && !required) { | ||
return []; | ||
} | ||
|
||
const emailUsername = input.substring(0, input.lastIndexOf('@')); | ||
const emailDomainSLD = input.substring(input.lastIndexOf('@') + 1, input.lastIndexOf('.')); | ||
const emailDomainTLD = input.substring(input.lastIndexOf('.') + 1); | ||
|
||
if ( | ||
re.test(input) | ||
&& !reUsername.test(emailUsername) | ||
&& !reDomainSLD.test(emailDomainSLD) | ||
&& !reDomainTLD.test(emailDomainTLD) | ||
) { | ||
return []; | ||
} | ||
|
||
errors.push('Please provide a valid email address'); | ||
|
||
return errors; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import email from './email'; | ||
import password from './password'; | ||
|
||
export { email, password }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* @param {string} input | ||
* @param {string} required | ||
* @returns {array} an array of errors or an empty array if no error | ||
*/ | ||
export default (input, required = '') => { | ||
const errors = []; | ||
|
||
if (!input && !required) { | ||
return []; | ||
} | ||
if ( | ||
input.match(/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,25}$/) | ||
&& input.match(/[ \\,;:"!#$%&'+-/=?^_`{|}~]/) | ||
) { | ||
return []; | ||
} | ||
|
||
errors.push( | ||
'Your password should have a minimum 8 and maximum of 25 characters, it must include at least one upper case letter, one lower case letter, one numeric digit and one special character (*&^!%$@#)' | ||
); | ||
|
||
return errors; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import db from '../models'; | ||
|
||
export default async (req, res, next) => { | ||
const errors = {}; | ||
if (Object.keys(req.body).length <= 0) { | ||
return res.status(400).json({ | ||
errors: { | ||
body: ['body can not be empty'] | ||
} | ||
}); | ||
} | ||
|
||
const checkUser = await db.User.findAll({ | ||
where: { | ||
email: req.body.email | ||
}, | ||
logging: false | ||
}); | ||
|
||
if (checkUser.length > 0) { | ||
errors.email = ['sorry, this email is already used']; | ||
} | ||
|
||
if (Object.keys(errors).length > 0) { | ||
return res.status(400).json({ | ||
errors | ||
}); | ||
} | ||
|
||
next(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* eslint-disable import/no-extraneous-dependencies */ | ||
import chai from 'chai'; | ||
import chaiHttp from 'chai-http'; | ||
import app from '../app'; | ||
|
||
const { expect } = chai; | ||
|
||
chai.use(chaiHttp); | ||
|
||
describe('POST /apiii', () => { | ||
it('should return an error message', (done) => { | ||
chai.request(app) | ||
.get('/apiii') | ||
.end((err, res) => { | ||
expect(res.status).to.equal(404); | ||
done(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
import './user-model'; | ||
import './article-model'; | ||
import './comment-model'; | ||
import './404'; | ||
import './validation/email'; | ||
import './validation/password'; | ||
import './validation/validate-new-user'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* eslint-disable import/no-extraneous-dependencies */ | ||
import chai from 'chai'; | ||
import validateEmail from '../../helpers/validation/email'; | ||
|
||
const { expect } = chai; | ||
|
||
describe('Email validation', () => { | ||
it('should return an array of error messages', () => { | ||
expect(validateEmail('abc@gmail.co/m', 'required').length).to.be.above(0); | ||
}); | ||
|
||
it('should return an empty array if there is no error', () => { | ||
expect(validateEmail('abc@gmail.com', 'required').length).to.be.equals(0); | ||
expect(validateEmail('', false).length).to.be.equals(0); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* eslint-disable import/no-extraneous-dependencies */ | ||
import chai from 'chai'; | ||
import validatePassword from '../../helpers/validation/password'; | ||
|
||
const { expect } = chai; | ||
|
||
describe('Password validation', () => { | ||
it('should return an array of error messages', () => { | ||
expect(validatePassword('abcde12345', 'required').length).to.be.above(0); | ||
}); | ||
|
||
it('should return an empty array if there is no error', () => { | ||
expect(validatePassword('Abcde12345!', 'required').length).to.be.equals(0); | ||
expect(validatePassword('', false).length).to.be.equals(0); | ||
}); | ||
}); |
Oops, something went wrong.