Search in sources :

Example 21 with User

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());
}
Also used : User(com.erudika.para.core.User) Profile(com.erudika.scoold.core.Profile) Before(org.junit.Before)

Example 22 with 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);
}
Also used : User(com.erudika.para.core.User) Profile(com.erudika.scoold.core.Profile) Before(org.junit.Before)

Example 23 with User

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());
}
Also used : SIGNINLINK(com.erudika.scoold.ScooldServer.SIGNINLINK) Question(com.erudika.scoold.core.Question) RequestParam(org.springframework.web.bind.annotation.RequestParam) Arrays(java.util.Arrays) Webhook(com.erudika.para.core.Webhook) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) ParaClient(com.erudika.para.client.ParaClient) StringUtils(org.apache.commons.lang3.StringUtils) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) Model(org.springframework.ui.Model) Locale(java.util.Locale) Map(java.util.Map) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ParseException(java.text.ParseException) Config(com.erudika.para.core.utils.Config) ZipEntry(java.util.zip.ZipEntry) ScooldUtils(com.erudika.scoold.utils.ScooldUtils) PostMapping(org.springframework.web.bind.annotation.PostMapping) ParaObject(com.erudika.para.core.ParaObject) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) ConfigValue(com.typesafe.config.ConfigValue) MediaType(org.springframework.http.MediaType) Set(java.util.Set) StreamingResponseBody(org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody) UUID(java.util.UUID) JsonMapper(com.fasterxml.jackson.databind.json.JsonMapper) SignedJWT(com.nimbusds.jwt.SignedJWT) Collectors(java.util.stream.Collectors) Comment(com.erudika.scoold.core.Comment) List(java.util.List) Tag(com.erudika.para.core.Tag) Optional(java.util.Optional) ADMINLINK(com.erudika.scoold.ScooldServer.ADMINLINK) App(com.erudika.para.core.App) Sysprop(com.erudika.para.core.Sysprop) ZipOutputStream(java.util.zip.ZipOutputStream) ParaObjectUtils(com.erudika.para.core.utils.ParaObjectUtils) ZipInputStream(java.util.zip.ZipInputStream) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) HashMap(java.util.HashMap) Pager(com.erudika.para.core.utils.Pager) Controller(org.springframework.stereotype.Controller) ArrayList(java.util.ArrayList) HOMEPAGE(com.erudika.scoold.ScooldServer.HOMEPAGE) Inject(javax.inject.Inject) LinkedHashMap(java.util.LinkedHashMap) MapperFeature(com.fasterxml.jackson.databind.MapperFeature) HttpServletRequest(javax.servlet.http.HttpServletRequest) FilterInputStream(java.io.FilterInputStream) GetMapping(org.springframework.web.bind.annotation.GetMapping) LinkedList(java.util.LinkedList) Logger(org.slf4j.Logger) Post(com.erudika.scoold.core.Post) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) User(com.erudika.para.core.User) Utils(com.erudika.para.core.utils.Utils) DateUtils(org.apache.commons.lang3.time.DateUtils) TimeUnit(java.util.concurrent.TimeUnit) HttpStatus(org.springframework.http.HttpStatus) Reply(com.erudika.scoold.core.Reply) MultipartFile(org.springframework.web.multipart.MultipartFile) SerializationFeature(com.fasterxml.jackson.databind.SerializationFeature) ResponseEntity(org.springframework.http.ResponseEntity) Collections(java.util.Collections) Profile(com.erudika.scoold.core.Profile) InputStream(java.io.InputStream) User(com.erudika.para.core.User) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Pager(com.erudika.para.core.utils.Pager) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) LinkedList(java.util.LinkedList)

Example 24 with User

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;
}
Also used : User(com.erudika.para.core.User) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ParaObject(com.erudika.para.core.ParaObject) List(java.util.List) Profile(com.erudika.scoold.core.Profile) LinkedHashMap(java.util.LinkedHashMap) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

User (com.erudika.para.core.User)24 Profile (com.erudika.scoold.core.Profile)18 ParaObject (com.erudika.para.core.ParaObject)10 HashMap (java.util.HashMap)9 LinkedHashMap (java.util.LinkedHashMap)9 Sysprop (com.erudika.para.core.Sysprop)6 Pager (com.erudika.para.core.utils.Pager)6 Post (com.erudika.scoold.core.Post)6 Reply (com.erudika.scoold.core.Reply)6 Map (java.util.Map)6 ParaClient (com.erudika.para.client.ParaClient)5 Tag (com.erudika.para.core.Tag)5 Webhook (com.erudika.para.core.Webhook)5 Config (com.erudika.para.core.utils.Config)5 ParaObjectUtils (com.erudika.para.core.utils.ParaObjectUtils)5 Utils (com.erudika.para.core.utils.Utils)5 Comment (com.erudika.scoold.core.Comment)5 Question (com.erudika.scoold.core.Question)5 UnapprovedReply (com.erudika.scoold.core.UnapprovedReply)5 Report (com.erudika.scoold.core.Report)4