-
Notifications
You must be signed in to change notification settings - Fork 0
Samipublicchat #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nj-io
wants to merge
13
commits into
master
Choose a base branch
from
samipublicchat
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Samipublicchat #18
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
fea8367
building public chat components
nj-io b2a18c9
authentication set up
MarlenAw d6b5eb4
merged redux pull request
nj-io b087124
set up the authentication and the userPage
hasansaad1 d033870
Merge branch 'master' into hasan
hasansaad1 06bf3d0
working version of public chat
nj-io 4f1609b
removed reference websockets chat repo
nj-io fa5a7e1
css and general interface improvement
nj-io 10c758f
removed console.logs
SamiSha99 905d133
Fixed an issue that caused an Error
SamiSha99 d394445
Removed all comments and commented codes
SamiSha99 248598b
few button tweaks on the landing page
nj-io efe9014
locally mergin hasan auth branch
nj-io File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,2 +1,3 @@ | ||
| public/ | ||
| node_modules/ | ||
| chat-program/ |
This file contains hidden or 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 hidden or 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 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <title></title> | ||
| </head> | ||
| <body> | ||
| <h1>404</h1> | ||
| <h2>The page you requested has not been found</h2> | ||
| </body> | ||
| </html> |
This file contains hidden or 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 @@ | ||
| DATABASE_URL= postgres://samis:12345@localhost:8080/coin | ||
This file contains hidden or 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,11 @@ | ||
| const fs = require('fs'); | ||
| const connect = require('./db_connection'); | ||
|
|
||
| const buildScript = fs.readFileSync(`${__dirname}/db_build.sql`, `utf8`); | ||
|
|
||
| connect.query(buildScript, (err, res) => { | ||
| connect.query(buildScript, err => { | ||
| if (err) { | ||
| throw err; | ||
| } | ||
| connect.end(); | ||
| }) | ||
| }); |
This file contains hidden or 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 hidden or 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,11 +1,7 @@ | ||
| const {Pool} = require('pg'); | ||
| const url = require('url'); | ||
| const { Pool } = require('pg'); | ||
| require('env2')('config.env'); | ||
|
|
||
| if (!process.env.DATABASE_URL) | ||
| throw new Error("enviroment var for database must be set"); | ||
| throw new Error('enviroment var for database must be set'); | ||
|
|
||
| const params = url.parse(process.env.DATABASE_URL); | ||
| const [username, password] = params.auth.split(':'); | ||
|
|
||
| module.exports = new Pool({connectionString: process.env.DATABASE_URL}); | ||
| module.exports = new Pool({ connectionString: process.env.DATABASE_URL }); |
This file contains hidden or 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,20 @@ | ||
| const connect = require("../db_connection"); | ||
| const bcrypt = require("bcrypt"); | ||
|
|
||
| const salt = 10; | ||
|
|
||
| const addUser = (username, password, email, country, city, cb) => { | ||
| bcrypt.hash(password, salt, (err, hash) => { | ||
| connect.query(`INSERT INTO users (username, password, email, country, city) VALUES ($1, $2, $3, $4, $5)`, | ||
| [username, hash, email, country, city], (err, result) => { | ||
| if(err){ | ||
| console.log("error in writing the query", err); | ||
| cb(err); | ||
| }else{ | ||
| cb(null, result); | ||
| } | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| module.exports = {addUser}; |
This file contains hidden or 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,13 +1,16 @@ | ||
| const connect = require('../db_connection'); | ||
|
|
||
| const posts = (req, res) => { | ||
| connect.query('SELECT * FROM posts INNER JOIN users ON (posts.user_id = users.user_id)', (err, posts) => { | ||
| if (err) { | ||
| res.status(500).end("Server Error, Please Try In Other Time"); | ||
| } else { | ||
| res.send(posts.rows); | ||
| connect.query( | ||
| `SELECT * FROM posts INNER JOIN users ON (posts.user_id = users.user_id)`, | ||
| (err, posts) => { | ||
| if (err) { | ||
| res.status(500).end('Server Error, Please Try In Other Time'); | ||
| } else { | ||
| res.send(posts.rows); | ||
| } | ||
| } | ||
| }); | ||
| } | ||
| ); | ||
| }; | ||
|
|
||
| module.exports = posts; |
This file contains hidden or 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,14 @@ | ||
| const connect = require('../db_connection'); | ||
|
|
||
| const userPosts = (username, cb) => { | ||
| connect.query('SELECT * FROM posts INNER JOIN users ON (posts.user_id = users.user_id) WHERE username = $1', [username], (err, posts) => { | ||
| if (err) { | ||
| cb(err); | ||
| } else { | ||
| // console.log('post.rows:', post.rows); | ||
| cb(null, posts.rows); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| module.exports = userPosts; |
This file contains hidden or 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,29 @@ | ||
| const connect = require('../db_connection'); | ||
| const bcrypt = require('bcrypt'); | ||
|
|
||
| const validateUser = (user, cb) => { | ||
| connect.query( | ||
| `SELECT * FROM users WHERE username = $1`, | ||
| [user.username], | ||
| (err, res) => { | ||
| if (err) { | ||
| return cb(err); | ||
| } | ||
| if (res.rows.length == 0) { | ||
| return cb(null, 0); | ||
| } | ||
|
|
||
| bcrypt.compare(user.password, res.rows[0].password, (err, isValid) => { | ||
| if (err) { | ||
| return cb(err); | ||
| } | ||
| if (!isValid) { | ||
| return cb(null, 0); | ||
| } | ||
| return cb(null, res.rows[0]); | ||
| }); | ||
| } | ||
| ); | ||
| }; | ||
|
|
||
| module.exports = validateUser; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file shouldn't be in source control.