admin could add user, fix #14
This commit is contained in:
@@ -41,7 +41,8 @@ const it = {
|
||||
logout_ok: 'Uscita correttamente',
|
||||
copy: 'Copia',
|
||||
recover_password: 'Recupera password',
|
||||
new_password: 'Nuova password'
|
||||
new_password: 'Nuova password',
|
||||
new_user: 'Nuovo utente'
|
||||
},
|
||||
|
||||
login: {
|
||||
@@ -106,7 +107,7 @@ const it = {
|
||||
added_anon: 'Evento aggiunto, verrà confermato quanto prima.',
|
||||
where_description: `Dov'è il gancio? Se il posto non è presente, scrivilo e <b>premi invio</b>. `,
|
||||
confirmed: 'Evento confermato',
|
||||
not_found: 'Evento non trovato'
|
||||
not_found: 'Evento non trovato',
|
||||
},
|
||||
|
||||
admin: {
|
||||
|
||||
13
package.json
13
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "gancio",
|
||||
"version": "0.9.3",
|
||||
"version": "0.9.4",
|
||||
"description": "My well-made Nuxt.js project",
|
||||
"author": "lesion",
|
||||
"scripts": {
|
||||
@@ -12,6 +12,15 @@
|
||||
"migrate:dev": "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": {
|
||||
"gancio": "server/index.js"
|
||||
},
|
||||
@@ -56,7 +65,7 @@
|
||||
"@nuxtjs/eslint-config": "^0.0.1",
|
||||
"babel-eslint": "^10.0.1",
|
||||
"eslint": "^5.15.1",
|
||||
"eslint-config-prettier": "^4.3.0",
|
||||
"eslint-config-prettier": "^5.0.0",
|
||||
"eslint-config-standard": ">=12.0.0",
|
||||
"eslint-loader": "^2.1.2",
|
||||
"eslint-plugin-import": ">=2.17.3",
|
||||
|
||||
@@ -5,13 +5,25 @@
|
||||
v-icon(name='times' color='red')
|
||||
h5 {{$t('common.admin')}}
|
||||
|
||||
el-tabs(tabPosition='lef' v-model='tab')
|
||||
el-tabs(v-model='tab')
|
||||
|
||||
//- USERS
|
||||
el-tab-pane.pt-1
|
||||
template(slot='label')
|
||||
v-icon(name='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-column(label='Email')
|
||||
template(slot-scope='data')
|
||||
@@ -126,8 +138,14 @@ export default {
|
||||
events: [],
|
||||
loading: false,
|
||||
settings: {
|
||||
allow_registration: true,
|
||||
mastodon_instance: ''
|
||||
},
|
||||
new_user: {
|
||||
email: '',
|
||||
password: '',
|
||||
admin: false,
|
||||
},
|
||||
mastodon_instance: '',
|
||||
tab: "0",
|
||||
open: true
|
||||
}
|
||||
@@ -201,11 +219,27 @@ export default {
|
||||
this.$router.push(`/event/${id}`)
|
||||
},
|
||||
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);
|
||||
},
|
||||
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) {
|
||||
try {
|
||||
this.loading = true
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
v-icon(name='times' color='red')
|
||||
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')")
|
||||
el-input.mb-2(ref='email' v-model='user.email' type='email' required
|
||||
:placeholder='$t("common.email")' autocomplete='email' name='email')
|
||||
@@ -44,7 +44,7 @@ export default {
|
||||
...mapActions(['login']),
|
||||
async register () {
|
||||
try {
|
||||
const { user } = await this.$axios.$post('/user', this.user)
|
||||
const { user } = await this.$axios.$post('/user/register', this.user)
|
||||
Message({
|
||||
message: this.$t(`register.${user.is_admin ? 'admin_' : ''}complete`),
|
||||
type: 'success'
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import Vue from 'vue'
|
||||
import { Button, Select, Tag, Option, Table, FormItem, Card, Row, Col, Upload, Checkbox,
|
||||
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'
|
||||
import locale from 'element-ui/lib/locale'
|
||||
|
||||
@@ -13,6 +13,9 @@ locale.use(locales[process.env.locale])
|
||||
|
||||
export default () => {
|
||||
Vue.use(Button)
|
||||
Vue.use(Collapse)
|
||||
Vue.use(CollapseItem)
|
||||
Vue.use(Backtop)
|
||||
Vue.use(Divider)
|
||||
Vue.use(Image)
|
||||
Vue.use(Step)
|
||||
|
||||
@@ -39,13 +39,6 @@ const Auth = {
|
||||
if (req.user.is_admin && req.user.is_active) return next()
|
||||
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) {
|
||||
const n_users = await User.count()
|
||||
try {
|
||||
@@ -243,6 +244,16 @@ const userController = {
|
||||
} catch (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
|
||||
})
|
||||
|
||||
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
|
||||
api.post('/auth/login', userController.login)
|
||||
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/recover_password', userController.updatePasswordWithRecoverCode)
|
||||
|
||||
api
|
||||
.route('/user')
|
||||
// register
|
||||
.post(userController.register)
|
||||
// get current user
|
||||
// .get(isAuth, userController.current)
|
||||
// update user (eg. confirm)
|
||||
.put(jwt, isAuth, isAdmin, userController.update)
|
||||
// register and add users
|
||||
api.post('/user/register', userController.register)
|
||||
api.post('/user', jwt, isAuth, isAdmin, userController.create)
|
||||
|
||||
// update user (disable/)
|
||||
api.put('/user', jwt, isAuth, isAdmin, userController.update)
|
||||
|
||||
// get all users
|
||||
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..)
|
||||
api.put('/place', jwt, isAuth, isAdmin, eventController.updatePlace)
|
||||
|
||||
api
|
||||
.route('/user/event')
|
||||
// add event
|
||||
.post(jwt, fillUser, upload.single('image'), userController.addEvent)
|
||||
api.post('/user/event', jwt, fillUser, upload.single('image'), userController.addEvent)
|
||||
|
||||
// update event
|
||||
.put(jwt, isAuth, upload.single('image'), userController.updateEvent)
|
||||
api.put('/user/event', jwt, isAuth, upload.single('image'), userController.updateEvent)
|
||||
|
||||
// remove event
|
||||
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)
|
||||
|
||||
// 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
|
||||
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 settingsController = require('./api/controller/settings')
|
||||
const config = require('./config.js')
|
||||
@@ -54,7 +54,6 @@ async function notify() {
|
||||
|
||||
let interval
|
||||
function startLoop(seconds) {
|
||||
console.error('starting notifier loop')
|
||||
interval = setInterval(notify, seconds * 1000)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user