Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jhowbhz committed Feb 21, 2023
0 parents commit 61c164e
Show file tree
Hide file tree
Showing 14 changed files with 1,998 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .env-example
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=
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# apigratis-chatopen

32 changes: 32 additions & 0 deletions middleware/JWTCheck.js
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 added ngrok.exe
Binary file not shown.
19 changes: 19 additions & 0 deletions package.json
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"
}
}
133 changes: 133 additions & 0 deletions public/assets/auth/auth.css
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;
}
43 changes: 43 additions & 0 deletions public/assets/auth/auth.js
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}`

}
});
Loading

0 comments on commit 61c164e

Please sign in to comment.