@@ -1124,33 +1124,6 @@ protected function enrollByInvitationToken($input) {
1124
1124
1125
1125
$ entityId = $ invitation ->getField ('entities_id ' );
1126
1126
1127
- //create agent user account
1128
- $ agentAccount = new User ();
1129
- $ agentAccount ->add ([
1130
- 'usercategories_id ' => $ config ['agentusercategories_id ' ],
1131
- 'name ' => 'flyvemdm- ' . PluginFlyvemdmCommon::generateUUID (),
1132
- 'realname ' => $ serial ,
1133
- '_profiles_id ' => $ config ['agent_profiles_id ' ],
1134
- 'profiles_id ' => $ config ['agent_profiles_id ' ], // Default profile when user logs in
1135
- '_entities_id ' => $ entityId ,
1136
- '_is_recursive ' => 0 ,
1137
- ]);
1138
-
1139
- if ($ agentAccount ->isNewItem ()) {
1140
- $ event = __ ('Cannot create a user account for the agent ' , 'flyvemdm ' );
1141
- $ this ->filterMessages ($ event );
1142
- $ this ->logInvitationEvent ($ invitation , $ event );
1143
- return false ;
1144
- }
1145
-
1146
- $ agentToken = User::getToken ($ agentAccount ->getID (), 'api_token ' );
1147
- if ($ agentToken === false ) {
1148
- $ event = __ ('Cannot create the API token for the agent ' , 'flyvemdm ' );
1149
- $ this ->filterMessages ($ event );
1150
- $ this ->logInvitationEvent ($ invitation , $ event );
1151
- return false ;
1152
- }
1153
-
1154
1127
//sign the agent's certificate (if TLS enabled)
1155
1128
if ($ config ['mqtt_tls_for_clients ' ] != '0 ' && $ config ['mqtt_use_client_cert ' ] != '0 ' ) {
1156
1129
$ answer = self ::signCertificate ($ csr );
@@ -1239,6 +1212,33 @@ protected function enrollByInvitationToken($input) {
1239
1212
'users_id ' => $ userId ,
1240
1213
]);
1241
1214
1215
+ //create agent user account
1216
+ $ agentAccount = new User ();
1217
+ $ agentAccount ->add ([
1218
+ 'usercategories_id ' => $ config ['agentusercategories_id ' ],
1219
+ 'name ' => 'flyvemdm- ' . PluginFlyvemdmCommon::generateUUID (),
1220
+ 'realname ' => $ serial ,
1221
+ '_profiles_id ' => $ config ['agent_profiles_id ' ],
1222
+ 'profiles_id ' => $ config ['agent_profiles_id ' ], // Default profile when user logs in
1223
+ '_entities_id ' => $ entityId ,
1224
+ '_is_recursive ' => 0 ,
1225
+ ]);
1226
+
1227
+ if ($ agentAccount ->isNewItem ()) {
1228
+ $ event = __ ('Cannot create a user account for the agent ' , 'flyvemdm ' );
1229
+ $ this ->filterMessages ($ event );
1230
+ $ this ->logInvitationEvent ($ invitation , $ event );
1231
+ return false ;
1232
+ }
1233
+
1234
+ $ agentToken = User::getToken ($ agentAccount ->getID (), 'api_token ' );
1235
+ if ($ agentToken === false ) {
1236
+ $ event = __ ('Cannot create the API token for the agent ' , 'flyvemdm ' );
1237
+ $ this ->filterMessages ($ event );
1238
+ $ this ->logInvitationEvent ($ invitation , $ event );
1239
+ return false ;
1240
+ }
1241
+
1242
1242
// Create the agent
1243
1243
$ defaultFleet = PluginFlyvemdmFleet::getDefaultFleet ();
1244
1244
if ($ defaultFleet === null ) {
0 commit comments