Merge branch 'dev'
This commit is contained in:
@@ -29,9 +29,17 @@ git clone https://framagit.org/les/gancio
|
|||||||
yarn
|
yarn
|
||||||
```
|
```
|
||||||
|
|
||||||
4. Hacking
|
4. Run db migrations
|
||||||
|
```bash
|
||||||
|
./node_modules/.bin/sequelize db:migrate
|
||||||
|
```
|
||||||
|
|
||||||
|
5. Hacking
|
||||||
```bash
|
```bash
|
||||||
yarn dev
|
yarn dev
|
||||||
```
|
```
|
||||||
|
|
||||||
Please use the [issue board](https://framagit.org/les/gancio/-/boards) and the [forum](https://framavox.org/g/hMXTDgtJ/gancio) to discuss any modification.
|
> warning "Warning"
|
||||||
|
> You need to register a first user, this will be an active administrator!
|
||||||
|
|
||||||
|
Please use the [issue board](https://framagit.org/les/gancio/-/boards) and the [forum](https://framavox.org/g/hMXTDgtJ/gancio) to discuss any modification.
|
||||||
|
|||||||
@@ -101,7 +101,8 @@
|
|||||||
"register": {
|
"register": {
|
||||||
"description": "I movimenti hanno bisogno di organizzarsi e autofinanziarsi. <br/>Questo è un dono per voi, usatelo solo per eventi non commerciali e ovviamente antifascisti, antisessisti, antirazzisti. \n <br/>Prima di poter pubblicare <strong>dobbiamo approvare l'account</strong>, considera che <strong>dietro questo sito ci sono delle persone</strong> di\n carne e sangue, scrivici quindi due righe per farci capire che eventi vorresti pubblicare.",
|
"description": "I movimenti hanno bisogno di organizzarsi e autofinanziarsi. <br/>Questo è un dono per voi, usatelo solo per eventi non commerciali e ovviamente antifascisti, antisessisti, antirazzisti. \n <br/>Prima di poter pubblicare <strong>dobbiamo approvare l'account</strong>, considera che <strong>dietro questo sito ci sono delle persone</strong> di\n carne e sangue, scrivici quindi due righe per farci capire che eventi vorresti pubblicare.",
|
||||||
"error": "Errore: ",
|
"error": "Errore: ",
|
||||||
"complete": "Confermeremo la registrazione quanto prima."
|
"complete": "Confermeremo la registrazione quanto prima.",
|
||||||
|
"first_user": "Amministratore creato e attivo"
|
||||||
},
|
},
|
||||||
"event": {
|
"event": {
|
||||||
"anon": "Anonimo",
|
"anon": "Anonimo",
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
import { mapState } from 'vuex'
|
import { mapState } from 'vuex'
|
||||||
import { Message } from 'element-ui'
|
import { Message } from 'element-ui'
|
||||||
import get from 'lodash/get'
|
import get from 'lodash/get'
|
||||||
|
import linkify from 'linkifyjs'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Register',
|
name: 'Register',
|
||||||
@@ -46,19 +47,21 @@ export default {
|
|||||||
this.$refs.email.focus()
|
this.$refs.email.focus()
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
close () {
|
|
||||||
this.$router.replace('/')
|
|
||||||
},
|
|
||||||
async register () {
|
async register () {
|
||||||
this.loading = true
|
|
||||||
try {
|
try {
|
||||||
await this.$axios.$post('/user/register', this.user)
|
if (!linkify.test(this.user.email, 'email')) {
|
||||||
|
throw new Error('Invalid email')
|
||||||
|
}
|
||||||
|
this.loading = true
|
||||||
|
const user = await this.$axios.$post('/user/register', this.user)
|
||||||
|
// this is the first user registered
|
||||||
|
const first_user = user && user.is_admin && user.is_active
|
||||||
Message({
|
Message({
|
||||||
showClose: true,
|
showClose: true,
|
||||||
message: this.$t('register.complete'),
|
message: first_user ? this.$t('register.first_user') : this.$t('register.complete'),
|
||||||
type: 'success'
|
type: 'success'
|
||||||
})
|
})
|
||||||
this.close()
|
this.$router.replace('/')
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const error = get(e, 'response.data.errors[0].message', String(e))
|
const error = get(e, 'response.data.errors[0].message', String(e))
|
||||||
Message({
|
Message({
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ const mail = require('../mail')
|
|||||||
const { user: User } = require('../models')
|
const { user: User } = require('../models')
|
||||||
const settingsController = require('./settings')
|
const settingsController = require('./settings')
|
||||||
const debug = require('debug')('user:controller')
|
const debug = require('debug')('user:controller')
|
||||||
|
const linkify = require('linkifyjs')
|
||||||
|
|
||||||
const userController = {
|
const userController = {
|
||||||
|
|
||||||
@@ -79,14 +80,22 @@ const userController = {
|
|||||||
if (!settingsController.settings.allow_registration) { return res.sendStatus(404) }
|
if (!settingsController.settings.allow_registration) { return res.sendStatus(404) }
|
||||||
const n_users = await User.count()
|
const n_users = await User.count()
|
||||||
try {
|
try {
|
||||||
|
req.body.recover_code = crypto.randomBytes(16).toString('hex')
|
||||||
|
|
||||||
// the first registered user will be an active admin
|
// the first registered user will be an active admin
|
||||||
if (n_users === 0) {
|
if (n_users === 0) {
|
||||||
req.body.is_active = req.body.is_admin = true
|
req.body.is_active = req.body.is_admin = true
|
||||||
} else {
|
const user = await User.create(req.body)
|
||||||
req.body.is_active = false
|
return res.json(user)
|
||||||
|
}
|
||||||
|
|
||||||
|
req.body.is_active = false
|
||||||
|
|
||||||
|
// check email
|
||||||
|
if (!linkify.test(req.body.email, 'email')) {
|
||||||
|
return res.status(404).json('Invalid email')
|
||||||
}
|
}
|
||||||
|
|
||||||
req.body.recover_code = crypto.randomBytes(16).toString('hex')
|
|
||||||
debug('Register user ', req.body.email)
|
debug('Register user ', req.body.email)
|
||||||
const user = await User.create(req.body)
|
const user = await User.create(req.body)
|
||||||
debug(`Sending registration email to ${user.email}`)
|
debug(`Sending registration email to ${user.email}`)
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING,
|
||||||
unique: { msg: 'error.email_taken' },
|
unique: { msg: 'error.email_taken' },
|
||||||
validate: {
|
validate: {
|
||||||
isEmail: true,
|
|
||||||
notEmpty: true
|
notEmpty: true
|
||||||
},
|
},
|
||||||
index: true,
|
index: true,
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ async function setupQuestionnaire (is_docker, db) {
|
|||||||
}
|
}
|
||||||
questions.push({
|
questions.push({
|
||||||
name: 'admin.email',
|
name: 'admin.email',
|
||||||
message: 'Admin email (a first user with this username will be created, also used as sender address)',
|
message: 'Admin email',
|
||||||
default: options => {
|
default: options => {
|
||||||
const baseurl = new url.URL(options.baseurl)
|
const baseurl = new url.URL(options.baseurl)
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create admin user
|
// create admin user
|
||||||
consola.info('Create admin user', admin)
|
consola.info(`Create admin with email: ${admin.email}`)
|
||||||
await db.user.create({
|
await db.user.create({
|
||||||
email: admin.email,
|
email: admin.email,
|
||||||
password: admin.password,
|
password: admin.password,
|
||||||
|
|||||||
Reference in New Issue
Block a user