Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
happy-botday
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Guillaume Vagner
happy-botday
Commits
4a21d9ac
Commit
4a21d9ac
authored
6 years ago
by
Guillaume Vagner
Browse files
Options
Downloads
Patches
Plain Diff
divide website
parent
cad98ae2
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
requests.js
+33
-2
33 additions, 2 deletions
requests.js
schedule.js
+0
-0
0 additions, 0 deletions
schedule.js
website.js
+3
-26
3 additions, 26 deletions
website.js
with
36 additions
and
28 deletions
requests.js
+
33
−
2
View file @
4a21d9ac
...
...
@@ -2,7 +2,7 @@
const
rp
=
require
(
'
request-promise
'
);
// Modules propres
var
{
modifyChan
}
=
require
(
'
./connection-db
'
);
var
{
modifyChan
,
getChanByState
}
=
require
(
'
./connection-db
'
);
// Configurations
const
config
=
require
(
'
./config
'
);
...
...
@@ -54,6 +54,37 @@ function getGroupById(token, id) {
}).
catch
(
err
=>
{
console
.
error
(
err
)
})
}
// Récupération d'un token
function
getFirstToken
(
code
,
state
)
{
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
:
code
,
redirect_uri
:
config
.
website
.
protocol
+
'
://
'
+
config
.
website
.
hostname
+
'
/auth
'
,
client_id
:
config
.
oauth2
.
clientid
,
client_secret
:
config
.
oauth2
.
secretid
}
}
return
Promise
.
all
([
rp
(
options
),
getChanByState
(
state
)
]).
then
(([
body
,
chan
])
=>
{
if
(
!
chan
)
return
rep
=
JSON
.
parse
(
body
);
chan
.
token
=
rep
.
access_token
;
chan
.
refresh
=
rep
.
refresh_token
;
chan
.
expiration
=
rep
.
expires_at
;
chan
.
state
=
''
;
return
modifyChan
(
chan
)
})
}
// Récupération d'un nouveau token
function
getNewToken
(
chan
)
{
...
...
@@ -79,4 +110,4 @@ function getNewToken(chan) {
})
};
module
.
exports
=
{
getBirthdays
,
sendRequest
,
searchGroups
,
getGroupById
,
getNewToken
};
\ No newline at end of file
module
.
exports
=
{
getBirthdays
,
sendRequest
,
searchGroups
,
getGroupById
,
getFirstToken
,
getNewToken
};
\ No newline at end of file
This diff is collapsed.
Click to expand it.
schedule.js
0 → 100644
+
0
−
0
View file @
4a21d9ac
This diff is collapsed.
Click to expand it.
website.js
+
3
−
26
View file @
4a21d9ac
// Modules extérieurs
var
app
=
require
(
'
express
'
)();
var
rp
=
require
(
'
request-promise
'
);
// Modules propres
var
bot
=
require
(
'
./telegram
'
);
var
{
modifyChan
,
getChanByState
}
=
require
(
'
./connection-db
'
);
var
{
getFirstToken
}
=
require
(
'
./requests
'
);
// Configurations
const
config
=
require
(
'
./config
'
);
app
.
listen
(
80
,
'
127.0.0.1
'
,
()
=>
{
app
.
listen
(
config
.
website
.
port
,
'
127.0.0.1
'
,
()
=>
{
console
.
log
(
`[express] Website is up and accessible on
${
config
.
website
.
protocol
}
://
${
config
.
website
.
hostname
}
/`
);
})
...
...
@@ -41,30 +41,7 @@ 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
}
}
return
rp
(
options
).
then
(
body
=>
{
return
Promise
.
all
([
body
,
getChanByState
(
req
.
query
.
state
)])
}).
then
(([
body
,
chan
])
=>
{
if
(
!
chan
)
return
rep
=
JSON
.
parse
(
body
);
chan
.
token
=
rep
.
access_token
;
chan
.
refresh
=
rep
.
refresh_token
;
chan
.
expiration
=
rep
.
expires_at
;
chan
.
state
=
''
;
return
modifyChan
(
chan
)
}).
then
(
chan
=>
{
return
getFirstToken
(
req
.
query
.
code
,
req
.
query
.
state
).
then
(
chan
=>
{
bot
.
sendMessage
(
chan
.
chatId
,
`@
${
chan
.
username
}
s'est connecté à OAuth2, shall we begin?`
)
res
.
redirect
(
301
,
`
${
config
.
website
.
protocol
}
://
${
config
.
website
.
hostname
}
/auth`
)
})
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment