poprawki w dodawaniu użytkowników
This commit is contained in:
parent
737877b16c
commit
48d6f7d267
@ -208,10 +208,22 @@ public class AuthorizationService {
|
|||||||
JSONArray participants = course.getJSONArray("user_groups").getJSONObject(0).getJSONArray("participants");
|
JSONArray participants = course.getJSONArray("user_groups").getJSONObject(0).getJSONArray("participants");
|
||||||
for (int j = 0 ; j < participants.length() ; j++){
|
for (int j = 0 ; j < participants.length() ; j++){
|
||||||
String id = participants.getJSONObject(j).getString("id");
|
String id = participants.getJSONObject(j).getString("id");
|
||||||
Optional<User> user = userRepository.findByUsosUserUsosId(id);
|
Optional<User> userCheck = userRepository.findByUsosUserUsosId(id);
|
||||||
if (user.isPresent())
|
User user = null;
|
||||||
if (!studyGroupMemberRepository.findByUserUsosUserUsosIdAndGroupUsosGroupId(id, groupId).isPresent())
|
if (userCheck.isPresent())
|
||||||
studyGroup.getMembers().add(new StudyGroupMember(studyGroup, user.get(), false));
|
user = userCheck.get();
|
||||||
|
else {
|
||||||
|
user = new User();
|
||||||
|
String generatedPassword = PasswordGenerator.generatePassword(16, ALPHA_CAPS + ALPHA + NUMERIC);
|
||||||
|
UsosUser usosUser = new UsosUser(id, bCryptPasswordEncoder.encode(generatedPassword));
|
||||||
|
user.setUsosUser(usosUser);
|
||||||
|
user.setName(participants.getJSONObject(j).getString("first_name"));
|
||||||
|
user.setSurname(participants.getJSONObject(j).getString("last_name"));
|
||||||
|
user.setUsername(id);
|
||||||
|
user = userRepository.save(user);
|
||||||
|
}
|
||||||
|
if (!studyGroupMemberRepository.findByUserUsosUserUsosIdAndGroupUsosGroupId(id, groupId).isPresent())
|
||||||
|
studyGroup.getMembers().add(new StudyGroupMember(studyGroup, user, false));
|
||||||
}
|
}
|
||||||
groupRepository.save(studyGroup);
|
groupRepository.save(studyGroup);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user