mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
* invite codes refactor typo * lint fixes * remove duplicate initeCodes on User * fix typo * clean permissionMiddleware * dummy permissions * separate validateInviteCode call * permissions group & user * test validateInviteCode + adjustments * more validateInviteCode fixes * missing test * generatePersonalInviteCode * generateGroupInviteCode * old tests * lint fixes * more lint fixes * fix validateInviteCode * fix redeemInviteCode, fix signup * fix all tests * fix lint * uniform types in config * test & fix invalidateInviteCode * cleanup test * fix & test redeemInviteCode * permissions * fix Group->inviteCodes * more cleanup * improve tests * fix code generation * cleanup * order inviteCodes result on User and Group * lint * test max invite codes + fix * better description of collision * tests: properly define group ids * reused old group query * reuse old Groupmembers query * remove duplicate skip * update comment * fix uniqueInviteCode * fix test * fix lint * Get invite codes * Show invitation data in registration * Add invitation list to menu (WIP) * Add mutations, add CreateInvitation, some fixes * Improve style, fix long comments * Lock scrolling when popover is open, but prevent layout change * small fixes * instant updates * Introduce config for link limit; add texts, layout changes * Validate comment length * Improve layout * Add message to copied link * Add invite link section to group settings * Handle hidden groups * Add menu entry for group invite links * Fix locale * hotfix invite codes * Add copy messages * More styling (WIP) * Design update * Don't forget user state * Localize placeholder * Add locale * Instant updates for group invites * fix registration with invite code * Fix text overflow * Fix instant updates * Overhaul styles, add locales, add heading * Add test and snapshot for CreateInvitation * Improve accessability; add invitation test * Add tests for InvitationList * Fix locales * Round plus button * Fix tests * Fix tests * fix locales * fix linting * Don't show name of hidden group in invite message * Add more tests * Update webapp/locales/de.json Co-authored-by: Ulf Gebhardt <ulf.gebhardt@webcraft-media.de> * Update webapp/locales/de.json Co-authored-by: Ulf Gebhardt <ulf.gebhardt@webcraft-media.de> --------- Co-authored-by: Ulf Gebhardt <ulf.gebhardt@webcraft-media.de> Co-authored-by: Wolfgang Huß <wolle.huss@pjannto.com>
125 lines
2.9 KiB
JavaScript
125 lines
2.9 KiB
JavaScript
import gql from 'graphql-tag'
|
|
import { VERSION } from '~/constants/terms-and-conditions-version.js'
|
|
import { currentUserQuery } from '~/graphql/User'
|
|
import Cookie from 'universal-cookie'
|
|
import metadata from '~/constants/metadata'
|
|
|
|
const cookies = new Cookie()
|
|
|
|
export const state = () => {
|
|
return {
|
|
user: null,
|
|
token: null,
|
|
pending: false,
|
|
}
|
|
}
|
|
|
|
export const mutations = {
|
|
SET_USER(state, user) {
|
|
state.user = user || null
|
|
},
|
|
SET_USER_PARTIAL(state, user) {
|
|
state.user = { ...state.user, ...user }
|
|
},
|
|
SET_TOKEN(state, token) {
|
|
state.token = token || null
|
|
},
|
|
SET_PENDING(state, pending) {
|
|
state.pending = pending
|
|
},
|
|
}
|
|
|
|
export const getters = {
|
|
isAuthenticated(state) {
|
|
return !!state.token
|
|
},
|
|
isLoggedIn(state) {
|
|
return !!(state.user && state.token)
|
|
},
|
|
pending(state) {
|
|
return !!state.pending
|
|
},
|
|
isAdmin(state) {
|
|
return !!state.user && state.user.role === 'admin'
|
|
},
|
|
isModerator(state) {
|
|
return !!state.user && (state.user.role === 'admin' || state.user.role === 'moderator')
|
|
},
|
|
user(state) {
|
|
return state.user || {}
|
|
},
|
|
token(state) {
|
|
return state.token
|
|
},
|
|
termsAndConditionsAgreed(state) {
|
|
return state.user && state.user.termsAndConditionsAgreedVersion === VERSION
|
|
},
|
|
}
|
|
|
|
export const actions = {
|
|
async init({ commit, dispatch }) {
|
|
if (!process.server) {
|
|
return
|
|
}
|
|
const token = this.app.$apolloHelpers.getToken()
|
|
if (!token) {
|
|
return
|
|
}
|
|
commit('SET_TOKEN', token)
|
|
await dispatch('fetchCurrentUser')
|
|
},
|
|
|
|
async check({ commit, dispatch, getters }) {
|
|
if (!this.app.$apolloHelpers.getToken()) {
|
|
await dispatch('logout')
|
|
}
|
|
return getters.isLoggedIn
|
|
},
|
|
|
|
async fetchCurrentUser({ commit, dispatch }) {
|
|
const client = this.app.apolloProvider.defaultClient
|
|
const {
|
|
data: { currentUser },
|
|
} = await client.query({ query: currentUserQuery })
|
|
if (!currentUser) return dispatch('logout')
|
|
commit('SET_USER', currentUser)
|
|
return currentUser
|
|
},
|
|
|
|
async login({ commit, dispatch }, { email, password }) {
|
|
commit('SET_PENDING', true)
|
|
try {
|
|
const client = this.app.apolloProvider.defaultClient
|
|
const {
|
|
data: { login },
|
|
} = await client.mutate({
|
|
mutation: gql(`
|
|
mutation($email: String!, $password: String!) {
|
|
login(email: $email, password: $password)
|
|
}
|
|
`),
|
|
variables: {
|
|
email,
|
|
password,
|
|
},
|
|
})
|
|
await this.app.$apolloHelpers.onLogin(login)
|
|
commit('SET_TOKEN', login)
|
|
await dispatch('fetchCurrentUser')
|
|
if (cookies.get(metadata.COOKIE_NAME) === undefined) {
|
|
throw new Error('no-cookie')
|
|
}
|
|
} catch (err) {
|
|
throw new Error(err)
|
|
} finally {
|
|
commit('SET_PENDING', false)
|
|
}
|
|
},
|
|
|
|
async logout({ commit }) {
|
|
commit('SET_USER', null)
|
|
commit('SET_TOKEN', null)
|
|
return this.app.$apolloHelpers.onLogout()
|
|
},
|
|
}
|