Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": ["airbnb", "prettier", "prettier/react"],
"plugins": ["prettier"],
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 2016,
"sourceType": "module",
Expand Down
11 changes: 11 additions & 0 deletions 404.html
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>
8 changes: 4 additions & 4 deletions database/db_build.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ DROP TABLE IF EXISTS posts CASCADE;

CREATE TABLE users (
user_id SERIAL PRIMARY KEY ,
user_name VARCHAR(100) NOT NULL UNIQUE ,
username VARCHAR(100) NOT NULL UNIQUE ,
password VARCHAR(100) NOT NULL ,
email TEXT NOT NULL UNIQUE,
country TEXT NOT NULL,
Expand All @@ -16,7 +16,7 @@ added_date DATE DEFAULT now()
CREATE TABLE posts(
post_id SERIAL PRIMARY KEY,
user_id INTEGER NOT NULL ,
prefferedPayment VARCHAR(100) NOT NULL,
prefferedpayment VARCHAR(100) NOT NULL,
country TEXT NOT NULL,
city TEXT NOT NULL,
coin TEXT NOT NULL,
Expand All @@ -26,10 +26,10 @@ CREATE TABLE posts(
added_date DATE DEFAULT now()
);

INSERT INTO users(user_name , password ,email, country,city) VALUES
INSERT INTO users(username , password ,email, country,city) VALUES
('hawk Kayleb' , '123' , 'user@gmail.com' , 'Israel' ,'Haifa' );

INSERT INTO posts(user_id, prefferedPayment, country, city, coin, qty, price, buyerSeller)
INSERT INTO posts(user_id, prefferedpayment, country, city, coin, qty, price, buyerSeller)
VALUES (1, 'Bank Transfer', 'Israel', 'Tel Aviv', 'Bitcoin', 1, 17000, 'Seller');

COMMIT;
20 changes: 20 additions & 0 deletions database/queries/addUsers.js
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};
14 changes: 14 additions & 0 deletions database/queries/userPosts.js
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);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get rid of this commented out code

cb(null, posts.rows);
}
});
}

module.exports = userPosts;
27 changes: 27 additions & 0 deletions database/queries/validateUser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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){
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not triple equals?

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;
Loading