-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 61c164e
Showing
14 changed files
with
1,998 additions
and
0 deletions.
There are no files selected for viewing
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,10 @@ | ||
PORT=9090 | ||
APP_URL=http://localhost:9090 | ||
APP_API=https://cluster-01.apigratis.com/api | ||
JWT_SECRET=MY_SECRET_KEY | ||
JWT_ALGO=HS256 | ||
|
||
SecretKey= | ||
PublicToken= | ||
DeviceToken= | ||
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,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
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,2 @@ | ||
# apigratis-chatopen | ||
|
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,32 @@ | ||
const jwt = require('jsonwebtoken'); | ||
|
||
function JWTCheck(req, res, next) { | ||
// Pega o token do header da requisição | ||
// const token = req.headers.authorization && req.headers.authorization.split(' ')[1]; | ||
|
||
//get all cookies headers | ||
const cookies = req.headers.cookie; | ||
|
||
//get token from cookies | ||
const token = cookies && cookies.split(';').find(c => c.trim().startsWith('token='))?.split('=')[1]; | ||
|
||
console.log('token', token); | ||
|
||
if (!token) { | ||
return res.status(401).redirect('/auth'); | ||
} | ||
|
||
try { | ||
// Verifica o token usando a chave secreta | ||
const decoded = jwt.verify(token, process.env.JWT_SECRET); | ||
// Adiciona os dados do usuário decodificados à requisição para uso nas próximas rotas | ||
req.userData = decoded; | ||
next(); | ||
} catch (error) { | ||
return res.status(401).redirect('/auth')-send({ | ||
message: 'Falha na autenticação do token' | ||
}); | ||
} | ||
} | ||
|
||
module.exports = JWTCheck; |
Binary file not shown.
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,19 @@ | ||
{ | ||
"name": "apigratis-socket", | ||
"version": "0.0.1", | ||
"description": "socket central apibrasil", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"axios": "^1.3.3", | ||
"body-parser": "^1.20.1", | ||
"dotenv": "^16.0.3", | ||
"express": "^4.16.3", | ||
"jsonwebtoken": "^8.3.0", | ||
"socket.io": "^2.1.1" | ||
} | ||
} |
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,133 @@ | ||
body{margin-top:20px;} | ||
|
||
body.login { | ||
position: initial; | ||
background: url('https://www.bootdey.com/template_demo/dayfriend/img/Bg/faces2.png'); | ||
padding-top: 0; | ||
} | ||
|
||
body.login #content { | ||
max-width: 760px; | ||
margin: auto; | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
bottom: 0; | ||
right: 0; | ||
} | ||
|
||
body.login .lock-container { | ||
margin: auto; | ||
width: 300px; | ||
} | ||
|
||
@media (min-width: 480px) { | ||
body.login .lock-container { | ||
bottom: 0; | ||
height: 550px; | ||
left: 0; | ||
position: absolute; | ||
top: 0; | ||
right: 0; | ||
} | ||
} | ||
|
||
body.login .lock-container h1 { | ||
text-align: center; | ||
color: #fff; | ||
font-size: 28px; | ||
} | ||
|
||
body.login .lock-container .panel { | ||
max-width: 300px !important; | ||
background: #fff; | ||
position: relative; | ||
} | ||
|
||
body.login .lock-container .panel img { | ||
margin: 20px 0 10px; | ||
} | ||
|
||
body.login .lock-container .panel input { | ||
margin-bottom: 10px; | ||
} | ||
|
||
body.login .lock-container .panel .btn { | ||
margin-top: 10px; | ||
} | ||
|
||
|
||
body.login .lock-container .panel .forgot-password { | ||
margin: 10px 0 0; | ||
font-weight: 500; | ||
color: #26a69a; | ||
display: block; | ||
} | ||
|
||
body.login #content { | ||
max-width: 760px; | ||
margin: auto; | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
bottom: 0; | ||
right: 0; | ||
} | ||
|
||
#content { | ||
min-width: 320px; | ||
} | ||
/* Sticky footer styles | ||
-------------------------------------------------- */ | ||
html { | ||
position: relative; | ||
min-height: 100%; | ||
} | ||
|
||
body { | ||
/* Margin bottom by footer height */ | ||
margin-bottom: 60px; | ||
} | ||
|
||
.footer { | ||
position: absolute; | ||
bottom: 0; | ||
width: 100%; | ||
/* Set the fixed height of the footer here */ | ||
height: 60px; | ||
background-color: #f5f5f5; | ||
} | ||
|
||
body.login .lock-container .panel input { | ||
margin-bottom: 10px; | ||
} | ||
|
||
.form-control { | ||
display: block; | ||
width: 100%; | ||
height: 34px; | ||
padding: 6px 12px; | ||
font-size: 14px; | ||
line-height: 1.42857143; | ||
color: #333333; | ||
background-color: #f7f7f7; | ||
background-image: none; | ||
border: 1px solid #efefef; | ||
border-radius: 4px; | ||
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075); | ||
transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s; | ||
} | ||
|
||
.footer-container { | ||
width: auto; | ||
max-width: 680px; | ||
padding: 0 15px; | ||
} | ||
.footer-container .text-muted { | ||
margin: 20px 0; | ||
} | ||
|
||
.img-login { | ||
width:120px; | ||
height:120px; | ||
} |
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,43 @@ | ||
window.addEventListener('load', () => { | ||
//body add class login breakpoint-1024 | ||
$("body").addClass("login breakpoint-1024"); | ||
}); | ||
|
||
const form = document.querySelector('form'); | ||
|
||
form.addEventListener('submit', async (e) => { | ||
e.preventDefault(); | ||
|
||
const email = form.email.value; | ||
const password = form.password.value; | ||
|
||
const response = await fetch('/api/auth', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify({ email, password }) | ||
}); | ||
|
||
const data = await response.json(); | ||
|
||
console.log(data); | ||
|
||
if (data.error == true ) { | ||
|
||
$('.alert-danger').css('display', 'block'); | ||
$('.alert').text(data.message); | ||
|
||
} else { | ||
|
||
// const cellphone = data?.user?.cellphone; | ||
let ddi = `55`; | ||
let ddd = data?.user?.cellphone?.substring(0, 2); | ||
let cellphone = data?.user?.cellphone?.substring(2, 11); | ||
|
||
let mobile = `${ddi}${ddd}${cellphone}`; | ||
|
||
window.location.href = `/chat?welcome=true&session=${mobile}` | ||
|
||
} | ||
}); |
Oops, something went wrong.