Merge remote-tracking branch 'upstream/develop' into feature/theming2
* upstream/develop: Fix color fallback order Use console.warn instead of console.log Get rid of mutation_types file, use inline approach. Minor fixes Add fallback color rule. Change english validation error messages Clean up the code Validate name presence on client-side as well Better styling for client-side validation. Add I18n for validation errors. Fix broken ToS link. Fix linter errors Add client validation for registration form Use Array.reduce instead of lodash.reduce Humanize validation errors returned on registration Added user option to hide instance-specific panel, rearranged config screen to better categorize it / adjustments to language selector fix
This commit is contained in:
commit
3452864260
14 changed files with 271 additions and 1056 deletions
12
src/modules/errors.js
Normal file
12
src/modules/errors.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
import { capitalize } from 'lodash'
|
||||
|
||||
export function humanizeErrors (errors) {
|
||||
return Object.entries(errors).reduce((errs, [k, val]) => {
|
||||
let message = val.reduce((acc, message) => {
|
||||
let key = capitalize(k.replace(/_/g, ' '))
|
||||
return acc + [key, message].join(' ') + '. '
|
||||
}, '')
|
||||
return [...errs, message]
|
||||
}, [])
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
import backendInteractorService from '../services/backend_interactor_service/backend_interactor_service.js'
|
||||
import { compact, map, each, merge } from 'lodash'
|
||||
import { set } from 'vue'
|
||||
import oauthApi from '../services/new_api/oauth'
|
||||
import {humanizeErrors} from './errors'
|
||||
|
||||
// TODO: Unify with mergeOrAdd in statuses.js
|
||||
export const mergeOrAdd = (arr, obj, item) => {
|
||||
|
@ -46,15 +48,28 @@ export const mutations = {
|
|||
setColor (state, { user: {id}, highlighted }) {
|
||||
const user = state.usersObject[id]
|
||||
set(user, 'highlight', highlighted)
|
||||
},
|
||||
signUpPending (state) {
|
||||
state.signUpPending = true
|
||||
state.signUpErrors = []
|
||||
},
|
||||
signUpSuccess (state) {
|
||||
state.signUpPending = false
|
||||
},
|
||||
signUpFailure (state, errors) {
|
||||
state.signUpPending = false
|
||||
state.signUpErrors = errors
|
||||
}
|
||||
}
|
||||
|
||||
export const defaultState = {
|
||||
loggingIn: false,
|
||||
lastLoginName: false,
|
||||
currentUser: false,
|
||||
loggingIn: false,
|
||||
users: [],
|
||||
usersObject: {}
|
||||
usersObject: {},
|
||||
signUpPending: false,
|
||||
signUpErrors: []
|
||||
}
|
||||
|
||||
const users = {
|
||||
|
@ -80,6 +95,34 @@ const users = {
|
|||
store.commit('setUserForStatus', status)
|
||||
})
|
||||
},
|
||||
async signUp (store, userInfo) {
|
||||
store.commit('signUpPending')
|
||||
|
||||
let rootState = store.rootState
|
||||
|
||||
let response = await rootState.api.backendInteractor.register(userInfo)
|
||||
if (response.ok) {
|
||||
const data = {
|
||||
oauth: rootState.oauth,
|
||||
instance: rootState.instance.server
|
||||
}
|
||||
let app = await oauthApi.getOrCreateApp(data)
|
||||
let result = await oauthApi.getTokenWithCredentials({
|
||||
app,
|
||||
instance: data.instance,
|
||||
username: userInfo.username,
|
||||
password: userInfo.password
|
||||
})
|
||||
store.commit('signUpSuccess')
|
||||
store.commit('setToken', result.access_token)
|
||||
store.dispatch('loginUser', result.access_token)
|
||||
} else {
|
||||
let data = await response.json()
|
||||
let errors = humanizeErrors(JSON.parse(data.error))
|
||||
store.commit('signUpFailure', errors)
|
||||
throw Error(errors)
|
||||
}
|
||||
},
|
||||
logout (store) {
|
||||
store.commit('clearCurrentUser')
|
||||
store.commit('setToken', false)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue