In this module, you can learn how to use Postgres. Don't have Postgres installed on your local machine yet? Fear not! We can make a Postgres database for you. Please login first to create your database. If you want, you may keep reading this tutorial without login.
`
+
In this module, you can learn how to use Postgres. Don't have Postgres installed on your local machine yet? Fear not! We can make a Postgres database for you. Simply click on the button below to create your temporary Postgres database. Credentials for your database will appear after it is done being created.
+
Temporary database credentials will expire in 5 days. If you want, you can signup with us and get a non-expiring Postgres database!
In this module, you can learn how to use Postgres. Don't have Postgres installed on your local machine yet? Fear not! We can make a Postgres database for you. Simply click on the button below to create your Postgres database. Credentials for your database will appear after it is done being created.
In this module, you can learn how to use Postgres. Don't have Postgres installed on your local machine yet? Fear not! We can make a Postgres database for you. Please login first to create your database. If you want, you may keep reading this tutorial without login.
\`
+
In this module, you can learn how to use Postgres. Don't have Postgres installed on your local machine yet? Fear not! We can make a Postgres database for you. Simply click on the button below to create your temporary Postgres database. Credentials for your database will appear after it is done being created.
+
Temporary database credentials will expire in 5 days. If you want, you can signup with us and get a non-expiring Postgres database!
In this module, you can learn how to use Postgres. Don't have Postgres installed on your local machine yet? Fear not! We can make a Postgres database for you. Simply click on the button below to create your Postgres database. Credentials for your database will appear after it is done being created.
-
+
\`
} else {
introduction.innerHTML = \`
@@ -97,10 +100,10 @@ database: \${username}\`
}
let disabled
- const createDb = () => {
+ const createdb = () => {
if (disabled) return
disabled = true
- const button = document.getElementById(\\"button\\")
+ const button = document.getElementById(\\"createdb_button\\")
button.classList.add(\\"disabled\\")
button.innerText = \\"Creating...\\"
fetch('/api/createDatabase/postgres', { method: \\"POST\\" }).then(r => r.json()).then((r) => {
@@ -123,6 +126,39 @@ database: \${username}\`
}
})
}
+ const anon_createdb = () => {
+ if (disabled) return
+ disabled = true
+ const button = document.getElementById(\\"anon_createdb_button\\")
+ button.classList.add(\\"disabled\\")
+ button.innerText = \\"Creating...\\"
+ fetch(\\"/api/anonymous/Postgres\\", { method: \\"POST\\" }).then((r) => r.json()).then((r) => {
+ console.log(r)
+ if (r.error) {
+ const message = res.error.message;
+ alert(message);
+ disabled = false
+ button.classList.remove(\\"disabled\\")
+ button.innerText = \\"Create my database\\"
+ } else {
+ credentials.innerHTML = \`host: learndatabases.dev
+username: \${r.username}
+password: \${r.dbPassword}
+database: \${r.username}\`
+ alert(\\"Temporary database is created. Since credentials are provided only once, please keep the information somewhere safe :)\\");
+ button.style.opacity = 0
+ setTimeout(() => {
+ button.innerText = \\"Complete!\\"
+ button.style.background = \\"rgb(10, 170, 75)\\"
+ button.style.opacity = 1
+ setTimeout(() => {
+ introduction.append(credentials)
+ }, 200)
+ }, 200)
+ }
+ });
+ }
+
const content = document.getElementById(\\"content\\")
fetch('/lessons/postgres.md').then(r => r.text()).then((r) => {
marked.setOptions({
@@ -137,16 +173,17 @@ database: \${username}\`
"
+
+"
`;
exports[`test welcome page should render resetPassword page correctly 1`] = `
From 392f76fe627444043760d99db33790313bf19eea Mon Sep 17 00:00:00 2001
From: Ulisseus
Date: Sun, 27 Sep 2020 18:20:57 +0300
Subject: [PATCH 03/12] closes #221 - Update Readme.md
Added step by step installation guide, Added comments to env.example
variables. DIALECT variable was removed since it's unnecessary, added new NODE_ENV
variable (String: "production"/"development"). With NODE_ENV set to
"development" confirmation emails will be send to localhost. Removed redundant
getEnv function and moved its test to mailer.test.js, updated mailer
snapshot.
---
README.md | 39 ++++++----------------
env.example | 37 +++++++++++++++-----
lib/getEnvVar.js | 8 -----
lib/getEnvVar.test.js | 16 ---------
lib/users.js | 2 +-
services/__snapshots__/mailer.test.js.snap | 1 +
services/mailer.js | 15 ++++++---
services/mailer.test.js | 16 +++++++--
8 files changed, 65 insertions(+), 69 deletions(-)
delete mode 100644 lib/getEnvVar.js
delete mode 100644 lib/getEnvVar.test.js
diff --git a/README.md b/README.md
index 9e0b738..010f7b2 100644
--- a/README.md
+++ b/README.md
@@ -1,27 +1,14 @@
-# databases
+# Learn Databases
-Fork the repository
-Go to https://c0d3.com
-Create a username and account
+A free site to learn and try different databases.
-Ssh into c0d3 server
-`ssh [c0d3.com username]@c0d.com -p 221`
+**Installation**
-Clone your fork on the server
-`git clone https://github.com/[github username]/databases.git`
-
-To run server
-1. install nodemon
-2. run npm start:dev
-
-To install nodemon
-`npm i -g nodemon`
-
-To start the server
-`npm run start:dev`
-
-If you need to make changes to the Database run:
-`ALTER_DB=true npm run start:dev`
+1. Fork the repository. If you're new to github refer to this [guide](https://github.com/garageScript/curriculum/wiki/Engineering-Workflow).
+2. Download the fork into your local machine.
+3. Install required node modules with `npm i`.
+4. Create new .env file, it should look like env.example but with valid credentials instead of `***`. Ask for passwords and api keys on our [chat](https://chat.c0d3.com/c0d3/channels/).
+5. Start server with `npm run start:dev` and register a new user.
### Production Phases
@@ -34,13 +21,9 @@ Phase 3: API to power user interactions (backend)
Phase 4: UI (aka frontend)
**We are here!**
-What needs to worked on
-https://github.com/garageScript/databases/issues
+* [Issues](https://github.com/garageScript/databases/issues)
-Wiki
-https://github.com/garageScript/databases/wiki
+* [Wiki](https://github.com/garageScript/databases/wiki)
-If you have any questions message us on our chat:
-https://chat.c0d3.com/c0d3/channels/
+* If you have any questions message us on our [chat](https://chat.c0d3.com/c0d3/channels/)
-__Sequelize credentials are in the chat for privacy__
diff --git a/env.example b/env.example
index edf8144..2df5def 100644
--- a/env.example
+++ b/env.example
@@ -1,9 +1,28 @@
-HOST=databases.com
-PORT=3000
-PG_USER=username
-PASSWORD=password
-DATABASE=database
-DIALECT=postgres
-ALTER_DB=true
-MAILGUN_API_KEY=01234567890123456789
-MAILGUN_DOMAIN=databases.com
\ No newline at end of file
+#api key for our mailing service
+MAILGUN_API_KEY=***
+#mailgun domain
+MAILGUN_DOMAIN=code3scape.com
+#testing port for jest
+TEST_PORT=30300
+#sequelize host adress
+HOST=104.168.169.204
+#sequelize postgres username
+PG_USER=***
+#sequelize postgres database name
+DATABASE=***
+#sequelize database password
+PASSWORD=***
+#sequelize allow to alter database: true/false
+ALTER_DB=true
+#password for session-express
+SECRET=***
+#Neo4j graph database url
+NEO4J_URL=neo4j://104.168.169.204
+#Neo4j username
+NEO4J_USER=***
+#Neo4j password
+NEO4J_PASSWORD=***
+#production/development flag, with development mode on confirmations emails will redirect to localhost
+NODE_ENV = development
+#local port, default value 3052
+PORT = 4000
\ No newline at end of file
diff --git a/lib/getEnvVar.js b/lib/getEnvVar.js
deleted file mode 100644
index 08af531..0000000
--- a/lib/getEnvVar.js
+++ /dev/null
@@ -1,8 +0,0 @@
-require('dotenv').config()
-
-module.exports = (type) => {
- if (type === 'mailgun') return {
- apiKey: process.env.MAILGUN_API_KEY || '123',
- domain: process.env.MAILGUN_DOMAIN
- }
-}
\ No newline at end of file
diff --git a/lib/getEnvVar.test.js b/lib/getEnvVar.test.js
deleted file mode 100644
index 0eafe3e..0000000
--- a/lib/getEnvVar.test.js
+++ /dev/null
@@ -1,16 +0,0 @@
-describe('test getEnvVar', () => {
- it('should return mailgun env var', () => {
- process.env.MAILGUN_API_KEY = 'test key'
- const getEnvVar = require('./getEnvVar')
- expect(getEnvVar('mailgun').apiKey).toEqual('test key')
- })
- it('should return default mailgun env var', () => {
- delete process.env.MAILGUN_API_KEY
- const getEnvVar = require('./getEnvVar')
- expect(getEnvVar('mailgun').apiKey).toEqual('123')
- })
- it('should return nothing without argument', () => {
- const getEnvVar = require('./getEnvVar')
- expect(getEnvVar()).toEqual(undefined)
- })
-})
\ No newline at end of file
diff --git a/lib/users.js b/lib/users.js
index 742f344..9d1ff83 100644
--- a/lib/users.js
+++ b/lib/users.js
@@ -29,7 +29,7 @@ users.sendPasswordResetEmail = async (userAccount) => {
const accountJSON = JSON.stringify(account);
const encodedToken = Buffer.from(accountJSON).toString("base64");
- await email.sendPasswordResetEmail(userAccount.email, encodedToken);
+ await email.sendPasswordResetEmail(userAccount.email, encodedToken, process.env.NODE_ENV, process.env.PORT);
const updatedAccount = await userAccount.update({
passwordReset: randomToken,
tokenExpiration: Date.now() + 1000 * 60 * 60 * 24,
diff --git a/services/__snapshots__/mailer.test.js.snap b/services/__snapshots__/mailer.test.js.snap
index fa77bf8..59f14d9 100644
--- a/services/__snapshots__/mailer.test.js.snap
+++ b/services/__snapshots__/mailer.test.js.snap
@@ -10,6 +10,7 @@ Object {
You have requested a (re)set password token. The button below will redirect you to our website with an autheticated token. Please click the button and set your password.
You have requested a (re)set password token. The button below will redirect you to our website with an autheticated token. Please click the button and set your password.
In this module, you can learn how to use Postgres. Don't have Postgres installed on your local machine yet? Fear not! We can make a Postgres database for you. Simply click on the button below to create your temporary Postgres database. Credentials for your database will appear after it is done being created.
-
Temporary database credentials will expire in 5 days. If you want, you can signup with us and get a non-expiring Postgres database!
+
Temporary database credentials will expire in 5 days. If you want, you can sign up with us and get a non-expiring Postgres database!
\`
} else if (!dbExists) {
@@ -145,7 +145,7 @@ database: \${username}\`
username: \${r.username}
password: \${r.dbPassword}
database: \${r.username}\`
- alert(\\"Temporary database is created. Since credentials are provided only once, please keep the information somewhere safe :)\\");
+ alert(\\"Your temporary database is created. Since credentials are provided only once, please keep the information somewhere safe :)\\");
button.style.opacity = 0
setTimeout(() => {
button.innerText = \\"Complete!\\"
diff --git a/views/postgres.ejs b/views/postgres.ejs
index 32a744a..cae19db 100644
--- a/views/postgres.ejs
+++ b/views/postgres.ejs
@@ -26,7 +26,7 @@ database: ${username}`
if (!username) {
introduction.innerHTML = `
In this module, you can learn how to use Postgres. Don't have Postgres installed on your local machine yet? Fear not! We can make a Postgres database for you. Simply click on the button below to create your temporary Postgres database. Credentials for your database will appear after it is done being created.
-
Temporary database credentials will expire in 5 days. If you want, you can signup with us and get a non-expiring Postgres database!
+
Temporary database credentials will expire in 5 days. If you want, you can sign up with us and get a non-expiring Postgres database!
`
} else if (!dbExists) {
@@ -87,7 +87,7 @@ database: ${username}`
username: ${r.username}
password: ${r.dbPassword}
database: ${r.username}`
- alert("Temporary database is created. Since credentials are provided only once, please keep the information somewhere safe :)");
+ alert("Your temporary database is created. Since credentials are provided only once, please keep the information somewhere safe :)");
button.style.opacity = 0
setTimeout(() => {
button.innerText = "Complete!"
From 59d6816c4fe19d8b8d95eac4077b1c79d7b46a3f Mon Sep 17 00:00:00 2001
From: Hoie Kim
Date: Mon, 28 Sep 2020 15:33:43 +0000
Subject: [PATCH 05/12] remove postgres.ejs
---
views/postgres.ejs | 103 ---------------------------------------------
1 file changed, 103 deletions(-)
delete mode 100644 views/postgres.ejs
diff --git a/views/postgres.ejs b/views/postgres.ejs
deleted file mode 100644
index eb4e1ec..0000000
--- a/views/postgres.ejs
+++ /dev/null
@@ -1,103 +0,0 @@
-<%- include("./partials/head") %>
-
Learn PostgreSQL
-
-
-
-
-
-
-
-
-
From ec8758f9221f32367b384342ab6af6cd9c78ff61 Mon Sep 17 00:00:00 2001
From: Hoie Kim
Date: Mon, 28 Sep 2020 15:43:08 +0000
Subject: [PATCH 06/12] minor change
---
src/server.test.js | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/server.test.js b/src/server.test.js
index 0df16f8..a739a4f 100644
--- a/src/server.test.js
+++ b/src/server.test.js
@@ -11,7 +11,6 @@ const userRoutes = require("./routes/userRoutes");
const renderRoutes = require("./routes/renderRoutes");
userRoutes.createUser = jest.fn();
-userRoutes.createAnonUser = jest.fn();
userRoutes.loginUser = jest.fn();
userRoutes.logoutUser = jest.fn();
userRoutes.deleteUser = jest.fn();
From dc1d5696728d8d011da492589dceb4cbef3b5344 Mon Sep 17 00:00:00 2001
From: Ulisseus
Date: Sun, 27 Sep 2020 18:20:57 +0300
Subject: [PATCH 07/12] closes #221 - Update Readme.md
Added step by step installation guide, Added comments to env.example
variables. DIALECT variable was removed since it's unnecessary, added new NODE_ENV
variable (String: "production"/"development"). With NODE_ENV set to
"development" confirmation emails will be send to localhost. Removed redundant
getEnv function and moved its test to mailer.test.js, updated mailer
snapshot.
---
README.md | 39 ++++++---------------
env.example | 40 +++++++++++++++++-----
lib/getEnvVar.js | 8 -----
lib/getEnvVar.test.js | 16 ---------
lib/users.js | 2 +-
services/__snapshots__/mailer.test.js.snap | 2 +-
services/mailer.js | 14 +++++---
services/mailer.test.js | 9 +++--
8 files changed, 60 insertions(+), 70 deletions(-)
delete mode 100644 lib/getEnvVar.js
delete mode 100644 lib/getEnvVar.test.js
diff --git a/README.md b/README.md
index 9e0b738..010f7b2 100644
--- a/README.md
+++ b/README.md
@@ -1,27 +1,14 @@
-# databases
+# Learn Databases
-Fork the repository
-Go to https://c0d3.com
-Create a username and account
+A free site to learn and try different databases.
-Ssh into c0d3 server
-`ssh [c0d3.com username]@c0d.com -p 221`
+**Installation**
-Clone your fork on the server
-`git clone https://github.com/[github username]/databases.git`
-
-To run server
-1. install nodemon
-2. run npm start:dev
-
-To install nodemon
-`npm i -g nodemon`
-
-To start the server
-`npm run start:dev`
-
-If you need to make changes to the Database run:
-`ALTER_DB=true npm run start:dev`
+1. Fork the repository. If you're new to github refer to this [guide](https://github.com/garageScript/curriculum/wiki/Engineering-Workflow).
+2. Download the fork into your local machine.
+3. Install required node modules with `npm i`.
+4. Create new .env file, it should look like env.example but with valid credentials instead of `***`. Ask for passwords and api keys on our [chat](https://chat.c0d3.com/c0d3/channels/).
+5. Start server with `npm run start:dev` and register a new user.
### Production Phases
@@ -34,13 +21,9 @@ Phase 3: API to power user interactions (backend)
Phase 4: UI (aka frontend)
**We are here!**
-What needs to worked on
-https://github.com/garageScript/databases/issues
+* [Issues](https://github.com/garageScript/databases/issues)
-Wiki
-https://github.com/garageScript/databases/wiki
+* [Wiki](https://github.com/garageScript/databases/wiki)
-If you have any questions message us on our chat:
-https://chat.c0d3.com/c0d3/channels/
+* If you have any questions message us on our [chat](https://chat.c0d3.com/c0d3/channels/)
-__Sequelize credentials are in the chat for privacy__
diff --git a/env.example b/env.example
index edf8144..932e9c0 100644
--- a/env.example
+++ b/env.example
@@ -1,9 +1,31 @@
-HOST=databases.com
-PORT=3000
-PG_USER=username
-PASSWORD=password
-DATABASE=database
-DIALECT=postgres
-ALTER_DB=true
-MAILGUN_API_KEY=01234567890123456789
-MAILGUN_DOMAIN=databases.com
\ No newline at end of file
+#api key for our mailing service
+MAILGUN_API_KEY=***
+#mailgun domain
+MAILGUN_DOMAIN=code3scape.com
+#testing port for jest
+TEST_PORT=30300
+#sequelize host adress
+HOST=104.168.169.204
+#sequelize postgres username
+PG_USER=***
+#sequelize postgres database name
+DATABASE=***
+#sequelize database password
+PASSWORD=***
+#sequelize allow to alter database: true/false
+ALTER_DB=true
+#password for session-express
+SECRET=***
+#Neo4j graph database url
+NEO4J_URL=neo4j://104.168.169.204
+#Neo4j username
+NEO4J_USER=***
+#Neo4j password
+NEO4J_PASSWORD=***
+#production/development flag
+NODE_ENV = development
+#local port, default value 3052
+PORT = 3052
+#hostname adress, default is https://learndatabases.dev,
+#if you want to use localhost you need to specify port, for example http://localhost:4000
+HOSTNAME = http://localhost:3052
\ No newline at end of file
diff --git a/lib/getEnvVar.js b/lib/getEnvVar.js
deleted file mode 100644
index 08af531..0000000
--- a/lib/getEnvVar.js
+++ /dev/null
@@ -1,8 +0,0 @@
-require('dotenv').config()
-
-module.exports = (type) => {
- if (type === 'mailgun') return {
- apiKey: process.env.MAILGUN_API_KEY || '123',
- domain: process.env.MAILGUN_DOMAIN
- }
-}
\ No newline at end of file
diff --git a/lib/getEnvVar.test.js b/lib/getEnvVar.test.js
deleted file mode 100644
index 0eafe3e..0000000
--- a/lib/getEnvVar.test.js
+++ /dev/null
@@ -1,16 +0,0 @@
-describe('test getEnvVar', () => {
- it('should return mailgun env var', () => {
- process.env.MAILGUN_API_KEY = 'test key'
- const getEnvVar = require('./getEnvVar')
- expect(getEnvVar('mailgun').apiKey).toEqual('test key')
- })
- it('should return default mailgun env var', () => {
- delete process.env.MAILGUN_API_KEY
- const getEnvVar = require('./getEnvVar')
- expect(getEnvVar('mailgun').apiKey).toEqual('123')
- })
- it('should return nothing without argument', () => {
- const getEnvVar = require('./getEnvVar')
- expect(getEnvVar()).toEqual(undefined)
- })
-})
\ No newline at end of file
diff --git a/lib/users.js b/lib/users.js
index 742f344..9d1ff83 100644
--- a/lib/users.js
+++ b/lib/users.js
@@ -29,7 +29,7 @@ users.sendPasswordResetEmail = async (userAccount) => {
const accountJSON = JSON.stringify(account);
const encodedToken = Buffer.from(accountJSON).toString("base64");
- await email.sendPasswordResetEmail(userAccount.email, encodedToken);
+ await email.sendPasswordResetEmail(userAccount.email, encodedToken, process.env.NODE_ENV, process.env.PORT);
const updatedAccount = await userAccount.update({
passwordReset: randomToken,
tokenExpiration: Date.now() + 1000 * 60 * 60 * 24,
diff --git a/services/__snapshots__/mailer.test.js.snap b/services/__snapshots__/mailer.test.js.snap
index fa77bf8..2b44a81 100644
--- a/services/__snapshots__/mailer.test.js.snap
+++ b/services/__snapshots__/mailer.test.js.snap
@@ -9,7 +9,7 @@ Object {
You have requested a (re)set password token. The button below will redirect you to our website with an autheticated token. Please click the button and set your password.
You have requested a (re)set password token. The button below will redirect you to our website with an autheticated token. Please click the button and set your password.
DEVELOPMENT MODE IS ON. This link will redirect you to your development server
" : ""}
Warning: Anyone with access to this email has access to your account. Don't share this email with other people.
diff --git a/services/mailer.test.js b/services/mailer.test.js
index 6d33473..896d2e9 100644
--- a/services/mailer.test.js
+++ b/services/mailer.test.js
@@ -1,4 +1,5 @@
jest.mock('../lib/log')
+require("dotenv").config();
const logGen = require('../lib/log')
const logger = {
info: jest.fn(),
@@ -19,7 +20,7 @@ mailgun.mockImplementation(() => {
const email = require('./mailer');
-describe('Test mailgun', ()=>{
+describe('Test mailgun', () => {
beforeEach(() => {
jest.clearAllMocks()
})
@@ -39,5 +40,9 @@ describe('Test mailgun', ()=>{
expect(logger.error).toHaveBeenCalledTimes(1)
expect(logger.error.mock.calls[0][0]).toEqual('Confirmation Email Error:')
})
-
+ it('should notify that development mode is on in confirmation email', async () => {
+ messages.send = jest.fn().mockReturnValue(Promise.resolve('hello'))
+ await email.sendPasswordResetEmail('paul@github.com', 'token123', "http://localhost:4000")
+ expect(messages.send.mock.calls[0][0].html.includes('DEVELOPMENT MODE IS ON')).toEqual(true)
+ })
})
From 0a833ed635c721f3e3345bd888d5d9632db16e6e Mon Sep 17 00:00:00 2001
From: Ulisseus
Date: Sun, 27 Sep 2020 18:20:57 +0300
Subject: [PATCH 08/12] closes #221 - Update Readme, remove getEnv.js, fixes to
envExample
---
README.md | 39 +++++-------------
env.example | 47 +++++++++++++++++-----
lib/getEnvVar.js | 8 ----
lib/getEnvVar.test.js | 16 --------
lib/users.js | 2 +-
services/__snapshots__/mailer.test.js.snap | 5 +++
services/mailer.js | 25 ++++++++++--
services/mailer.test.js | 22 ++++++++--
8 files changed, 95 insertions(+), 69 deletions(-)
delete mode 100644 lib/getEnvVar.js
delete mode 100644 lib/getEnvVar.test.js
diff --git a/README.md b/README.md
index 9e0b738..010f7b2 100644
--- a/README.md
+++ b/README.md
@@ -1,27 +1,14 @@
-# databases
+# Learn Databases
-Fork the repository
-Go to https://c0d3.com
-Create a username and account
+A free site to learn and try different databases.
-Ssh into c0d3 server
-`ssh [c0d3.com username]@c0d.com -p 221`
+**Installation**
-Clone your fork on the server
-`git clone https://github.com/[github username]/databases.git`
-
-To run server
-1. install nodemon
-2. run npm start:dev
-
-To install nodemon
-`npm i -g nodemon`
-
-To start the server
-`npm run start:dev`
-
-If you need to make changes to the Database run:
-`ALTER_DB=true npm run start:dev`
+1. Fork the repository. If you're new to github refer to this [guide](https://github.com/garageScript/curriculum/wiki/Engineering-Workflow).
+2. Download the fork into your local machine.
+3. Install required node modules with `npm i`.
+4. Create new .env file, it should look like env.example but with valid credentials instead of `***`. Ask for passwords and api keys on our [chat](https://chat.c0d3.com/c0d3/channels/).
+5. Start server with `npm run start:dev` and register a new user.
### Production Phases
@@ -34,13 +21,9 @@ Phase 3: API to power user interactions (backend)
Phase 4: UI (aka frontend)
**We are here!**
-What needs to worked on
-https://github.com/garageScript/databases/issues
+* [Issues](https://github.com/garageScript/databases/issues)
-Wiki
-https://github.com/garageScript/databases/wiki
+* [Wiki](https://github.com/garageScript/databases/wiki)
-If you have any questions message us on our chat:
-https://chat.c0d3.com/c0d3/channels/
+* If you have any questions message us on our [chat](https://chat.c0d3.com/c0d3/channels/)
-__Sequelize credentials are in the chat for privacy__
diff --git a/env.example b/env.example
index edf8144..fd363ef 100644
--- a/env.example
+++ b/env.example
@@ -1,9 +1,38 @@
-HOST=databases.com
-PORT=3000
-PG_USER=username
-PASSWORD=password
-DATABASE=database
-DIALECT=postgres
-ALTER_DB=true
-MAILGUN_API_KEY=01234567890123456789
-MAILGUN_DOMAIN=databases.com
\ No newline at end of file
+#api key for our mailing service
+MAILGUN_API_KEY=***
+#mailgun domain
+MAILGUN_DOMAIN=code3scape.com
+#testing port for jest
+TEST_PORT=30300
+#sequelize host adress
+HOST=104.168.169.204
+#sequelize postgres username
+PG_USER=***
+#sequelize postgres database name
+DATABASE=***
+#sequelize database password
+PASSWORD=***
+#sequelize allow to alter database: true/false
+ALTER_DB=true
+#password for session-express
+SECRET=***
+#Neo4j graph database url
+NEO4J_URL=neo4j://104.168.169.204
+#Neo4j username
+NEO4J_USER=***
+#Neo4j password
+NEO4J_PASSWORD=***
+<<<<<<< HEAD
+#production/development flag
+NODE_ENV = development
+#local port, default value 3052
+PORT = 3052
+#hostname adress, default is https://learndatabases.dev,
+#if you want to use localhost you need to specify port, for example http://localhost:4000
+HOSTNAME = http://localhost:3052
+=======
+#production/development flag, with development mode on confirmations emails will redirect to localhost
+NODE_ENV = development
+#local port, default value 3052
+PORT = 4000
+>>>>>>> 392f76f... closes #221 - Update Readme.md
diff --git a/lib/getEnvVar.js b/lib/getEnvVar.js
deleted file mode 100644
index 08af531..0000000
--- a/lib/getEnvVar.js
+++ /dev/null
@@ -1,8 +0,0 @@
-require('dotenv').config()
-
-module.exports = (type) => {
- if (type === 'mailgun') return {
- apiKey: process.env.MAILGUN_API_KEY || '123',
- domain: process.env.MAILGUN_DOMAIN
- }
-}
\ No newline at end of file
diff --git a/lib/getEnvVar.test.js b/lib/getEnvVar.test.js
deleted file mode 100644
index 0eafe3e..0000000
--- a/lib/getEnvVar.test.js
+++ /dev/null
@@ -1,16 +0,0 @@
-describe('test getEnvVar', () => {
- it('should return mailgun env var', () => {
- process.env.MAILGUN_API_KEY = 'test key'
- const getEnvVar = require('./getEnvVar')
- expect(getEnvVar('mailgun').apiKey).toEqual('test key')
- })
- it('should return default mailgun env var', () => {
- delete process.env.MAILGUN_API_KEY
- const getEnvVar = require('./getEnvVar')
- expect(getEnvVar('mailgun').apiKey).toEqual('123')
- })
- it('should return nothing without argument', () => {
- const getEnvVar = require('./getEnvVar')
- expect(getEnvVar()).toEqual(undefined)
- })
-})
\ No newline at end of file
diff --git a/lib/users.js b/lib/users.js
index 742f344..9d1ff83 100644
--- a/lib/users.js
+++ b/lib/users.js
@@ -29,7 +29,7 @@ users.sendPasswordResetEmail = async (userAccount) => {
const accountJSON = JSON.stringify(account);
const encodedToken = Buffer.from(accountJSON).toString("base64");
- await email.sendPasswordResetEmail(userAccount.email, encodedToken);
+ await email.sendPasswordResetEmail(userAccount.email, encodedToken, process.env.NODE_ENV, process.env.PORT);
const updatedAccount = await userAccount.update({
passwordReset: randomToken,
tokenExpiration: Date.now() + 1000 * 60 * 60 * 24,
diff --git a/services/__snapshots__/mailer.test.js.snap b/services/__snapshots__/mailer.test.js.snap
index fa77bf8..81d4458 100644
--- a/services/__snapshots__/mailer.test.js.snap
+++ b/services/__snapshots__/mailer.test.js.snap
@@ -9,7 +9,12 @@ Object {
You have requested a (re)set password token. The button below will redirect you to our website with an autheticated token. Please click the button and set your password.
You have requested a (re)set password token. The button below will redirect you to our website with an autheticated token. Please click the button and set your password.
+<<<<<<< HEAD
+ Set my Password ${hostname != "https://learndatabases.dev" ?
+ "
DEVELOPMENT MODE IS ON. This link will redirect you to your development server
" : ""}
+=======
Set my Password
+ ${mode === "development" ?
+ "
DEVELOPMENT MODE IS ON. This link will redirect you to your local server
Warning: Anyone with access to this email has access to your account. Don't share this email with other people.
diff --git a/services/mailer.test.js b/services/mailer.test.js
index 6d33473..f50d8bb 100644
--- a/services/mailer.test.js
+++ b/services/mailer.test.js
@@ -1,4 +1,5 @@
jest.mock('../lib/log')
+require("dotenv").config();
const logGen = require('../lib/log')
const logger = {
info: jest.fn(),
@@ -19,14 +20,14 @@ mailgun.mockImplementation(() => {
const email = require('./mailer');
-describe('Test mailgun', ()=>{
+describe('Test mailgun', () => {
beforeEach(() => {
jest.clearAllMocks()
})
it('should test if mocksend and mailgun is called', async () => {
messages.send = jest.fn().mockReturnValue(Promise.resolve('hello'))
- await email.sendPasswordResetEmail('paul@github.com', 'token123')
+ await email.sendPasswordResetEmail('paul@github.com', 'token123', true)
expect(messages.send).toHaveBeenCalledTimes(1)
expect(messages.send.mock.calls[0][0]).toMatchSnapshot()
expect(logger.info).toHaveBeenCalledTimes(1)
@@ -39,5 +40,20 @@ describe('Test mailgun', ()=>{
expect(logger.error).toHaveBeenCalledTimes(1)
expect(logger.error.mock.calls[0][0]).toEqual('Confirmation Email Error:')
})
-
+<<<<<<< HEAD
+ it('should notify that development mode is on in confirmation email', async () => {
+ messages.send = jest.fn().mockReturnValue(Promise.resolve('hello'))
+ await email.sendPasswordResetEmail('paul@github.com', 'token123', "http://localhost:4000")
+=======
+ it('should send email to learndatabases with ENV_MODE set to production', async () => {
+ messages.send = jest.fn().mockReturnValue(Promise.resolve('hello'))
+ await email.sendPasswordResetEmail('paul@github.com', 'token123', "production", 4000)
+ expect(messages.send.mock.calls[0][0].html.includes('https://learndatabases.dev/setPassword/token123')).toEqual(true)
+ })
+ it('should notify that development mode is on in confirmation email', async () => {
+ messages.send = jest.fn().mockReturnValue(Promise.resolve('hello'))
+ await email.sendPasswordResetEmail('paul@github.com', 'token123', "development", 4000)
+>>>>>>> 392f76f... closes #221 - Update Readme.md
+ expect(messages.send.mock.calls[0][0].html.includes('DEVELOPMENT MODE IS ON')).toEqual(true)
+ })
})
From 1ba2e06827e89c9def6ab6a302a193b9141cda9e Mon Sep 17 00:00:00 2001
From: Ulisseus
Date: Tue, 29 Sep 2020 00:06:30 +0300
Subject: [PATCH 09/12] fix a typo
---
env.example | 7 -------
lib/users.js | 2 +-
services/__snapshots__/mailer.test.js.snap | 5 -----
services/mailer.js | 13 -------------
services/mailer.test.js | 13 +------------
5 files changed, 2 insertions(+), 38 deletions(-)
diff --git a/env.example b/env.example
index fd363ef..91941cb 100644
--- a/env.example
+++ b/env.example
@@ -22,7 +22,6 @@ NEO4J_URL=neo4j://104.168.169.204
NEO4J_USER=***
#Neo4j password
NEO4J_PASSWORD=***
-<<<<<<< HEAD
#production/development flag
NODE_ENV = development
#local port, default value 3052
@@ -30,9 +29,3 @@ PORT = 3052
#hostname adress, default is https://learndatabases.dev,
#if you want to use localhost you need to specify port, for example http://localhost:4000
HOSTNAME = http://localhost:3052
-=======
-#production/development flag, with development mode on confirmations emails will redirect to localhost
-NODE_ENV = development
-#local port, default value 3052
-PORT = 4000
->>>>>>> 392f76f... closes #221 - Update Readme.md
diff --git a/lib/users.js b/lib/users.js
index 9d1ff83..4348d55 100644
--- a/lib/users.js
+++ b/lib/users.js
@@ -29,7 +29,7 @@ users.sendPasswordResetEmail = async (userAccount) => {
const accountJSON = JSON.stringify(account);
const encodedToken = Buffer.from(accountJSON).toString("base64");
- await email.sendPasswordResetEmail(userAccount.email, encodedToken, process.env.NODE_ENV, process.env.PORT);
+ await email.sendPasswordResetEmail(userAccount.email, encodedToken, process.env.HOSTNAME);
const updatedAccount = await userAccount.update({
passwordReset: randomToken,
tokenExpiration: Date.now() + 1000 * 60 * 60 * 24,
diff --git a/services/__snapshots__/mailer.test.js.snap b/services/__snapshots__/mailer.test.js.snap
index 81d4458..2b44a81 100644
--- a/services/__snapshots__/mailer.test.js.snap
+++ b/services/__snapshots__/mailer.test.js.snap
@@ -9,12 +9,7 @@ Object {
You have requested a (re)set password token. The button below will redirect you to our website with an autheticated token. Please click the button and set your password.
You have requested a (re)set password token. The button below will redirect you to our website with an autheticated token. Please click the button and set your password.
-<<<<<<< HEAD
Set my Password ${hostname != "https://learndatabases.dev" ?
"
DEVELOPMENT MODE IS ON. This link will redirect you to your development server
" : ""}
-=======
- Set my Password
- ${mode === "development" ?
- "
DEVELOPMENT MODE IS ON. This link will redirect you to your local server
In this module, you can learn how to use ${database}. Don't have ${database} installed on your local machine yet? Fear not! We can make an ${database} database for you. Simply click on the button below to create your ${database} database. Credentials for your database will appear after it is done being created.
In this module, you can learn how to use ${database}. You have already created an ${database} database on our server. Here are the credentials for your database.
From 5b60ba8027e30d6d1d2e76de8a6f272636739754 Mon Sep 17 00:00:00 2001
From: Ulisseus
Date: Wed, 30 Sep 2020 12:52:46 +0300
Subject: [PATCH 12/12] remove global variable in mailer.js args
---
env.example | 6 +++---
lib/users.js | 2 +-
services/mailer.js | 7 +++----
services/mailer.test.js | 11 ++++++++++-
4 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/env.example b/env.example
index 91941cb..83bca08 100644
--- a/env.example
+++ b/env.example
@@ -1,4 +1,4 @@
-#api key for our mailing service
+#api key for mailing service
MAILGUN_API_KEY=***
#mailgun domain
MAILGUN_DOMAIN=code3scape.com
@@ -22,10 +22,10 @@ NEO4J_URL=neo4j://104.168.169.204
NEO4J_USER=***
#Neo4j password
NEO4J_PASSWORD=***
-#production/development flag
+#production/development flag, in jest tests this varible is "test" by default
NODE_ENV = development
#local port, default value 3052
PORT = 3052
#hostname adress, default is https://learndatabases.dev,
#if you want to use localhost you need to specify port, for example http://localhost:4000
-HOSTNAME = http://localhost:3052
+HOSTNAME = https://learndatabases.dev
diff --git a/lib/users.js b/lib/users.js
index 4348d55..742f344 100644
--- a/lib/users.js
+++ b/lib/users.js
@@ -29,7 +29,7 @@ users.sendPasswordResetEmail = async (userAccount) => {
const accountJSON = JSON.stringify(account);
const encodedToken = Buffer.from(accountJSON).toString("base64");
- await email.sendPasswordResetEmail(userAccount.email, encodedToken, process.env.HOSTNAME);
+ await email.sendPasswordResetEmail(userAccount.email, encodedToken);
const updatedAccount = await userAccount.update({
passwordReset: randomToken,
tokenExpiration: Date.now() + 1000 * 60 * 60 * 24,
diff --git a/services/mailer.js b/services/mailer.js
index ab5bfd5..6e89e73 100644
--- a/services/mailer.js
+++ b/services/mailer.js
@@ -9,8 +9,8 @@ const mg = mailgun({
const mgModule = {};
-mgModule.sendPasswordResetEmail = (receiver, token, hostname = "https://learndatabases.dev") => {
- const link = `${hostname}/setPassword/${token}`
+mgModule.sendPasswordResetEmail = (receiver, token) => {
+ const link = `${process.env.HOSTNAME||"https://learndatabases.dev"}/setPassword/${token}`
const data = {
from: "admin@learndatabases.dev",
to: receiver,
@@ -22,8 +22,7 @@ mgModule.sendPasswordResetEmail = (receiver, token, hostname = "https://learndat
You have requested a (re)set password token. The button below will redirect you to our website with an autheticated token. Please click the button and set your password.
- Set my Password ${hostname != "https://learndatabases.dev" ?
- "
DEVELOPMENT MODE IS ON. This link will redirect you to your development server
" : ""}
+ Set my Password ${link!=`https://learndatabases.dev/setPassword/${token}`?"
DEVELOPMENT MODE IS ON. This link will redirect you to your development server
" : ""}
Warning: Anyone with access to this email has access to your account. Don't share this email with other people.
diff --git a/services/mailer.test.js b/services/mailer.test.js
index 896d2e9..c63e3f4 100644
--- a/services/mailer.test.js
+++ b/services/mailer.test.js
@@ -26,6 +26,7 @@ describe('Test mailgun', () => {
})
it('should test if mocksend and mailgun is called', async () => {
+ process.env.HOSTNAME = ""
messages.send = jest.fn().mockReturnValue(Promise.resolve('hello'))
await email.sendPasswordResetEmail('paul@github.com', 'token123')
expect(messages.send).toHaveBeenCalledTimes(1)
@@ -35,14 +36,22 @@ describe('Test mailgun', () => {
})
it('should call logger.error when function is called with invalid argument', async () => {
+ process.env.HOSTNAME = ""
messages.send = jest.fn().mockReturnValue(Promise.reject('rejected'))
await email.sendPasswordResetEmail(null, null)
expect(logger.error).toHaveBeenCalledTimes(1)
expect(logger.error.mock.calls[0][0]).toEqual('Confirmation Email Error:')
})
it('should notify that development mode is on in confirmation email', async () => {
+ process.env.HOSTNAME= "http://localhost:4000"
messages.send = jest.fn().mockReturnValue(Promise.resolve('hello'))
- await email.sendPasswordResetEmail('paul@github.com', 'token123', "http://localhost:4000")
+ await email.sendPasswordResetEmail('paul@github.com', 'token123')
expect(messages.send.mock.calls[0][0].html.includes('DEVELOPMENT MODE IS ON')).toEqual(true)
})
+ it('should redirect to learndatabases.dev in confirmation email if no HOSTNAME was provided in .env file', async () => {
+ process.env.HOSTNAME = ""
+ messages.send = jest.fn().mockReturnValue(Promise.resolve('hello'))
+ await email.sendPasswordResetEmail('paul@github.com', 'token123')
+ expect(messages.send.mock.calls[0][0].html.includes('https://learndatabases.dev/setPassword')).toEqual(true)
+ })
})