use of com.erudika.para.core.User in project scoold by Erudika.
the class AvatarRepositoryProxyTest method setUp.
@Before
public void setUp() {
this.gravatarAvatarGeneratorFake = mock(GravatarAvatarGenerator.class);
this.profile = new Profile();
this.profile.setUser(new User());
}
use of com.erudika.para.core.User in project scoold by Erudika.
the class ImgurAvatarRepositoryTest method setUp.
@Before
public void setUp() {
this.profile = new Profile();
this.profile.setUser(new User());
this.defaultRepository = new DefaultAvatarRepository();
this.repository = new ImgurAvatarRepository(defaultRepository);
}
use of com.erudika.para.core.User in project scoold by Erudika.
the class AdminController method importAccountsFromSO.
private void importAccountsFromSO(List<Map<String, Object>> objs) {
logger.info("Importing {} accounts...", objs.size());
List<Map<String, String>> toPatch = new LinkedList<>();
Map<String, String> accounts = objs.stream().collect(Collectors.toMap(k -> ((Integer) k.get("accountId")).toString(), v -> (String) v.get("verifiedEmail")));
// find all user objects even if there are more than 10000 users in the system
Pager pager = new Pager(1, "_docid", false, Config.MAX_ITEMS_PER_PAGE);
List<User> users;
do {
users = pc.findQuery(Utils.type(User.class), "*", pager);
if (!users.isEmpty()) {
users.stream().forEach(u -> {
if (accounts.containsKey(u.getCreatorid())) {
u.setEmail(accounts.get(u.getCreatorid()));
Map<String, String> user = new HashMap<>();
user.put(Config._ID, u.getId());
user.put(Config._EMAIL, u.getEmail());
user.put(Config._IDENTIFIER, u.getEmail());
toPatch.add(user);
}
});
}
pc.invokePatch("_batch", toPatch, Map.class);
toPatch.clear();
} while (!users.isEmpty());
}
use of com.erudika.para.core.User in project scoold by Erudika.
the class ApiController method createUser.
@PostMapping("/users")
public Map<String, Object> createUser(HttpServletRequest req, HttpServletResponse res) {
Map<String, Object> entity = readEntity(req);
if (entity.isEmpty()) {
badReq("Missing request body.");
}
Map<String, Object> userEntity = new HashMap<>();
userEntity.put(Config._TYPE, Utils.type(User.class));
userEntity.put(Config._NAME, entity.get(Config._NAME));
userEntity.put(Config._EMAIL, entity.get(Config._EMAIL));
userEntity.put(Config._IDENTIFIER, entity.get(Config._IDENTIFIER));
userEntity.put(Config._GROUPS, entity.get(Config._GROUPS));
userEntity.put("active", entity.getOrDefault("active", true));
userEntity.put("picture", entity.get("picture"));
User newUser = ParaObjectUtils.setAnnotatedFields(new User(), userEntity, null);
newUser.setPassword((String) entity.get(Config._PASSWORD));
newUser.setIdentifier(StringUtils.isBlank(newUser.getIdentifier()) ? newUser.getEmail() : newUser.getIdentifier());
String[] errors = ValidationUtils.validateObject(newUser);
if (errors.length == 0) {
// generic and password providers are identical but this was fixed in Para 1.37.1 (backwards compatibility)
String provider = "generic".equals(newUser.getIdentityProvider()) ? "password" : newUser.getIdentityProvider();
User createdUser = pc.signIn(provider, newUser.getIdentifier() + Config.SEPARATOR + newUser.getName() + Config.SEPARATOR + newUser.getPassword(), false);
// user is probably active:false so activate them
List<User> created = pc.findQuery(newUser.getType(), Config._EMAIL + ":" + newUser.getEmail());
if (createdUser == null && !created.isEmpty()) {
createdUser = created.iterator().next();
if (Utils.timestamp() - createdUser.getTimestamp() > TimeUnit.SECONDS.toMillis(20)) {
// user existed previously
createdUser = null;
} else if (newUser.getActive() && !createdUser.getActive()) {
createdUser.setActive(true);
pc.update(createdUser);
}
}
if (createdUser == null) {
badReq("Failed to create user. User may already exist.");
} else {
Profile profile = Profile.fromUser(createdUser);
profile.getSpaces().addAll(readSpaces(((List<String>) entity.getOrDefault("spaces", Collections.emptyList())).toArray(new String[0])));
res.setStatus(HttpStatus.CREATED.value());
pc.create(profile);
Map<String, Object> payload = new LinkedHashMap<>(ParaObjectUtils.getAnnotatedFields(profile, false));
payload.put("user", createdUser);
utils.triggerHookEvent("user.signup", payload);
logger.info("Created new user through API '{}' with id={}, groups={}, spaces={}.", createdUser.getName(), profile.getId(), profile.getGroups(), profile.getSpaces());
Map<String, Object> result = new LinkedHashMap<>(ParaObjectUtils.getAnnotatedFields(profile, false));
result.put("user", createdUser);
return result;
}
}
badReq("Failed to create user - " + String.join("; ", errors));
return null;
}
Aggregations