user rsa key for federation
This commit is contained in:
@@ -25,10 +25,14 @@ html, body {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
.el-card {
|
.el-card {
|
||||||
max-width: 670px;
|
max-width: 630px;
|
||||||
margin: 30px auto;
|
margin: 30px auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#admin.el-card {
|
||||||
|
max-width: 850px;
|
||||||
|
}
|
||||||
|
|
||||||
.el-dialog {
|
.el-dialog {
|
||||||
margin-top: 0px !important;
|
margin-top: 0px !important;
|
||||||
border-radius: 0px;
|
border-radius: 0px;
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ div
|
|||||||
template(slot='title')
|
template(slot='title')
|
||||||
h4 <v-icon name='plus'/> {{$t('common.new_user')}}
|
h4 <v-icon name='plus'/> {{$t('common.new_user')}}
|
||||||
el-form(inline)
|
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-form-item(:label="$t('common.email')")
|
||||||
el-input(v-model='new_user.email')
|
el-input(v-model='new_user.email')
|
||||||
el-form-item(:label="$t('common.admin')")
|
el-form-item(:label="$t('common.admin')")
|
||||||
@@ -14,23 +16,26 @@ div
|
|||||||
|
|
||||||
//- USERS LIST
|
//- USERS LIST
|
||||||
el-table(:data='paginatedUsers' small)
|
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')
|
el-table-column(label='Email')
|
||||||
template(slot-scope='data')
|
template(slot-scope='data')
|
||||||
el-popover(trigger='hover' :content='data.row.description' width='400')
|
el-popover(trigger='hover' :content='data.row.description' width='400')
|
||||||
span(slot='reference') {{data.row.email}}
|
span(slot='reference') {{data.row.email}}
|
||||||
|
|
||||||
el-table-column(:label="$t('common.actions')")
|
el-table-column(:label="$t('common.actions')")
|
||||||
template(slot-scope='data')
|
template(slot-scope='data')
|
||||||
div(v-if='data.row.id!==$auth.user.id')
|
div(v-if='data.row.id!==$auth.user.id')
|
||||||
el-button.mr-1(size='mini'
|
el-button-group
|
||||||
:type='data.row.is_active?"warning":"success"'
|
el-button(size='mini'
|
||||||
@click='toggle(data.row)') {{data.row.is_active?$t('common.deactivate'):$t('common.activate')}}
|
:type='data.row.is_active?"warning":"success"'
|
||||||
el-button(size='mini'
|
@click='toggle(data.row)') {{data.row.is_active?$t('common.deactivate'):$t('common.activate')}}
|
||||||
:type='data.row.is_admin?"danger":"warning"'
|
el-button(size='mini'
|
||||||
@click='toggleAdmin(data.row)') {{data.row.is_admin?$t('admin.remove_admin'):$t('common.admin')}}
|
:type='data.row.is_admin?"danger":"warning"'
|
||||||
el-button(size='mini'
|
@click='toggleAdmin(data.row)') {{data.row.is_admin?$t('admin.remove_admin'):$t('common.admin')}}
|
||||||
type='danger'
|
el-button(size='mini'
|
||||||
@click='delete_user(data.row)') {{$t('admin.delete_user')}}
|
type='danger'
|
||||||
|
@click='delete_user(data.row)') {{$t('admin.delete_user')}}
|
||||||
div(v-else)
|
div(v-else)
|
||||||
span {{$t('common.me')}}
|
span {{$t('common.me')}}
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,8 @@ export default {
|
|||||||
enable: 'Abilita',
|
enable: 'Abilita',
|
||||||
disable: 'Disabilita',
|
disable: 'Disabilita',
|
||||||
me: 'Sei te',
|
me: 'Sei te',
|
||||||
password_updated: 'Password modificata!'
|
password_updated: 'Password modificata!',
|
||||||
|
username: 'Nickname'
|
||||||
},
|
},
|
||||||
|
|
||||||
login: {
|
login: {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<template lang="pug">
|
<template lang="pug">
|
||||||
el-card
|
el-card#admin
|
||||||
nuxt-link.float-right(to='/')
|
nuxt-link.float-right(to='/')
|
||||||
v-icon(name='times' color='red')
|
v-icon(name='times' color='red')
|
||||||
h5 {{$t('common.admin')}}
|
h5 {{$t('common.admin')}}
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
'use strict'
|
'use strict'
|
||||||
const bcrypt = require('bcryptjs')
|
const bcrypt = require('bcryptjs')
|
||||||
|
const crypto = require('crypto')
|
||||||
|
const util = require('util')
|
||||||
|
|
||||||
|
const generateKeyPair = util.promisify(crypto.generateKeyPair)
|
||||||
|
|
||||||
module.exports = (sequelize, DataTypes) => {
|
module.exports = (sequelize, DataTypes) => {
|
||||||
const user = sequelize.define('user', {
|
const user = sequelize.define('user', {
|
||||||
@@ -20,7 +24,8 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
password: DataTypes.STRING,
|
password: DataTypes.STRING,
|
||||||
recover_code: DataTypes.STRING,
|
recover_code: DataTypes.STRING,
|
||||||
is_admin: DataTypes.BOOLEAN,
|
is_admin: DataTypes.BOOLEAN,
|
||||||
is_active: DataTypes.BOOLEAN
|
is_active: DataTypes.BOOLEAN,
|
||||||
|
rsa: DataTypes.JSONB
|
||||||
}, {
|
}, {
|
||||||
scopes: {
|
scopes: {
|
||||||
withoutPassword: {
|
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
|
return user
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ router.get('/u/:name', async (req, res) => {
|
|||||||
if (!name) return res.status(400).send('Bad request.')
|
if (!name) return res.status(400).send('Bad request.')
|
||||||
const user = await User.findOne({where: { username: name }})
|
const user = await User.findOne({where: { username: name }})
|
||||||
if (!user) return res.status(404).send(`No record found for ${name}`)
|
if (!user) return res.status(404).send(`No record found for ${name}`)
|
||||||
const domain = 'local'
|
|
||||||
const ret = {
|
const ret = {
|
||||||
'@context': [
|
'@context': [
|
||||||
'https://www.w3.org/ns/activitystreams',
|
'https://www.w3.org/ns/activitystreams',
|
||||||
@@ -22,7 +21,7 @@ router.get('/u/:name', async (req, res) => {
|
|||||||
'publicKey': {
|
'publicKey': {
|
||||||
'id': `${config.baseurl}/federation/u/${name}#main-key`,
|
'id': `${config.baseurl}/federation/u/${name}#main-key`,
|
||||||
'owner': `${config.baseurl}/federation/u/${name}`,
|
'owner': `${config.baseurl}/federation/u/${name}`,
|
||||||
'publicKeyPem': user.pubkey
|
'publicKeyPem': user.rsa.publicKey
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res.json(ret)
|
res.json(ret)
|
||||||
|
|||||||
26
server/migrations/20190729103119-add_rsa.js
Normal file
26
server/migrations/20190729103119-add_rsa.js
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
'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');
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user