Search in sources :

Example 1 with NewUserDTO

use of io.hops.hopsworks.api.admin.dto.NewUserDTO in project hopsworks by logicalclocks.

the class UsersAdminResource method createUser.

private Response createUser(String email, String password, String givenName, String surname, int maxNumProjects, String role, UserAccountStatus status, UriInfo uriInfo) throws UserException {
    UserDTO newUser = new UserDTO();
    newUser.setEmail(email);
    newUser.setFirstName(givenName);
    newUser.setLastName(surname);
    newUser.setMaxNumProjects(maxNumProjects > 0 ? maxNumProjects : settings.getMaxNumProjPerUser());
    String passwordGen = password != null && !password.isEmpty() ? password : securityUtils.generateRandomString(UserValidator.TEMP_PASSWORD_LENGTH);
    newUser.setChosenPassword(passwordGen);
    newUser.setRepeatedPassword(passwordGen);
    newUser.setTos(true);
    userValidator.isValidNewUser(newUser, passwordGen.equals(password));
    UserAccountStatus statusDefault = status != null ? status : UserAccountStatus.TEMP_PASSWORD;
    Users user = usersController.registerUser(newUser, role != null ? role : Settings.DEFAULT_ROLE, statusDefault, UserAccountType.M_ACCOUNT_TYPE);
    NewUserDTO newUserDTO = new NewUserDTO(user);
    URI href = uriInfo.getAbsolutePathBuilder().path(user.getUid().toString()).build();
    if (!passwordGen.equals(password)) {
        newUserDTO.setPassword(passwordGen);
    }
    return Response.created(href).entity(newUserDTO).build();
}
Also used : UserAccountStatus(io.hops.hopsworks.persistence.entity.user.security.ua.UserAccountStatus) UserDTO(io.hops.hopsworks.common.dao.user.UserDTO) NewUserDTO(io.hops.hopsworks.api.admin.dto.NewUserDTO) Users(io.hops.hopsworks.persistence.entity.user.Users) NewUserDTO(io.hops.hopsworks.api.admin.dto.NewUserDTO) URI(java.net.URI)

Example 2 with NewUserDTO

use of io.hops.hopsworks.api.admin.dto.NewUserDTO in project hopsworks by logicalclocks.

the class UsersAdminResource method resetPassword.

@ApiOperation(value = "Reset password of a user specified by id.", response = NewUserDTO.class)
@PUT
@Path("/users/{id}/reset")
@Produces(MediaType.APPLICATION_JSON)
public Response resetPassword(@Context HttpServletRequest req, @Context SecurityContext sc, @PathParam("id") Integer id) throws UserException, MessagingException {
    String password = usersController.resetPassword(id, req.getRemoteUser());
    NewUserDTO newUserDTO = new NewUserDTO();
    newUserDTO.setPassword(password);
    return Response.ok(newUserDTO).build();
}
Also used : NewUserDTO(io.hops.hopsworks.api.admin.dto.NewUserDTO) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT)

Aggregations

NewUserDTO (io.hops.hopsworks.api.admin.dto.NewUserDTO)2 UserDTO (io.hops.hopsworks.common.dao.user.UserDTO)1 Users (io.hops.hopsworks.persistence.entity.user.Users)1 UserAccountStatus (io.hops.hopsworks.persistence.entity.user.security.ua.UserAccountStatus)1 ApiOperation (io.swagger.annotations.ApiOperation)1 URI (java.net.URI)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1