-
Notifications
You must be signed in to change notification settings - Fork 9
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
AbrarNa'im #7
Open
abrarnaim015
wants to merge
34
commits into
kgd-05-eclipse-fox:master
Choose a base branch
from
abrarnaim015:master
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
AbrarNa'im #7
Changes from 10 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
6fd626c
sedang proses validasi
abrarnaim015 a3311f7
AbrarNaim
abrarnaim015 260f818
Abrar Naim D1 Done
abrarnaim015 8616245
Abrar Naim D1 Done
abrarnaim015 5605169
Abrar Naim D2 proses logIn & register
abrarnaim015 fce162a
Abrar Naim D2 proses logIn midelware
abrarnaim015 7184f60
Abrar Naim D2 proses midelware & perbaikan TODO
abrarnaim015 b637461
Abrar Naim D2 proses Authentication
abrarnaim015 b780cce
Abrar Naim D2 Authentication & Authorization DONE
abrarnaim015 423b8ee
Abrar Naim D2 proses errorhandler
abrarnaim015 9ec93d6
Abrar Naim D2 ErrorHandler DONE
abrarnaim015 b10b89f
Abrar Naim D2 ErrorHandler DONE
abrarnaim015 29ec564
Abrar Naim D3 Revisi Helper, bcrypt, jwt ==> DONE
abrarnaim015 8391561
Abrar Naim D3 revisi ErrorHandler
abrarnaim015 b41e2f7
Add 3rd API binaryjazz.us/wp-json/genrenator/v1
abrarnaim015 4a11d37
Add 3rd API add HTML, CSS, jQuery, Form user login
abrarnaim015 5ba99e9
Add 3rd API add HTML, CSS, jQuery, Form user login
abrarnaim015 27c3fe6
memperbaiki eror di server
abrarnaim015 222f57c
add login, home page, and logout with token
abrarnaim015 bc62d13
add singup proces
abrarnaim015 f4784e5
add Home Page, navbar, logout
abrarnaim015 ffb3e9e
add forn add todo, show all todo, dll
abrarnaim015 1fd1e9c
todo list done proces google sign in
abrarnaim015 cb63d74
proces google sign in
abrarnaim015 a6c5d9e
end
abrarnaim015 e652ac9
end
abrarnaim015 61d5994
process heroku
abrarnaim015 159b610
process heroku & forebase
abrarnaim015 56555ce
process heroku & forebase
abrarnaim015 1d73fae
Todo v1.1
abrarnaim015 255f746
fixed all bismillah
abrarnaim015 89a3884
fixed all bismillah and update heroku and firebase
abrarnaim015 507d299
fixed button google, layout, and progres responsiv
abrarnaim015 5b0b461
fixed button google, layout, and progres responsiv
abrarnaim015 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
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
PORT=3000 | ||
RAHASIA='nami<==**' | ||
SALT=10 |
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 @@ | ||
node_modules |
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,16 @@ | ||
require('dotenv').config() | ||
|
||
const express = require('express') | ||
const app = express() | ||
const port = process.env.PORT | ||
const routers = require('./routes') | ||
const errorHandler = require('./middlewares/errorHandler.js') | ||
|
||
app.use(express.json()) | ||
app.use(express.urlencoded({extended: true})) | ||
app.use(routers) | ||
app.use(errorHandler) | ||
|
||
app.listen(port, ()=>{ | ||
console.log(`Let's Go to app FancyTodo http://localhost:${port}`) | ||
}) |
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,23 @@ | ||
{ | ||
"development": { | ||
"username": "postgres", | ||
"password": "postgres", | ||
"database": "FancyTodo", | ||
"host": "127.0.0.1", | ||
"dialect": "postgres" | ||
}, | ||
"test": { | ||
"username": "postgres", | ||
"password": null, | ||
"database": "FancyTodo", | ||
"host": "127.0.0.1", | ||
"dialect": "postgres" | ||
}, | ||
"production": { | ||
"username": "root", | ||
"password": null, | ||
"database": "database_production", | ||
"host": "127.0.0.1", | ||
"dialect": "mysql" | ||
} | ||
} |
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,113 @@ | ||
const {Todo} = require ('../models') | ||
const Super = require('../helper/super.js') | ||
|
||
class TodoController{ | ||
|
||
static async getTodo(req, res, next){ | ||
try { | ||
let data = await Todo.findAll({ | ||
where: {UserId: req.key.id} | ||
}) | ||
res.status(200).json(data) | ||
} catch (err) { | ||
next(err) | ||
} | ||
} | ||
|
||
static async postTodo(req, res, next){ | ||
try { | ||
let dataInput = req.body | ||
let validasiError = Super.validasiPutTodo(dataInput) | ||
if(validasiError.length>0){ | ||
let error ={ | ||
cek: 'postTodo', | ||
status: 400, | ||
msg: validasiError, | ||
} | ||
next(error) | ||
}else{ | ||
dataInput.UserId = req.key.id | ||
let data = await Todo.create(dataInput) | ||
res.status(201).json(data) | ||
} | ||
} catch (err) { | ||
next(err) | ||
} | ||
} | ||
|
||
static async getTodoById(req, res, next){ | ||
try { | ||
let id = +req.params.id | ||
let data = await Todo.findByPk(id) | ||
res.status(200).json(data) | ||
} catch (err) { | ||
next(err) | ||
} | ||
} | ||
|
||
static async putTodo(req, res, next){ | ||
try { | ||
let id = +req.params.id | ||
let dataInput = req.body | ||
|
||
let validasiError = Super.validasiPutTodo(dataInput) | ||
if(validasiError.length>0){ | ||
let error ={ | ||
cek: 'postTodo', | ||
status: 400, | ||
msg: validasiError, | ||
} | ||
next(error) | ||
}else{ | ||
if(!dataInput.status){ | ||
dataInput.status = 'not done' | ||
} | ||
let data = await Todo.update(dataInput, { | ||
where: {id} | ||
}) | ||
res.status(200).json(dataInput) | ||
} | ||
} catch (err) { | ||
next(err) | ||
} | ||
} | ||
|
||
static async patchTodo(req, res, next){ | ||
try { | ||
let id = +req.params.id | ||
let dataInput = req.body.status | ||
let data = Todo.findByPk(id) | ||
data.status = dataInput | ||
Todo.update(data, { | ||
where: {id} | ||
}) | ||
res.status(200).json(data) | ||
} catch (err) { | ||
next(err) | ||
} | ||
} | ||
|
||
static async deleteTodo(req, res, next){ | ||
try { | ||
let id = +req.params.id | ||
let data = await Todo.destroy({ | ||
where: {id} | ||
}) | ||
if(data===0){ | ||
let errMess = { | ||
massage: 'Id Tidak ditemukan' | ||
} | ||
res.status(400).json(errMess) | ||
}else{ | ||
let output = { | ||
massage: 'todo succes to delete' | ||
} | ||
res.status(200).json(output) | ||
} | ||
} catch (err) { | ||
next(err) | ||
} | ||
} | ||
} | ||
|
||
module.exports = TodoController |
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,52 @@ | ||
const {User} = require('../models') | ||
const Super = require('../helper/super.js') | ||
|
||
class UserController{ | ||
static async register(req, res){ | ||
try { | ||
let dataBody = req.body | ||
console.log(dataBody, 'benar' ) | ||
let newData = Super.validasiRegister(dataBody.password) | ||
let dataUpuser = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. penamaan variabel dibenahi ya, misal newUser |
||
email: dataBody.email, | ||
password: newData.password | ||
} | ||
let data = await User.create(dataUpuser) | ||
let postData = { | ||
id: data.id, | ||
email: data.email | ||
} | ||
res.status(201).json(postData) | ||
} catch (err) { | ||
console.log(err, 'err') | ||
res.status(400).json(err) | ||
} | ||
} | ||
|
||
static async login(req, res){ | ||
try { | ||
let dataBody = req.body | ||
let dataBaseUsers = await User.findOne({ | ||
where: {email: dataBody.email} | ||
}) | ||
if(!dataBaseUsers){ | ||
res.status(401).json({error: 'Email atau Password anda tidak Valid 1'}) | ||
}else if(!Super.validasiLoginUser(dataBody.password, dataBaseUsers.password)){ | ||
res.status(401).json({error: 'Email atau Password anda tidak Valid 2'}) | ||
}else{ | ||
let dataUser = { | ||
id: dataBaseUsers.id, | ||
email: dataBaseUsers.email | ||
} | ||
let userToken = Super.tokenUser(dataUser) | ||
dataUser.token = userToken | ||
res.status(200).json(dataUser) | ||
} | ||
} catch (err) { | ||
res.status(400).json(err) | ||
} | ||
} | ||
} | ||
|
||
|
||
module.exports = UserController |
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 @@ | ||
[email protected] | ||
abrarnaim | ||
|
||
[email protected] | ||
nami | ||
|
||
[email protected] | ||
nana | ||
|
||
[email protected] | ||
yuke |
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,46 @@ | ||
const bcrypt = require('bcryptjs'); | ||
const jwt = require('jsonwebtoken') | ||
|
||
class Super { | ||
|
||
static validasiPutTodo(data){ | ||
let dataEror = '' | ||
for(let i in data){ | ||
if(i !== 'status'){ | ||
if(!data[i]){ | ||
let output = `${i} Tidak boleh kosong - ` | ||
dataEror += output | ||
} | ||
} | ||
} | ||
|
||
return dataEror | ||
} | ||
|
||
static validasiRegister(data){ | ||
const salt = bcrypt.genSaltSync(+process.env.SALT); | ||
const hash = bcrypt.hashSync(data, salt); | ||
|
||
return { | ||
password: hash | ||
} | ||
} | ||
|
||
static validasiLoginUser(passLogin, passDB){ | ||
return bcrypt.compareSync(passLogin, passDB) | ||
} | ||
|
||
static tokenUser(data){ | ||
const token = jwt.sign(data, process.env.RAHASIA) | ||
return token | ||
} | ||
|
||
static cekToken(data){ | ||
var decoded = jwt.verify(data, process.env.RAHASIA); | ||
return decoded | ||
// console.log(decoded.foo) | ||
} | ||
|
||
} | ||
|
||
module.exports = Super |
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,26 @@ | ||
const Super = require('../helper/super.js') | ||
const {User} = require('../models') | ||
|
||
const authentication = async (req, res, next)=>{ | ||
// console.log(req.headers) | ||
let token = req.headers.token | ||
try { | ||
if(!token){ | ||
throw({msg: 'invalid token', status: 401}) | ||
}else{ | ||
let cekToken = Super.cekToken(token) | ||
let dataUserDB = await User.findByPk(cekToken.id) | ||
|
||
if(!dataUserDB){ | ||
throw({msg: 'invalid token', status: 401}) | ||
}else{ | ||
req.key = dataUserDB | ||
next() | ||
} | ||
} | ||
} catch (err) { | ||
res.status(400).json(err) | ||
} | ||
} | ||
|
||
module.exports = authentication |
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,26 @@ | ||
const {Todo} = require('../models') | ||
|
||
const authorization = async (req, res, next)=>{ | ||
try { | ||
let dataTodo = await Todo.findOne({ | ||
where: { | ||
id: +req.params.id | ||
} | ||
}) | ||
if(dataTodo.UserId===req.key.id){ | ||
next() | ||
}else{ | ||
throw({msg: 'Unauthorized', status: 401}) | ||
} | ||
} catch (err) { | ||
// let error ={ | ||
// name: 'suthorization', | ||
// status: 400, | ||
// msg: 'Unauthorized' | ||
// } | ||
next(err) | ||
} | ||
|
||
} | ||
|
||
module.exports = authorization |
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,13 @@ | ||
module.exports = (err, req, res, next) =>{ | ||
let status | ||
let msg | ||
if(!err.cek){ | ||
status = 500 | ||
msg = 'Internal Server Error, try again leter' | ||
}else{ | ||
status = err.status | ||
msg = err.msg | ||
} | ||
|
||
res.status(status).json({msg}) | ||
} |
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,36 @@ | ||
'use strict'; | ||
module.exports = { | ||
up: async (queryInterface, Sequelize) => { | ||
await queryInterface.createTable('Todos', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
title: { | ||
type: Sequelize.STRING | ||
}, | ||
description: { | ||
type: Sequelize.STRING | ||
}, | ||
status: { | ||
type: Sequelize.STRING | ||
}, | ||
dueDate: { | ||
type: Sequelize.DATE | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}); | ||
}, | ||
down: async (queryInterface, Sequelize) => { | ||
await queryInterface.dropTable('Todos'); | ||
} | ||
}; |
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.
nama class nya jangan Super ya, mungkin InputValidation lebih cocok