-
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
34 changed files
with
522 additions
and
64 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
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,11 @@ | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { Factory } from 'rosie'; | ||
|
||
export default Factory.define('article') | ||
.sequence('id') | ||
.attr('userId', 1) | ||
.attr('title', 'Going home like a dog') | ||
.attr('description', 'Holla and Holla') | ||
.attr('body', 'More about this the dance of chicken') | ||
.attr('coverUrl', 'placeholer.jpg') | ||
.attr('slug', 'going-home-like-a-dog-2aijv735e7w'); |
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 user from './user'; | ||
import article from './article'; | ||
|
||
export { user, article }; |
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,15 @@ | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { Factory } from 'rosie'; | ||
import Chance from 'chance'; | ||
|
||
const chance = new Chance(); | ||
|
||
export default Factory.define('user') | ||
.sequence('id') | ||
.attr('firstName', chance.first()) | ||
.attr('lastName', chance.last()) | ||
.attr('username', chance.word({ length: 5 })) | ||
.attr('email', chance.email({ domain: 'example.com' })) | ||
.attr('password', 'Baaa1234!') | ||
.attr('role', 'admin') | ||
.attr('permissions', ['read', 'write', 'delete', 'edit']); |
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,32 @@ | ||
/** | ||
* @param {string} input | ||
* @param {string} required | ||
* @returns {array} an array of errors or an empty array if no error | ||
*/ | ||
export default (input, required = '') => { | ||
if (!input && !required) { | ||
return []; | ||
} | ||
|
||
let errors = []; | ||
const re = /[A-Z0-9]+@[A-Z0-9-]+\.[A-Z]{2,4}/gim; | ||
const reUsername = /[\\ ,;:"!#$%&'*+/=?^`{|}~]/g; | ||
const reDomainSLD = /[ \\,;:"!#$%&'*+/=?^`{|}~]/g; | ||
const reDomainTLD = /[\d+ \\,;:"!#$%&'*+-/=?^_`{|}~]/g; | ||
|
||
const emailUsername = input.substring(0, input.lastIndexOf('@')); | ||
const emailDomainSLD = input.substring(input.lastIndexOf('@') + 1, input.lastIndexOf('.')); | ||
const emailDomainTLD = input.substring(input.lastIndexOf('.') + 1); | ||
|
||
const isEmailUsername = !emailUsername.match(/^[0-9]/) && !reUsername.test(emailUsername); | ||
const isEmailDomainSLD = !emailDomainSLD.match(/^[0-9]/) && !reDomainSLD.test(emailDomainSLD); | ||
const isEmailDomainTLD = !emailDomainTLD.match(/^[0-9]/) && !reDomainTLD.test(emailDomainTLD); | ||
|
||
if (re.test(input) && isEmailUsername && isEmailDomainSLD && isEmailDomainTLD) { | ||
return []; | ||
} | ||
|
||
errors = [...['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,5 @@ | ||
import isUser from './isUser'; | ||
import email from './email'; | ||
import password from './password'; | ||
|
||
export { isUser, 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,15 @@ | ||
import { User } from '../../queries'; | ||
|
||
/** | ||
* @param {object} input | ||
* @returns {boolean} return true if the user exists or false if not | ||
*/ | ||
export default async (input = {}) => { | ||
const findUser = await User.findOne(input); | ||
|
||
if (!findUser.errors && Object.keys(findUser).length > 0) { | ||
return true; | ||
} | ||
|
||
return false; | ||
}; |
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,27 @@ | ||
import * as validate from '../helpers/validation'; | ||
|
||
export default async (req, res, next) => { | ||
if (Object.keys(req.body).length <= 0) { | ||
return res.status(400).json({ errors: { body: ['body can not be empty'] } }); | ||
} | ||
|
||
// check errors in email or password | ||
const errors = { | ||
email: [...validate.email(req.body.email, 'required')], | ||
password: [...validate.password(req.body.password, 'required')] | ||
}; | ||
|
||
const isUser = await validate.isUser({ email: req.body.email }); | ||
|
||
if (isUser) { | ||
errors.email = [...['sorry, this email is already used']]; | ||
} | ||
|
||
Object.keys(errors).forEach(error => errors[error].length > 0 || delete errors[error]); | ||
|
||
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
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 * as User from './users'; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export { User }; |
Oops, something went wrong.