admin could add user, fix #14
This commit is contained in:
@@ -41,7 +41,8 @@ const it = {
|
|||||||
logout_ok: 'Uscita correttamente',
|
logout_ok: 'Uscita correttamente',
|
||||||
copy: 'Copia',
|
copy: 'Copia',
|
||||||
recover_password: 'Recupera password',
|
recover_password: 'Recupera password',
|
||||||
new_password: 'Nuova password'
|
new_password: 'Nuova password',
|
||||||
|
new_user: 'Nuovo utente'
|
||||||
},
|
},
|
||||||
|
|
||||||
login: {
|
login: {
|
||||||
@@ -106,7 +107,7 @@ const it = {
|
|||||||
added_anon: 'Evento aggiunto, verrà confermato quanto prima.',
|
added_anon: 'Evento aggiunto, verrà confermato quanto prima.',
|
||||||
where_description: `Dov'è il gancio? Se il posto non è presente, scrivilo e <b>premi invio</b>. `,
|
where_description: `Dov'è il gancio? Se il posto non è presente, scrivilo e <b>premi invio</b>. `,
|
||||||
confirmed: 'Evento confermato',
|
confirmed: 'Evento confermato',
|
||||||
not_found: 'Evento non trovato'
|
not_found: 'Evento non trovato',
|
||||||
},
|
},
|
||||||
|
|
||||||
admin: {
|
admin: {
|
||||||
|
|||||||
13
package.json
13
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "gancio",
|
"name": "gancio",
|
||||||
"version": "0.9.3",
|
"version": "0.9.4",
|
||||||
"description": "My well-made Nuxt.js project",
|
"description": "My well-made Nuxt.js project",
|
||||||
"author": "lesion",
|
"author": "lesion",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -12,6 +12,15 @@
|
|||||||
"migrate:dev": "sequelize db:migrate",
|
"migrate:dev": "sequelize db:migrate",
|
||||||
"migrate": "NODE_ENV=production sequelize db:migrate"
|
"migrate": "NODE_ENV=production sequelize db:migrate"
|
||||||
},
|
},
|
||||||
|
"license": "AGPL-3.0",
|
||||||
|
"bugs": {
|
||||||
|
"email": "lesion@autistici.org",
|
||||||
|
"url": "https://git.lattuga.net/cisti/gancio/issues"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://git.lattuga.net/cisti/gancio.git"
|
||||||
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"gancio": "server/index.js"
|
"gancio": "server/index.js"
|
||||||
},
|
},
|
||||||
@@ -56,7 +65,7 @@
|
|||||||
"@nuxtjs/eslint-config": "^0.0.1",
|
"@nuxtjs/eslint-config": "^0.0.1",
|
||||||
"babel-eslint": "^10.0.1",
|
"babel-eslint": "^10.0.1",
|
||||||
"eslint": "^5.15.1",
|
"eslint": "^5.15.1",
|
||||||
"eslint-config-prettier": "^4.3.0",
|
"eslint-config-prettier": "^5.0.0",
|
||||||
"eslint-config-standard": ">=12.0.0",
|
"eslint-config-standard": ">=12.0.0",
|
||||||
"eslint-loader": "^2.1.2",
|
"eslint-loader": "^2.1.2",
|
||||||
"eslint-plugin-import": ">=2.17.3",
|
"eslint-plugin-import": ">=2.17.3",
|
||||||
|
|||||||
@@ -5,13 +5,25 @@
|
|||||||
v-icon(name='times' color='red')
|
v-icon(name='times' color='red')
|
||||||
h5 {{$t('common.admin')}}
|
h5 {{$t('common.admin')}}
|
||||||
|
|
||||||
el-tabs(tabPosition='lef' v-model='tab')
|
el-tabs(v-model='tab')
|
||||||
|
|
||||||
//- USERS
|
//- USERS
|
||||||
el-tab-pane.pt-1
|
el-tab-pane.pt-1
|
||||||
template(slot='label')
|
template(slot='label')
|
||||||
v-icon(name='users')
|
v-icon(name='users')
|
||||||
span.ml-1 {{$t('common.users')}}
|
span.ml-1 {{$t('common.users')}}
|
||||||
|
el-collapse
|
||||||
|
el-collapse-item
|
||||||
|
template(slot='title')
|
||||||
|
p {{$t('common.new_user')}}
|
||||||
|
el-form(inline)
|
||||||
|
el-form-item(:label="$t('common.email')")
|
||||||
|
el-input(v-model='new_user.email')
|
||||||
|
el-form-item(:label="$t('common.password')")
|
||||||
|
el-input(v-model='new_user.password' type='password')
|
||||||
|
el-form-item(:label="$t('common.admin')")
|
||||||
|
el-switch(v-model='new_user.admin')
|
||||||
|
el-button.float-right(@click='create_user' type='success' plain) {{$t('common.send')}}
|
||||||
el-table(:data='paginatedUsers' small)
|
el-table(:data='paginatedUsers' small)
|
||||||
el-table-column(label='Email')
|
el-table-column(label='Email')
|
||||||
template(slot-scope='data')
|
template(slot-scope='data')
|
||||||
@@ -126,8 +138,14 @@ export default {
|
|||||||
events: [],
|
events: [],
|
||||||
loading: false,
|
loading: false,
|
||||||
settings: {
|
settings: {
|
||||||
|
allow_registration: true,
|
||||||
|
mastodon_instance: ''
|
||||||
|
},
|
||||||
|
new_user: {
|
||||||
|
email: '',
|
||||||
|
password: '',
|
||||||
|
admin: false,
|
||||||
},
|
},
|
||||||
mastodon_instance: '',
|
|
||||||
tab: "0",
|
tab: "0",
|
||||||
open: true
|
open: true
|
||||||
}
|
}
|
||||||
@@ -201,11 +219,27 @@ export default {
|
|||||||
this.$router.push(`/event/${id}`)
|
this.$router.push(`/event/${id}`)
|
||||||
},
|
},
|
||||||
async associate_mastondon_instance () {
|
async associate_mastondon_instance () {
|
||||||
if (!this.mastodon_instance) return false
|
if (!this.settings.mastodon_instance) return false
|
||||||
|
|
||||||
const url = await this.$axios.$post('/settings/getauthurl', {instance: this.mastodon_instance})
|
const url = await this.$axios.$post('/settings/getauthurl', {instance: this.settings.mastodon_instance})
|
||||||
setTimeout( () => window.location.href=url, 100);
|
setTimeout( () => window.location.href=url, 100);
|
||||||
},
|
},
|
||||||
|
async create_user () {
|
||||||
|
try {
|
||||||
|
this.loading = true
|
||||||
|
const user = await this.$axios.$post('/user', this.new_user)
|
||||||
|
this.new_user = { email: '', password: '', is_admin: false }
|
||||||
|
Message({
|
||||||
|
type: 'success',
|
||||||
|
message: this.$t('user.create_ok')
|
||||||
|
})
|
||||||
|
} catch (e) {
|
||||||
|
Message({
|
||||||
|
type: 'error',
|
||||||
|
message: this.$t('user.error_create') + e
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
async confirm (id) {
|
async confirm (id) {
|
||||||
try {
|
try {
|
||||||
this.loading = true
|
this.loading = true
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
v-icon(name='times' color='red')
|
v-icon(name='times' color='red')
|
||||||
h5 {{$t('common.register')}}
|
h5 {{$t('common.register')}}
|
||||||
|
|
||||||
el-form(@submit.native.prevent='register' method='POST' action='/api/user')
|
el-form(@submit.native.prevent='register' method='POST' action='/api/user/register')
|
||||||
p(v-html="$t('register.description')")
|
p(v-html="$t('register.description')")
|
||||||
el-input.mb-2(ref='email' v-model='user.email' type='email' required
|
el-input.mb-2(ref='email' v-model='user.email' type='email' required
|
||||||
:placeholder='$t("common.email")' autocomplete='email' name='email')
|
:placeholder='$t("common.email")' autocomplete='email' name='email')
|
||||||
@@ -44,7 +44,7 @@ export default {
|
|||||||
...mapActions(['login']),
|
...mapActions(['login']),
|
||||||
async register () {
|
async register () {
|
||||||
try {
|
try {
|
||||||
const { user } = await this.$axios.$post('/user', this.user)
|
const { user } = await this.$axios.$post('/user/register', this.user)
|
||||||
Message({
|
Message({
|
||||||
message: this.$t(`register.${user.is_admin ? 'admin_' : ''}complete`),
|
message: this.$t(`register.${user.is_admin ? 'admin_' : ''}complete`),
|
||||||
type: 'success'
|
type: 'success'
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import { Button, Select, Tag, Option, Table, FormItem, Card, Row, Col, Upload, Checkbox,
|
import { Button, Select, Tag, Option, Table, FormItem, Card, Row, Col, Upload, Checkbox,
|
||||||
Form, Tabs, TabPane, Switch, Input, Loading, TimeSelect, Badge, ButtonGroup, Divider, Step, Steps,
|
Form, Tabs, TabPane, Switch, Input, Loading, TimeSelect, Badge, ButtonGroup, Divider, Step, Steps,
|
||||||
TableColumn, ColorPicker, Pagination, Popover, Tooltip, Dialog, Image,
|
TableColumn, ColorPicker, Pagination, Popover, Tooltip, Dialog, Image, Backtop, Collapse, CollapseItem,
|
||||||
Container, Footer, Timeline, TimelineItem, Menu, MenuItem } from 'element-ui'
|
Container, Footer, Timeline, TimelineItem, Menu, MenuItem } from 'element-ui'
|
||||||
import locale from 'element-ui/lib/locale'
|
import locale from 'element-ui/lib/locale'
|
||||||
|
|
||||||
@@ -13,6 +13,9 @@ locale.use(locales[process.env.locale])
|
|||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
Vue.use(Button)
|
Vue.use(Button)
|
||||||
|
Vue.use(Collapse)
|
||||||
|
Vue.use(CollapseItem)
|
||||||
|
Vue.use(Backtop)
|
||||||
Vue.use(Divider)
|
Vue.use(Divider)
|
||||||
Vue.use(Image)
|
Vue.use(Image)
|
||||||
Vue.use(Step)
|
Vue.use(Step)
|
||||||
|
|||||||
@@ -39,13 +39,6 @@ const Auth = {
|
|||||||
if (req.user.is_admin && req.user.is_active) return next()
|
if (req.user.is_admin && req.user.is_active) return next()
|
||||||
return res.status(403).send({ message: 'Admin needed' })
|
return res.status(403).send({ message: 'Admin needed' })
|
||||||
},
|
},
|
||||||
async adminOrFirstRun(req, res, next) {
|
|
||||||
if (req.user && req.user.is_admin && req.user.is_active) return next()
|
|
||||||
const settings = await Settings.settings()
|
|
||||||
if (!settings.firstRun) {
|
|
||||||
return next()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -217,6 +217,7 @@ const userController = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
async register(req, res) {
|
async register(req, res) {
|
||||||
const n_users = await User.count()
|
const n_users = await User.count()
|
||||||
try {
|
try {
|
||||||
@@ -243,6 +244,16 @@ const userController = {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
res.status(404).json(e)
|
res.status(404).json(e)
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async create(req, res) {
|
||||||
|
try {
|
||||||
|
req.body.is_active = true
|
||||||
|
const user = await User.create(req.body)
|
||||||
|
res.json(user)
|
||||||
|
} catch (e) {
|
||||||
|
res.status(404).json(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,17 +24,6 @@ const jwt = expressJwt({
|
|||||||
credentialsRequired: false
|
credentialsRequired: false
|
||||||
})
|
})
|
||||||
|
|
||||||
function errorHandler(fn) {
|
|
||||||
return async (req, res) => {
|
|
||||||
try {
|
|
||||||
await fn(req, res)
|
|
||||||
} catch (e) {
|
|
||||||
console.error(String(e))
|
|
||||||
return res.status(500).json(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// AUTH
|
// AUTH
|
||||||
api.post('/auth/login', userController.login)
|
api.post('/auth/login', userController.login)
|
||||||
api.post('/auth/logout', userController.logout)
|
api.post('/auth/logout', userController.logout)
|
||||||
@@ -44,14 +33,12 @@ api.post('/user/recover', userController.forgotPassword)
|
|||||||
api.post('/user/check_recover_code', userController.checkRecoverCode)
|
api.post('/user/check_recover_code', userController.checkRecoverCode)
|
||||||
api.post('/user/recover_password', userController.updatePasswordWithRecoverCode)
|
api.post('/user/recover_password', userController.updatePasswordWithRecoverCode)
|
||||||
|
|
||||||
api
|
// register and add users
|
||||||
.route('/user')
|
api.post('/user/register', userController.register)
|
||||||
// register
|
api.post('/user', jwt, isAuth, isAdmin, userController.create)
|
||||||
.post(userController.register)
|
|
||||||
// get current user
|
// update user (disable/)
|
||||||
// .get(isAuth, userController.current)
|
api.put('/user', jwt, isAuth, isAdmin, userController.update)
|
||||||
// update user (eg. confirm)
|
|
||||||
.put(jwt, isAuth, isAdmin, userController.update)
|
|
||||||
|
|
||||||
// get all users
|
// get all users
|
||||||
api.get('/users', jwt, isAuth, isAdmin, userController.getAll)
|
api.get('/users', jwt, isAuth, isAdmin, userController.getAll)
|
||||||
@@ -62,12 +49,11 @@ api.put('/tag', jwt, isAuth, isAdmin, eventController.updateTag)
|
|||||||
// update a place (modify address..)
|
// update a place (modify address..)
|
||||||
api.put('/place', jwt, isAuth, isAdmin, eventController.updatePlace)
|
api.put('/place', jwt, isAuth, isAdmin, eventController.updatePlace)
|
||||||
|
|
||||||
api
|
// add event
|
||||||
.route('/user/event')
|
api.post('/user/event', jwt, fillUser, upload.single('image'), userController.addEvent)
|
||||||
// add event
|
|
||||||
.post(jwt, fillUser, upload.single('image'), userController.addEvent)
|
// update event
|
||||||
// update event
|
api.put('/user/event', jwt, isAuth, upload.single('image'), userController.updateEvent)
|
||||||
.put(jwt, isAuth, upload.single('image'), userController.updateEvent)
|
|
||||||
|
|
||||||
// remove event
|
// remove event
|
||||||
api.delete('/user/event/:id', jwt, isAuth, userController.delEvent)
|
api.delete('/user/event/:id', jwt, isAuth, userController.delEvent)
|
||||||
@@ -96,7 +82,8 @@ api.get('/event/unconfirm/:event_id', jwt, isAuth, isAdmin, eventController.unco
|
|||||||
api.get('/export/:type', exportController.export)
|
api.get('/export/:type', exportController.export)
|
||||||
|
|
||||||
// get events in this range
|
// get events in this range
|
||||||
api.get('/event/:month/:year', errorHandler(eventController.getAll))
|
api.get('/event/:month/:year', eventController.getAll)
|
||||||
|
// api.get('/event/:month/:year', eventController.getAfter)
|
||||||
|
|
||||||
// mastodon oauth auth
|
// mastodon oauth auth
|
||||||
api.post('/settings/getauthurl', jwt, isAuth, isAdmin, settingsController.getAuthURL)
|
api.post('/settings/getauthurl', jwt, isAuth, isAdmin, settingsController.getAuthURL)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const mail = require('./mail')
|
const mail = require('./api/mail')
|
||||||
const bot = require('./api/controller/bot')
|
const bot = require('./api/controller/bot')
|
||||||
const settingsController = require('./api/controller/settings')
|
const settingsController = require('./api/controller/settings')
|
||||||
const config = require('./config.js')
|
const config = require('./config.js')
|
||||||
@@ -54,7 +54,6 @@ async function notify() {
|
|||||||
|
|
||||||
let interval
|
let interval
|
||||||
function startLoop(seconds) {
|
function startLoop(seconds) {
|
||||||
console.error('starting notifier loop')
|
|
||||||
interval = setInterval(notify, seconds * 1000)
|
interval = setInterval(notify, seconds * 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user