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;' style='max-width: 600px;'
:disabled='group.id <= 2' :disabled='group.id <= 2'
) )
template(v-if='group.id > 2') template(v-if='group.id !== 2')
v-divider v-divider
v-card-text v-card-text
v-text-field( v-text-field(

View File

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

View File

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

View File

@ -281,6 +281,13 @@ module.exports = class User extends Model {
if (err) { return reject(err) } if (err) { return reject(err) }
if (!user) { return reject(new WIKI.Error.AuthLoginFailed()) } 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? // Must Change Password?
if (user.mustChangePwd) { if (user.mustChangePwd) {
try { try {
@ -291,7 +298,8 @@ module.exports = class User extends Model {
return resolve({ return resolve({
mustChangePwd: true, mustChangePwd: true,
continuationToken: pwdChangeToken continuationToken: pwdChangeToken,
redirect
}) })
} catch (errc) { } catch (errc) {
WIKI.logger.warn(errc) WIKI.logger.warn(errc)
@ -308,7 +316,8 @@ module.exports = class User extends Model {
}) })
return resolve({ return resolve({
tfaRequired: true, tfaRequired: true,
continuationToken: tfaToken continuationToken: tfaToken,
redirect
}) })
} catch (errc) { } catch (errc) {
WIKI.logger.warn(errc) WIKI.logger.warn(errc)
@ -319,7 +328,7 @@ module.exports = class User extends Model {
context.req.logIn(user, { session: !strInfo.useForm }, async errc => { context.req.logIn(user, { session: !strInfo.useForm }, async errc => {
if (errc) { return reject(errc) } if (errc) { return reject(errc) }
const jwtToken = await WIKI.models.users.refreshToken(user) const jwtToken = await WIKI.models.users.refreshToken(user)
resolve({ jwt: jwtToken.token }) resolve({ jwt: jwtToken.token, redirect })
}) })
})(context.req, context.res, () => {}) })(context.req, context.res, () => {})
}) })