Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
funkwhale
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arthur Brugière
funkwhale
Commits
f78e3c64
Commit
f78e3c64
authored
3 years ago
by
Ciarán Ainsworth
Committed by
Georg Krause
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add beforeRouteEnter guards for moderation pages
parent
003203c4
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
front/.eslintrc.js
+2
-1
2 additions, 1 deletion
front/.eslintrc.js
front/src/router/index.js
+335
-303
335 additions, 303 deletions
front/src/router/index.js
front/src/store/auth.js
+41
-43
41 additions, 43 deletions
front/src/store/auth.js
with
378 additions
and
347 deletions
front/.eslintrc.js
+
2
−
1
View file @
f78e3c64
...
...
@@ -13,7 +13,8 @@ module.exports = {
},
parserOptions
:
{
ecmaVersion
:
2018
,
sourceType
:
'
module
'
sourceType
:
'
module
'
,
parser
:
'
babel-eslint
'
},
plugins
:
[
'
vue
'
...
...
This diff is collapsed.
Click to expand it.
front/src/router/index.js
+
335
−
303
View file @
f78e3c64
This diff is collapsed.
Click to expand it.
front/src/store/auth.js
+
41
−
43
View file @
f78e3c64
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
)
{
le
t
data
=
new
FormData
()
cons
t
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,14 +26,14 @@ function getDefaultOauth () {
clientId
:
null
,
clientSecret
:
null
,
accessToken
:
null
,
refreshToken
:
null
,
refreshToken
:
null
}
}
const
NEEDED_SCOPES
=
[
"
read
"
,
"
write
"
,
'
read
'
,
'
write
'
].
join
(
'
'
)
async
function
createOauthApp
(
domain
)
{
async
function
createOauthApp
(
domain
)
{
const
payload
=
{
name
:
`Funkwhale web client at
${
window
.
location
.
hostname
}
`
,
website
:
baseUrl
,
...
...
@@ -112,9 +110,9 @@ export default {
state
.
token
=
value
},
scopedTokens
:
(
state
,
value
)
=>
{
state
.
scopedTokens
=
{...
value
}
state
.
scopedTokens
=
{
...
value
}
},
permission
:
(
state
,
{
key
,
status
})
=>
{
permission
:
(
state
,
{
key
,
status
})
=>
{
state
.
availablePermissions
[
key
]
=
status
},
profilePartialUpdate
:
(
state
,
payload
)
=>
{
...
...
@@ -133,8 +131,9 @@ 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
();
login
({
commit
,
dispatch
},
{
next
,
credentials
,
onError
})
{
const
router
=
require
(
'
@/router
'
).
default
var
form
=
new
FormData
()
Object
.
keys
(
credentials
).
forEach
((
k
)
=>
{
form
.
set
(
k
,
credentials
[
k
])
})
...
...
@@ -150,13 +149,13 @@ export default {
onError
(
response
)
})
},
async
logout
({
state
,
commit
})
{
async
logout
({
state
,
commit
})
{
try
{
await
axios
.
post
(
'
users/logout
'
)
}
catch
{
console
.
log
(
'
Error while logging out, probably logged in via oauth
'
)
}
le
t
modules
=
[
cons
t
modules
=
[
'
auth
'
,
'
favorites
'
,
'
player
'
,
...
...
@@ -165,22 +164,21 @@ export default {
'
radios
'
]
modules
.
forEach
(
m
=>
{
commit
(
`
${
m
}
/reset`
,
null
,
{
root
:
true
})
commit
(
`
${
m
}
/reset`
,
null
,
{
root
:
true
})
})
logger
.
default
.
info
(
'
Log out, goodbye!
'
)
},
async
check
({
commit
,
dispatch
,
state
})
{
async
check
({
commit
,
dispatch
,
state
})
{
logger
.
default
.
info
(
'
Checking authentication…
'
)
commit
(
'
authenticated
'
,
false
)
le
t
profile
=
await
dispatch
(
'
fetchProfile
'
)
cons
t
profile
=
await
dispatch
(
'
fetchProfile
'
)
if
(
profile
)
{
commit
(
'
authenticated
'
,
true
)
}
else
{
logger
.
default
.
info
(
'
Anonymous user
'
)
}
},
fetchProfile
({
commit
,
dispatch
,
state
})
{
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
)
{
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
)
{
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
)]
})
...
...
@@ -227,45 +225,45 @@ export default {
resolve
()
})
},
async
oauthLogin
({
state
,
rootState
,
commit
,
getters
},
next
)
{
le
t
app
=
await
createOauthApp
(
getters
[
"
appDomain
"
]
)
commit
(
"
oauthApp
"
,
app
)
async
oauthLogin
({
state
,
rootState
,
commit
,
getters
},
next
)
{
cons
t
app
=
await
createOauthApp
(
getters
.
appDomain
)
commit
(
'
oauthApp
'
,
app
)
const
redirectUri
=
encodeURIComponent
(
`
${
baseUrl
}
/auth/callback`
)
le
t
params
=
`response_type=code&scope=
${
encodeURIComponent
(
NEEDED_SCOPES
)}
&redirect_uri=
${
redirectUri
}
&state=
${
next
}
&client_id=
${
state
.
oauth
.
clientId
}
`
cons
t
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
},
async
handleOauthCallback
({
state
,
commit
,
dispatch
},
authorizationCode
)
{
async
handleOauthCallback
({
state
,
commit
,
dispatch
},
authorizationCode
)
{
console
.
log
(
'
Fetching token...
'
)
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`
}
const
response
=
await
axios
.
post
(
'
oauth/token/
'
,
asForm
(
payload
),
{
headers
:
{
'
Content-Type
'
:
'
multipart/form-data
'
}
}
{
headers
:
{
'
Content-Type
'
:
'
multipart/form-data
'
}
}
)
commit
(
"
oauthToken
"
,
response
.
data
)
commit
(
'
oauthToken
'
,
response
.
data
)
await
dispatch
(
'
fetchProfile
'
)
},
async
refreshOauthToken
({
state
,
commit
},
authorizationCode
)
{
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
}
le
t
response
=
await
axios
.
post
(
`
oauth/token/
`
,
cons
t
response
=
await
axios
.
post
(
'
oauth/token/
'
,
asForm
(
payload
),
{
headers
:
{
'
Content-Type
'
:
'
multipart/form-data
'
}
}
{
headers
:
{
'
Content-Type
'
:
'
multipart/form-data
'
}
}
)
commit
(
'
oauthToken
'
,
response
.
data
)
}
,
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment