Skip to content

Commit

Permalink
Merge 8ac798e into 1a24820
Browse files Browse the repository at this point in the history
  • Loading branch information
devPinheiro committed Jul 2, 2019
2 parents 1a24820 + 8ac798e commit 0031263
Show file tree
Hide file tree
Showing 30 changed files with 1,116 additions and 96 deletions.
11 changes: 10 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
{
"presets": ["@babel/preset-env"]
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "current"
}
}
],
]
}
4 changes: 4 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ TEST_DATABASE_USERNAME=
TEST_DATABASE_PASSWORD=
TEST_DATABASE_NAME=
TEST_DATABASE_HOST=
SECRET=
MAIL_USERNAME=
MAIL_PASSWORD=

4 changes: 1 addition & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@
}
}
],
"parserOptions": {
"sourceType": "module"
}
"parserOptions": 0
}
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"prettier.eslintIntegration": true
}
119 changes: 119 additions & 0 deletions mail.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
module.exports = {
/*
|--------------------------------------------------------------------------
| Connection
|--------------------------------------------------------------------------
|
| Connection to be used for sending emails. Each connection needs to
| define a driver too.
|
*/
connection: process.env.MAIL_CONNECTION || 'smtp',

/*
|--------------------------------------------------------------------------
| Views
|--------------------------------------------------------------------------
|
| This configuration defines the folder in which all emails are stored.
| If it's not defined, /mails is used as default.
|
*/
views: 'mails',

/*
|--------------------------------------------------------------------------
| View engine
|--------------------------------------------------------------------------
|
| This is the view engine that should be used. The currently supported are:
| handlebars, edge
|
*/
viewEngine: 'handlebars',

/*
|--------------------------------------------------------------------------
| SMTP
|--------------------------------------------------------------------------
|
| Here we define configuration for sending emails via SMTP.
|
*/
smtp: {
driver: 'smtp',
pool: true,
port: process.env.SMTP_PORT || 2525,
host: process.env.SMTP_HOST || 'smtp.mailtrap.io',
secure: false,
auth: {
user: process.env.MAIL_USERNAME,
pass: process.env.MAIL_PASSWORD
},
maxConnections: 5,
maxMessages: 100,
rateLimit: 10
},

/*
|--------------------------------------------------------------------------
| SparkPost
|--------------------------------------------------------------------------
|
| Here we define configuration for spark post. Extra options can be defined
| inside the "extra" object.
|
| https://developer.sparkpost.com/api/transmissions.html#header-options-attributes
|
| extras: {
| campaign_id: 'sparkpost campaign id',
| options: { // sparkpost options }
| }
|
*/
sparkpost: {
driver: 'sparkpost',
// endpoint: 'https://api.eu.sparkpost.com/api/v1',
apiKey: process.env.SPARKPOST_API_KEY,
extras: {}
},

/*
|--------------------------------------------------------------------------
| Mailgun
|--------------------------------------------------------------------------
|
| Here we define configuration for mailgun. Extra options can be defined
| inside the "extra" object.
|
| https://mailgun-documentation.readthedocs.io/en/latest/api-sending.html#sending
|
| extras: {
| 'o:tag': '',
| 'o:campaign': '',,
| . . .
| }
|
*/
mailgun: {
driver: 'mailgun',
domain: process.env.MAILGUN_DOMAIN,
apiKey: process.env.MAILGUN_API_KEY,
extras: {}
},

/*
|--------------------------------------------------------------------------
| Ethereal
|--------------------------------------------------------------------------
|
| Ethereal driver to quickly test emails in your browser. A disposable
| account is created automatically for you.
|
| https://ethereal.email
|
*/
ethereal: {
driver: 'ethereal'
}
}
3 changes: 3 additions & 0 deletions mails/welcome-mail/welcome-mail.html.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Hi {{name}}. Welcome To Author's Haven.

Please click on this <a href={{ url }} =>link</a> to confirm your email.
Empty file.
Empty file.
18 changes: 13 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "A Social platform for the creative at heart",
"main": "index.js",
"scripts": {
"test": " nyc mocha src/**/*.spec.js --require @babel/register --exit || true",
"start": "babel-node src/index.js",
"test": "NODE_ENV=test npm run migration-rollback && npm run db-migration && nyc mocha src/**/*.spec.js --require @babel/register --exit || true",
"start": "nodemon --exec babel-node src/index.js",
"build": "npm run clean && npm run babel-build",
"clean": "rm -rf dist",
"babel-build": "babel src -d dist && node dist/index",
Expand All @@ -22,21 +22,27 @@
"@babel/node": "^7.4.5",
"@babel/preset-env": "^7.4.5",
"@babel/register": "^7.4.4",
"bcryptjs": "^2.4.3",
"body-parser": "^1.18.3",
"chai": "^4.2.0",
"chai-http": "^4.3.0",
"cors": "^2.8.4",
"cross-env": "^5.2.0",
"dotenv": "^6.2.0",
"express": "^4.16.3",
"jsonwebtoken": "^8.3.0",
"express-validator": "^6.1.0",
"faker": "^4.1.0",
"friendly-mail": "^1.0.0",
"jsonwebtoken": "^8.5.1",
"mocha": "^6.1.4",
"pg": "^7.11.0",
"pg-hstore": "^2.3.3",
"sequelize": "^5.8.12",
"sequelize-cli": "^5.5.0",
"swagger-ui-express": "^4.0.6",
"sequelize-test-helpers": "^1.1.2",
"sinon": "^7.3.2",
"sequelize-test-helpers": "^1.1.2"
"sinon-chai": "^3.3.0",
"swagger-ui-express": "^4.0.6"
},
"devDependencies": {
"coveralls": "^3.0.4",
Expand All @@ -46,6 +52,8 @@
"eslint-plugin-import": "^2.17.3",
"eslint-plugin-prettier": "^3.1.0",
"mocha-lcov-reporter": "^1.3.0",
"morgan": "^1.9.1",
"nodemon": "^1.19.1",
"nyc": "^14.1.1",
"prettier": "^1.18.2"
}
Expand Down
34 changes: 34 additions & 0 deletions src/controllers/auth.controllers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {
loginService,
signUpService,
isUserExist
} from '../services/auth.service';
import Helper from '../services/helper';

const signUp = async (request, response) => {
try {
const result = await isUserExist(request.body.email.toLowerCase());
if (result) {
return Helper.failResponse(response, 409, {
message: 'user already exists'
});
}

const value = await signUpService(request.body);
return Helper.successResponse(response, 201, value.user);
} catch (error) {
return Helper.errorResponse(response, 500);
}
};

const login = async (request, response) => {
const value = await loginService(request.body);
if (value) {
return Helper.successResponse(response, 200, value.user);
}
return Helper.failResponse(response, 400, {
message: 'Invalid email/password'
});
};

export default { signUp, login };
3 changes: 3 additions & 0 deletions src/db/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,23 @@ module.exports = {
password: process.env.DATABASE_PASSWORD,
database: process.env.DATABASE_NAME,
host: process.env.DATABASE_HOST,
logging: false,
dialect: 'postgres'
},
test: {
username: process.env.TEST_DATABASE_USERNAME,
password: process.env.TEST_DATABASE_PASSWORD,
database: process.env.TEST_DATABASE_NAME,
host: process.env.TEST_DATABASE_HOST,
logging: false,
dialect: 'postgres'
},
production: {
username: process.env.DATABASE_USERNAME,
password: process.env.DATABASE_PASSWORD,
database: process.env.DATABASE_NAME,
host: process.env.DATABASE_HOST,
logging: false,
dialect: 'postgres'
}
};
8 changes: 8 additions & 0 deletions src/db/migrations/20190627124710-create-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ module.exports = {
type: Sequelize.STRING,
allowNull: false
},
userName: {
type: Sequelize.STRING,
allowNull: true
},
email: {
type: Sequelize.STRING,
allowNull: false,
Expand All @@ -33,6 +37,10 @@ module.exports = {
allowNull: false,
defaultValue: false
},
confirmEmailCode: {
type: Sequelize.STRING,
allowNull: true
},
isNotified: {
type: Sequelize.BOOLEAN,
allowNull: false,
Expand Down
7 changes: 7 additions & 0 deletions src/db/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ const db = {};
let sequelize;
if (config.use_env_variable === 'production') {
sequelize = new Sequelize(process.env[config.use_env_variable], config);
} else if (process.env.NODE_ENV === 'test') {
sequelize = new Sequelize(
process.env.TEST_DATABASE_NAME,
process.env.TEST_DATABASE_USERNAME,
process.env.TEST_DATABASE_PASSWORD,
config
);
} else {
sequelize = new Sequelize(
process.env.DATABASE_NAME,
Expand Down
Loading

0 comments on commit 0031263

Please sign in to comment.