Commit d6c19258 authored by Guillaume Vagner's avatar Guillaume Vagner
Browse files

ended basic website

parent 7987e65e
config.js
mongoose.js
\ No newline at end of file
<!DOCTYPE html>
<html>
<title>Happy Botday !</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Raleway">
<style>
body,
h1 {
font-family: "Raleway", sans-serif
}
body,
html {
height: 100%
}
.bgimg {
background-image: url('/background.jpg');
min-height: 100%;
background-position: center;
background-size: cover;
}
</style>
<body>
<div class="bgimg w3-display-container w3-animate-opacity w3-text-white">
<div class="w3-display-middle">
<p class="w3-large w3-center">Connecté ! Tu peux fermer cette fenêtre.
</p>
</div>
</div>
</body>
</html>
\ No newline at end of file
......@@ -30,7 +30,7 @@
<div class="w3-display-middle">
<h1 class="w3-jumbo w3-animate-top">HAPPY BOTDAY!</h1>
<hr class="w3-border-grey" style="margin:auto;width:40%">
<p class="w3-large w3-center">Go to <a href="https://t.me/happyCSbot">t.me/happyCSbot</a> for configuration.
<p class="w3-large w3-center">Va sur <a href="https://t.me/happyCSbot">t.me/happyCSbot</a> pour la configuration.
</p>
</div>
</div>
......
require('./telegram');
const config = require('./config');
var app = require('express')();
app.listen(80, config.website.hostname, () => {
console.log(`[express] Website is up and accessible on ${config.website.protocol}://${config.website.hostname}`);
})
app.get('/', function (req, res) {
res.sendFile(__dirname + '/index.html')
})
app.get('/background.jpg', function (req, res) {
res.sendFile(__dirname + '/background.jpg')
})
app.get('/auth', function (req, res) {
res.sendFile(__dirname + '/auth.html');
})
app.get('/:id', function (req, res) {
res.send(req.params.id)
})
\ No newline at end of file
const bot = require('./telegram');
const app = require('./website');
\ No newline at end of file
{
"_from": "request@^2.83.0",
"_from": "request",
"_id": "request@2.88.0",
"_inBundle": false,
"_integrity": "sha512-NAqBSrijGLZdM0WZNsInLJpkJokL72XYjUpnB0iwsRgxh7dB6COrHnTBNwN0E+lHDAJzu7kLAkDeY08z2/A0hg==",
"_location": "/request",
"_phantomChildren": {},
"_requested": {
"type": "range",
"type": "tag",
"registry": true,
"raw": "request@^2.83.0",
"raw": "request",
"name": "request",
"escapedName": "request",
"rawSpec": "^2.83.0",
"rawSpec": "",
"saveSpec": null,
"fetchSpec": "^2.83.0"
"fetchSpec": "latest"
},
"_requiredBy": [
"#USER",
"/",
"/node-telegram-bot-api"
],
"_resolved": "https://registry.npmjs.org/request/-/request-2.88.0.tgz",
"_shasum": "9c2fca4f7d35b592efe57c7f0a55e81052124fef",
"_spec": "request@^2.83.0",
"_where": "/home/capsule_man/developpement/happy-botday/node_modules/node-telegram-bot-api",
"_spec": "request",
"_where": "/home/capsule_man/developpement/happy-botday",
"author": {
"name": "Mikeal Rogers",
"email": "mikeal.rogers@gmail.com"
......
......@@ -20,6 +20,7 @@
"license": "ISC",
"dependencies": {
"express": "^4.16.4",
"node-telegram-bot-api": "^0.30.0"
"node-telegram-bot-api": "^0.30.0",
"request": "^2.88.0"
}
}
process.env["NTBA_FIX_319"] = 1;
const TelegramBot = require('node-telegram-bot-api');
const config = require('./config');
......@@ -13,6 +14,8 @@ bot.onText(/\/start/, (msg, _) => {
bot.onText(/\/connect/, (msg, _) => {
const chatId = msg.chat.id;
const resp = `Pour vous identifier, connectez-vous via l\'OAuth2 de ViaRézo depuis ce lien : ${config.website.protocol}://${config.website.hostname}/${chatId}`;
const resp = `Pour vous identifier, connectez-vous via l\'OAuth2 de ViaRézo depuis ce lien : ${config.website.protocol}://${config.website.hostname}/?chatid=${chatId}`;
bot.sendMessage(chatId, resp);
});
\ No newline at end of file
});
module.exports = bot;
\ No newline at end of file
const config = require('./config');
const app = require('express')();
const request = require('request');
const bot = require('./telegram');
app.listen(80, config.website.hostname, () => {
console.log(`[express] Website is up and accessible on ${config.website.protocol}://${config.website.hostname}/`);
})
app.get('/', function (req, res) {
if (!req.query.chatid) { return res.sendFile(`${__dirname}/index.html`) };
const state = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
const redirectURI = config.website.protocol + '://' + config.website.hostname + '/auth';
const url = `https://auth.viarezo.fr/oauth/authorize/?redirect_uri=${redirectURI}&client_id=${config.oauth2.clientid}&response_type=code&state=${state}&scope=${config.oauth2.scope}`;
return res.redirect(301, url);
})
app.get('/background.jpg', function (req, res) {
res.sendFile(`${__dirname}/background.jpg`)
})
app.get('/auth', function (req, res) {
if (!req.query.code || !req.query.state) { return res.sendFile(`${__dirname}/auth.html`) }
const options = {
url: 'https://auth.viarezo.fr/oauth/token',
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
form: {
grant_type: 'authorization_code',
code: req.query.code,
redirect_uri: config.website.protocol + '://' + config.website.hostname + '/auth',
client_id: config.oauth2.clientid,
client_secret: config.oauth2.secretid
}
}
request(options, (err, res, body) => {
console.log(res.statusCode);
if (!err && res.statusCode == 200) {
console.log(body)
}
})
return res.redirect(301, `${config.website.protocol}://${config.website.hostname}/auth`);
})
module.exports = app;
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment