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
64beb39b
Commit
64beb39b
authored
Jul 29, 2019
by
les
Browse files
user rsa key for federation
parent
f98820da
Changes
7
Hide whitespace changes
Inline
Side-by-side
assets/style.less
View file @
64beb39b
...
...
@@ -25,10 +25,14 @@ html, body {
// }
.el-card {
max-width: 6
7
0px;
max-width: 6
3
0px;
margin: 30px auto;
}
#admin.el-card {
max-width: 850px;
}
.el-dialog {
margin-top: 0px !important;
border-radius: 0px;
...
...
components/admin/Users.vue
View file @
64beb39b
...
...
@@ -6,6 +6,8 @@ div
template(slot='title')
h4 <v-icon name='plus'/>
{{
$t
(
'
common.new_user
'
)
}}
el-form(inline)
el-form-item(:label="$t('common.username')")
el-input(v-model='new_user.username')
el-form-item(:label="$t('common.email')")
el-input(v-model='new_user.email')
el-form-item(:label="$t('common.admin')")
...
...
@@ -14,23 +16,26 @@ div
//- USERS LIST
el-table(:data='paginatedUsers' small)
el-table-column(label='Username')
template(slot-scope='data')
span(slot='reference')
{{
data
.
row
.
username
}}
el-table-column(label='Email')
template(slot-scope='data')
el-popover(trigger='hover' :content='data.row.description' width='400')
span(slot='reference')
{{
data
.
row
.
email
}}
el-table-column(:label="$t('common.actions')")
template(slot-scope='data')
div(v-if='data.row.id!==$auth.user.id')
el-button.mr-1(size='mini'
:type='data.row.is_active?"warning":"success"'
@click='toggle(data.row)')
{{
data
.
row
.
is_active
?
$t
(
'
common.deactivate
'
):
$t
(
'
common.activate
'
)
}}
el-button(size='mini'
:type='data.row.is_admin?"danger":"warning"'
@click='toggleAdmin(data.row)')
{{
data
.
row
.
is_admin
?
$t
(
'
admin.remove_admin
'
):
$t
(
'
common.admin
'
)
}}
el-button(size='mini'
type='danger'
@click='delete_user(data.row)')
{{
$t
(
'
admin.delete_user
'
)
}}
el-button-group
el-button(size='mini'
:type='data.row.is_active?"warning":"success"'
@click='toggle(data.row)')
{{
data
.
row
.
is_active
?
$t
(
'
common.deactivate
'
):
$t
(
'
common.activate
'
)
}}
el-button(size='mini'
:type='data.row.is_admin?"danger":"warning"'
@click='toggleAdmin(data.row)')
{{
data
.
row
.
is_admin
?
$t
(
'
admin.remove_admin
'
):
$t
(
'
common.admin
'
)
}}
el-button(size='mini'
type='danger'
@click='delete_user(data.row)')
{{
$t
(
'
admin.delete_user
'
)
}}
div(v-else)
span
{{
$t
(
'
common.me
'
)
}}
...
...
locales/it.js
View file @
64beb39b
...
...
@@ -48,7 +48,8 @@ export default {
enable
:
'
Abilita
'
,
disable
:
'
Disabilita
'
,
me
:
'
Sei te
'
,
password_updated
:
'
Password modificata!
'
password_updated
:
'
Password modificata!
'
,
username
:
'
Nickname
'
},
login
:
{
...
...
pages/admin.vue
View file @
64beb39b
<
template
lang=
"pug"
>
el-card
el-card
#admin
nuxt-link.float-right(to='/')
v-icon(name='times' color='red')
h5
{{
$t
(
'
common.admin
'
)
}}
...
...
server/api/models/user.js
View file @
64beb39b
'
use strict
'
const
bcrypt
=
require
(
'
bcryptjs
'
)
const
crypto
=
require
(
'
crypto
'
)
const
util
=
require
(
'
util
'
)
const
generateKeyPair
=
util
.
promisify
(
crypto
.
generateKeyPair
)
module
.
exports
=
(
sequelize
,
DataTypes
)
=>
{
const
user
=
sequelize
.
define
(
'
user
'
,
{
...
...
@@ -20,7 +24,8 @@ module.exports = (sequelize, DataTypes) => {
password
:
DataTypes
.
STRING
,
recover_code
:
DataTypes
.
STRING
,
is_admin
:
DataTypes
.
BOOLEAN
,
is_active
:
DataTypes
.
BOOLEAN
is_active
:
DataTypes
.
BOOLEAN
,
rsa
:
DataTypes
.
JSONB
},
{
scopes
:
{
withoutPassword
:
{
...
...
@@ -48,5 +53,22 @@ module.exports = (sequelize, DataTypes) => {
}
})
user
.
beforeCreate
(
async
(
user
,
options
)
=>
{
// generate rsa keys
console
.
error
(
'
generate rsa key
'
)
const
rsa
=
await
generateKeyPair
(
'
rsa
'
,
{
modulusLength
:
4096
,
publicKeyEncoding
:
{
type
:
'
spki
'
,
format
:
'
pem
'
},
privateKeyEncoding
:
{
type
:
'
pkcs8
'
,
format
:
'
pem
'
}
})
user
.
rsa
=
rsa
})
return
user
};
server/federation/index.js
View file @
64beb39b
...
...
@@ -8,7 +8,6 @@ router.get('/u/:name', async (req, res) => {
if
(
!
name
)
return
res
.
status
(
400
).
send
(
'
Bad request.
'
)
const
user
=
await
User
.
findOne
({
where
:
{
username
:
name
}})
if
(
!
user
)
return
res
.
status
(
404
).
send
(
`No record found for
${
name
}
`
)
const
domain
=
'
local
'
const
ret
=
{
'
@context
'
:
[
'
https://www.w3.org/ns/activitystreams
'
,
...
...
@@ -22,7 +21,7 @@ router.get('/u/:name', async (req, res) => {
'
publicKey
'
:
{
'
id
'
:
`
${
config
.
baseurl
}
/federation/u/
${
name
}
#main-key`
,
'
owner
'
:
`
${
config
.
baseurl
}
/federation/u/
${
name
}
`
,
'
publicKeyPem
'
:
user
.
pubk
ey
'
publicKeyPem
'
:
user
.
rsa
.
publicK
ey
}
}
res
.
json
(
ret
)
...
...
server/migrations/20190729103119-add_rsa.js
0 → 100644
View file @
64beb39b
'
use strict
'
;
module
.
exports
=
{
up
:
(
queryInterface
,
Sequelize
)
=>
{
return
queryInterface
.
addColumn
(
'
users
'
,
'
rsa
'
,
{
type
:
Sequelize
.
JSONB
})
/*
Add altering commands here.
Return a promise to correctly handle asynchronicity.
Example:
return queryInterface.createTable('users', { id: Sequelize.INTEGER });
*/
},
down
:
(
queryInterface
,
Sequelize
)
=>
{
/*
Add reverting commands here.
Return a promise to correctly handle asynchronicity.
Example:
return queryInterface.dropTable('users');
*/
}
};
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