Skip to content
Snippets Groups Projects
Verified Commit 73f4fa14 authored by Ciarán Ainsworth's avatar Ciarán Ainsworth Committed by Georg Krause
Browse files

Add beforeRouteEnter guards for moderation pages

parent d44fc7e6
No related branches found
No related tags found
No related merge requests found
module.exports = {
env: {
browser: true,
es6: true
},
extends: [
'plugin:vue/recommended',
'standard'
],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly'
},
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
parser: 'babel-eslint'
},
plugins: [
'vue'
],
rules: {
}
}
This diff is collapsed.
import Vue from 'vue'
import axios from 'axios'
import logger from '@/logging'
import router from '@/router'
import lodash from '@/lodash'
function getDefaultScopedTokens () {
return {
listen: null,
listen: null
}
}
function asForm (obj) {
let data = new FormData()
const data = new FormData()
Object.entries(obj).forEach((e) => {
data.set(e[0], e[1])
})
return data
}
let baseUrl = `${window.location.protocol}//${window.location.hostname}`
if (window.location.port) {
baseUrl = `${baseUrl}:${window.location.port}`
......@@ -28,12 +26,12 @@ function getDefaultOauth () {
clientId: null,
clientSecret: null,
accessToken: null,
refreshToken: null,
refreshToken: null
}
}
const NEEDED_SCOPES = [
"read",
"write",
'read',
'write'
].join(' ')
async function createOauthApp (domain) {
const payload = {
......@@ -134,7 +132,8 @@ export default {
actions: {
// Send a request to the login URL and save the returned JWT
login ({ commit, dispatch }, { next, credentials, onError }) {
var form = new FormData();
const router = require('@/router').default
var form = new FormData()
Object.keys(credentials).forEach((k) => {
form.set(k, credentials[k])
})
......@@ -156,7 +155,7 @@ export default {
} catch {
console.log('Error while logging out, probably logged in via oauth')
}
let modules = [
const modules = [
'auth',
'favorites',
'player',
......@@ -172,7 +171,7 @@ export default {
async check ({ commit, dispatch, state }) {
logger.default.info('Checking authentication…')
commit('authenticated', false)
let profile = await dispatch('fetchProfile')
const profile = await dispatch('fetchProfile')
if (profile) {
commit('authenticated', true)
} else {
......@@ -180,7 +179,6 @@ export default {
}
},
fetchProfile ({ commit, dispatch, state }) {
return new Promise((resolve, reject) => {
axios.get('users/me/').then((response) => {
logger.default.info('Successfully fetched user profile')
......@@ -204,22 +202,22 @@ export default {
dispatch('playlists/fetchOwn', null, { root: true })
}, (response) => {
logger.default.info('Error while fetching user profile')
reject()
reject(new Error('Error while fetching user profile'))
})
})
},
updateProfile ({ commit }, data) {
return new Promise((resolve, reject) => {
commit("authenticated", true)
commit("profile", data)
commit("username", data.username)
commit("fullUsername", data.full_username)
commit('authenticated', true)
commit('profile', data)
commit('username', data.username)
commit('fullUsername', data.full_username)
if (data.tokens) {
commit("scopedTokens", data.tokens)
commit('scopedTokens', data.tokens)
}
Object.keys(data.permissions).forEach(function (key) {
// this makes it easier to check for permissions in templates
commit("permission", {
commit('permission', {
key,
status: data.permissions[String(key)]
})
......@@ -228,10 +226,10 @@ export default {
})
},
async oauthLogin ({ state, rootState, commit, getters }, next) {
let app = await createOauthApp(getters["appDomain"])
commit("oauthApp", app)
const app = await createOauthApp(getters.appDomain)
commit('oauthApp', app)
const redirectUri = encodeURIComponent(`${baseUrl}/auth/callback`)
let params = `response_type=code&scope=${encodeURIComponent(NEEDED_SCOPES)}&redirect_uri=${redirectUri}&state=${next}&client_id=${state.oauth.clientId}`
const params = `response_type=code&scope=${encodeURIComponent(NEEDED_SCOPES)}&redirect_uri=${redirectUri}&state=${next}&client_id=${state.oauth.clientId}`
const authorizeUrl = `${rootState.instance.instanceUrl}authorize?${params}`
console.log('Redirecting user...', authorizeUrl)
window.location = authorizeUrl
......@@ -241,7 +239,7 @@ export default {
const payload = {
client_id: state.oauth.clientId,
client_secret: state.oauth.clientSecret,
grant_type: "authorization_code",
grant_type: 'authorization_code',
code: authorizationCode,
redirect_uri: `${baseUrl}/auth/callback`
}
......@@ -250,22 +248,22 @@ export default {
asForm(payload),
{ headers: { 'Content-Type': 'multipart/form-data' } }
)
commit("oauthToken", response.data)
commit('oauthToken', response.data)
await dispatch('fetchProfile')
},
async refreshOauthToken ({ state, commit }, authorizationCode) {
const payload = {
client_id: state.oauth.clientId,
client_secret: state.oauth.clientSecret,
grant_type: "refresh_token",
refresh_token: state.oauth.refreshToken,
grant_type: 'refresh_token',
refresh_token: state.oauth.refreshToken
}
let response = await axios.post(
`oauth/token/`,
const response = await axios.post(
'oauth/token/',
asForm(payload),
{ headers: { 'Content-Type': 'multipart/form-data' } }
)
commit('oauthToken', response.data)
},
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment