Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
les
gancio
Commits
37895087
Commit
37895087
authored
Jul 28, 2019
by
les
Browse files
start a new fediverse experience
parent
f1d54c77
Changes
4
Hide whitespace changes
Inline
Side-by-side
server/api/controller/
bot
.js
→
server/api/controller/
fediverse
.js
View file @
37895087
...
...
@@ -8,7 +8,7 @@ const settingsController = require('./settings')
const
get
=
require
(
'
lodash/get
'
)
const
botController
=
{
bot
:
null
,
bot
s
:
null
,
async
initialize
()
{
const
access_token
=
get
(
settingsController
.
secretSettings
,
'
mastodon_auth.access_token
'
)
const
instance
=
get
(
settingsController
.
settings
,
'
mastodon_instance
'
)
...
...
server/api/controller/settings.js
View file @
37895087
...
...
@@ -79,38 +79,38 @@ const settingsController = {
res
.
json
(
settings
)
},
async
getAuthURL
(
req
,
res
)
{
const
instance
=
req
.
body
.
instance
const
callback
=
`
${
config
.
baseurl
}
/api/settings/oauth`
const
{
client_id
,
client_secret
}
=
await
Mastodon
.
createOAuthApp
(
`https://
${
instance
}
/api/v1/apps`
,
'
gancio
'
,
'
read write
'
,
callback
)
const
url
=
await
Mastodon
.
getAuthorizationUrl
(
client_id
,
client_secret
,
`https://
${
instance
}
`
,
'
read write
'
,
callback
)
//
async getAuthURL(req, res) {
//
const instance = req.body.instance
//
const callback = `${config.baseurl}/api/settings/oauth`
//
const { client_id, client_secret } = await Mastodon.createOAuthApp(`https://${instance}/api/v1/apps`,
//
'gancio', 'read write', callback)
//
const url = await Mastodon.getAuthorizationUrl(client_id, client_secret,
//
`https://${instance}`, 'read write', callback)
await
settingsController
.
set
(
'
mastodon_instance
'
,
instance
)
await
settingsController
.
set
(
'
mastodon_auth
'
,
{
client_id
,
client_secret
},
true
)
res
.
json
(
url
)
},
//
await settingsController.set('mastodon_instance', instance )
//
await settingsController.set('mastodon_auth', { client_id, client_secret }, true)
//
res.json(url)
//
},
async
code
(
req
,
res
)
{
const
code
=
req
.
query
.
code
const
callback
=
`
${
config
.
baseurl
}
/api/settings/oauth`
const
client_id
=
settingsController
.
secretSettings
.
mastodon_auth
.
client_id
const
client_secret
=
settingsController
.
secretSettings
.
mastodon_auth
.
client_secret
const
instance
=
settingsController
.
settings
.
mastodon_instance
//
async code(req, res) {
//
const code = req.query.code
//
const callback = `${config.baseurl}/api/settings/oauth`
//
const client_id = settingsController.secretSettings.mastodon_auth.client_id
//
const client_secret = settingsController.secretSettings.mastodon_auth.client_secret
//
const instance = settingsController.settings.mastodon_instance
try
{
const
access_token
=
await
Mastodon
.
getAccessToken
(
client_id
,
client_secret
,
code
,
`https://
${
instance
}
`
,
callback
)
const
mastodon_auth
=
{
client_id
,
client_secret
,
access_token
}
await
settingsController
.
set
(
'
mastodon_auth
'
,
mastodon_auth
,
true
)
const
botController
=
require
(
'
./
bot
'
)
botController
.
initialize
()
res
.
redirect
(
'
/admin
'
)
}
catch
(
e
)
{
res
.
json
(
e
)
}
},
//
try {
//
const access_token = await Mastodon.getAccessToken(client_id, client_secret, code,
//
`https://${instance}`, callback)
//
const mastodon_auth = { client_id, client_secret, access_token }
//
await settingsController.set('mastodon_auth', mastodon_auth, true)
//
const botController = require('./
fediverse
')
//
botController.initialize()
//
res.redirect('/admin')
//
} catch (e) {
//
res.json(e)
//
}
//
},
}
setTimeout
(
settingsController
.
initialize
,
200
)
...
...
server/api/models/user.js
View file @
37895087
...
...
@@ -3,6 +3,13 @@ const bcrypt = require('bcryptjs')
module
.
exports
=
(
sequelize
,
DataTypes
)
=>
{
const
user
=
sequelize
.
define
(
'
user
'
,
{
username
:
{
type
:
DataTypes
.
STRING
,
unique
:
true
,
index
:
true
,
allowNull
:
false
},
display_name
:
DataTypes
.
STRING
,
email
:
{
type
:
DataTypes
.
STRING
,
unique
:
true
,
...
...
server/notifier.js
View file @
37895087
const
mail
=
require
(
'
./api/mail
'
)
const
bot
=
require
(
'
./api/controller/
bot
'
)
const
bot
=
require
(
'
./api/controller/
fediverse
'
)
const
settingsController
=
require
(
'
./api/controller/settings
'
)
const
config
=
require
(
'
config
'
)
const
eventController
=
require
(
'
./api/controller/event
'
)
...
...
@@ -10,6 +10,7 @@ const { event: Event, notification: Notification, event_notification: EventNoti
const
notifier
=
{
async
sendNotification
(
notification
,
event
)
{
return
const
promises
=
[]
switch
(
notification
.
type
)
{
case
'
mail
'
:
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment