feat: redirect on login based on group

This commit is contained in:
NGPixel 2020-07-19 15:13:35 -04:00
parent be499e5795
commit 10f17c5712
4 changed files with 17 additions and 4 deletions

View File

@ -61,7 +61,7 @@
style='max-width: 600px;'
:disabled='group.id <= 2'
)
template(v-if='group.id > 2')
template(v-if='group.id !== 2')
v-divider
v-card-text
v-text-field(

View File

@ -350,6 +350,7 @@ export default {
mustChangePwd
mustProvideTFA
continuationToken
redirect
}
}
}
@ -386,6 +387,8 @@ export default {
if (loginRedirect) {
Cookies.remove('loginRedirect')
window.location.replace(loginRedirect)
} else if (respObj.redirect) {
window.location.replace(respObj.redirect)
} else {
window.location.replace('/')
}

View File

@ -109,6 +109,7 @@ type AuthenticationLoginResponse {
mustChangePwd: Boolean
mustProvideTFA: Boolean
continuationToken: String
redirect: String
}
type AuthenticationRegisterResponse {

View File

@ -281,6 +281,13 @@ module.exports = class User extends Model {
if (err) { return reject(err) }
if (!user) { return reject(new WIKI.Error.AuthLoginFailed()) }
// Get redirect target
user.groups = await user.$relatedQuery('groups').select('groups.id', 'permissions', 'redirectOnLogin')
let redirect = '/'
if (user.groups && user.groups.length > 0) {
redirect = user.groups[0].redirectOnLogin
}
// Must Change Password?
if (user.mustChangePwd) {
try {
@ -291,7 +298,8 @@ module.exports = class User extends Model {
return resolve({
mustChangePwd: true,
continuationToken: pwdChangeToken
continuationToken: pwdChangeToken,
redirect
})
} catch (errc) {
WIKI.logger.warn(errc)
@ -308,7 +316,8 @@ module.exports = class User extends Model {
})
return resolve({
tfaRequired: true,
continuationToken: tfaToken
continuationToken: tfaToken,
redirect
})
} catch (errc) {
WIKI.logger.warn(errc)
@ -319,7 +328,7 @@ module.exports = class User extends Model {
context.req.logIn(user, { session: !strInfo.useForm }, async errc => {
if (errc) { return reject(errc) }
const jwtToken = await WIKI.models.users.refreshToken(user)
resolve({ jwt: jwtToken.token })
resolve({ jwt: jwtToken.token, redirect })
})
})(context.req, context.res, () => {})
})