Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Register
Sign in
Toggle navigation
Menu
UPSMF
user-service
Commits
5cfaacf0
Commit
5cfaacf0
authored
3 years ago
by
ChakshuGautam
Browse files
Options
Download
Patches
Plain Diff
feat(user service): add school details when user with school role logs in
parent
9c72ef69
master
1.0
0.1.8
0.1.7
0.1
v2.4.4
v2.4.3
v2.4.2
v2.4.1
v2.4.0
v2.3.9
v2.3.8
v2.3.7
v2.3.6
v2.3.5
v2.3.4
v2.3.3.1
v2.3.3
v2.3.2
v2.3.1
v2.3.0
v2.2.0
v2.1.7
v2.1.6
v2.1.5
v2.1.4
v2.1.3
v2.1.2
v2.1.1
v2.1.0
v2.0.0
v1.1.0
v1.1
v1.0.6
v1.0.5
v1.0.4
v1.0.3
v1.0.2
v1.0.1
v0.1.6
v0.1.5
list
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/user/fusionauth/fusionauth.service.ts
+93
-28
src/user/fusionauth/fusionauth.service.ts
src/user/user.service.ts
+10
-2
src/user/user.service.ts
with
103 additions
and
30 deletions
+103
-30
src/user/fusionauth/fusionauth.service.ts
+
93
−
28
View file @
5cfaacf0
...
...
@@ -3,6 +3,9 @@ import FusionAuthClient, {
LoginResponse
,
RegistrationRequest
,
RegistrationResponse
,
SearchRequest
,
SearchResponse
,
Sort
,
UUID
,
User
,
UserRegistration
,
...
...
@@ -129,36 +132,45 @@ export class FusionauthService {
update
(
userID
:
UUID
,
authObj
:
any
,
isSimpleUpdate
=
false
,
):
Promise
<
{
statusFA
:
FAStatus
;
userId
:
UUID
;
fusionAuthUser
:
User
}
>
{
const
registrations
:
Array
<
UserRegistration
>
=
[];
const
currentRegistration
:
UserRegistration
=
{
username
:
authObj
.
username
,
applicationId
:
process
.
env
.
FUSIONAUTH_APPLICATION_ID
,
roles
:
authObj
.
role
,
};
registrations
.
push
(
currentRegistration
);
const
userRequest
:
UserRequest
=
{
user
:
{
active
:
true
,
data
:
{
school
:
authObj
.
school
,
education
:
authObj
.
education
,
address
:
authObj
.
address
,
gender
:
authObj
.
gender
,
dateOfRetirement
:
authObj
.
dateOfRetirement
,
phoneVerified
:
false
,
udise
:
authObj
.
udise
,
},
email
:
authObj
.
email
,
firstName
:
authObj
.
firstName
,
lastName
:
authObj
.
lastName
,
fullName
:
authObj
.
fullName
,
let
userRequest
:
UserRequest
;
if
(
!
isSimpleUpdate
)
{
const
registrations
:
Array
<
UserRegistration
>
=
[];
const
currentRegistration
:
UserRegistration
=
{
username
:
authObj
.
username
,
password
:
authObj
.
password
,
imageUrl
:
authObj
.
avatar
,
mobilePhone
:
authObj
.
phone
,
},
};
applicationId
:
process
.
env
.
FUSIONAUTH_APPLICATION_ID
,
roles
:
authObj
.
role
,
};
registrations
.
push
(
currentRegistration
);
userRequest
=
{
user
:
{
active
:
true
,
data
:
{
school
:
authObj
.
school
,
education
:
authObj
.
education
,
address
:
authObj
.
address
,
gender
:
authObj
.
gender
,
dateOfRetirement
:
authObj
.
dateOfRetirement
,
phoneVerified
:
false
,
udise
:
authObj
.
udise
,
},
email
:
authObj
.
email
,
firstName
:
authObj
.
firstName
,
lastName
:
authObj
.
lastName
,
fullName
:
authObj
.
fullName
,
username
:
authObj
.
username
,
password
:
authObj
.
password
,
imageUrl
:
authObj
.
avatar
,
mobilePhone
:
authObj
.
phone
,
},
};
}
else
{
userRequest
=
{
user
:
authObj
,
};
}
return
this
.
fusionauthClient
.
patchUser
(
userID
,
userRequest
)
...
...
@@ -189,4 +201,57 @@ export class FusionauthService {
verifyUsernamePhoneCombination
():
Promise
<
boolean
>
{
return
Promise
.
resolve
(
true
);
}
//One time Task
async
updateAllEmptyRolesToSchool
():
Promise
<
any
>
{
let
allDone
=
false
;
const
searchRequest
:
SearchRequest
=
{
search
:
{
numberOfResults
:
15
,
startRow
:
0
,
sortFields
:
[
{
missing
:
'
_first
'
,
name
:
'
id
'
,
order
:
Sort
.
asc
,
},
],
query
:
'
{"bool":{"must":[{"nested":{"path":"registrations","query":{"bool":{"must":[{"match":{"registrations.applicationId":"f0ddb3f6-091b-45e4-8c0f-889f89d4f5da"}}],"must_not":[{"match":{"registrations.roles":"school"}}]}}}}]}}
'
,
},
};
let
iteration
=
0
;
let
invalidUsersCount
=
0
;
while
(
!
allDone
)
{
iteration
+=
1
;
searchRequest
.
search
.
startRow
=
invalidUsersCount
;
const
resp
:
ClientResponse
<
SearchResponse
>
=
await
this
.
fusionauthClient
.
searchUsersByQuery
(
searchRequest
);
const
total
=
resp
.
response
.
total
;
console
.
log
(
iteration
,
total
);
if
(
total
===
0
)
allDone
=
true
;
else
{
const
users
:
Array
<
User
>
=
resp
.
response
.
users
;
for
(
const
user
of
users
)
{
if
(
user
.
registrations
[
0
].
roles
===
undefined
)
{
user
.
registrations
[
0
].
roles
=
[
'
school
'
];
console
.
log
(
'
Here
'
,
user
);
await
this
.
fusionauthClient
.
updateRegistration
(
user
.
id
,
{
registration
:
user
.
registrations
[
0
],
})
.
then
((
resp
)
=>
{
console
.
log
(
'
response
'
,
JSON
.
stringify
(
resp
));
})
.
catch
((
e
)
=>
{
console
.
log
(
'
error
'
,
JSON
.
stringify
(
e
));
});
}
else
{
console
.
log
(
'
Invalid User
'
,
user
.
id
);
invalidUsersCount
+=
1
;
}
}
}
}
}
}
This diff is collapsed.
Click to expand it.
src/user/user.service.ts
+
10
−
2
View file @
5cfaacf0
...
...
@@ -248,14 +248,22 @@ export class UserService {
return
this
.
fusionAuthService
.
login
(
user
)
.
then
(
async
(
resp
:
ClientResponse
<
LoginResponse
>
)
=>
{
const
fusionAuthUser
:
LoginResponse
=
resp
.
response
;
console
.
log
(
fusionAuthUser
.
user
.
registrations
[
0
].
roles
);
let
fusionAuthUser
:
LoginResponse
=
resp
.
response
;
if
(
this
.
isOldSchoolUser
(
fusionAuthUser
.
user
))
{
//updateUserData with school and udise
fusionAuthUser
.
user
.
data
=
{};
const
udise
=
fusionAuthUser
.
user
.
username
;
fusionAuthUser
.
user
.
data
.
udise
=
udise
;
const
schoolId
=
await
this
.
userDBService
.
getSchool
(
udise
);
fusionAuthUser
.
user
.
data
.
school
=
schoolId
.
id
;
await
this
.
fusionAuthService
.
update
(
fusionAuthUser
.
user
.
id
,
fusionAuthUser
.
user
,
true
,
);
//login again to get new JWT
fusionAuthUser
=
(
await
this
.
fusionAuthService
.
login
(
user
)).
response
;
const
response
:
SignupResponse
=
new
SignupResponse
().
init
(
uuidv4
());
response
.
responseCode
=
ResponseCode
.
OK
;
response
.
result
=
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
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
Menu
Explore
Projects
Groups
Topics
Snippets