feat: user profile fetch info + groups

This commit is contained in:
NGPixel
2020-03-30 01:30:10 -04:00
committed by Nicolas Giard
parent 8ea699ac7a
commit c7f3c9d908
6 changed files with 498 additions and 24 deletions

View File

@@ -26,6 +26,24 @@ module.exports = {
usr.password = ''
usr.tfaSecret = ''
return usr
},
async profile (obj, args, context, info) {
if (!context.req.user || context.req.user.id < 1 || context.req.user.id === 2) {
throw new WIKI.Error.AuthRequired()
}
const usr = await WIKI.models.users.query().findById(context.req.user.id)
if (!usr.isActive) {
throw new WIKI.Error.AuthAccountBanned()
}
const usrGroups = await usr.$relatedQuery('groups')
return {
...usr,
password: '',
providerKey: '',
tfaSecret: '',
lastLoginOn: '1970-01-01',
groups: usrGroups.map(g => g.name)
}
}
},
UserMutation: {

View File

@@ -27,6 +27,8 @@ type UserQuery {
single(
id: Int!
): User @auth(requires: ["manage:users", "manage:system"])
profile: UserProfile
}
# -----------------------------------------------
@@ -110,3 +112,19 @@ type User {
updatedAt: Date!
groups: [Group]!
}
type UserProfile {
id: Int!
name: String!
email: String!
providerName: String
isSystem: Boolean!
isVerified: Boolean!
location: String!
jobTitle: String!
timezone: String!
createdAt: Date!
updatedAt: Date!
lastLoginOn: Date!
groups: [String]!
}

View File

@@ -69,6 +69,10 @@ module.exports = {
message: 'You are not authorized to register. Your domain is not whitelisted.',
code: 1011
}),
AuthRequired: CustomError('AuthRequired', {
message: 'You must be authenticated to access this resource.',
code: 1019
}),
AuthTFAFailed: CustomError('AuthTFAFailed', {
message: 'Incorrect TFA Security Code.',
code: 1005