Search in sources :

Example 11 with User

use of com.datastax.fallout.service.core.User in project fallout by datastax.

the class UserDAO method createUserIfNotExists.

public User createUserIfNotExists(String name, String email, String password, String group) {
    return logger.withScopedDebug("Creating new user").get(() -> {
        User user = makeUser(name, email, password, group);
        logger.withScopedInfo("addUser").run(() -> createUserIfNotExists(user));
        return user;
    });
}
Also used : User(com.datastax.fallout.service.core.User)

Example 12 with User

use of com.datastax.fallout.service.core.User in project fallout by datastax.

the class AccountResource method doLost.

@POST
@Path("/lost")
@Timed
@Produces(MediaType.APPLICATION_JSON)
public Response doLost(@FormParam("email") @NotEmpty String email) {
    validateEmail(email);
    User existingUser = userDAO.getUser(email);
    if (existingUser != null) {
        userDAO.addResetToken(existingUser);
        String resetUrl = String.format("%s/a/pages/reset.html?token=%s&email=%s", configuration.getExternalUrl(), existingUser.getResetToken(), email);
        try {
            String emailBody = "<html><body>" + "Hi, <br/> We heard you are having trouble logging into Fallout." + "<br/><br/> You can reset your fallout password with the following link: " + "<a href=\"" + resetUrl + "\">" + resetUrl + "</a>" + "</body></html>";
            mailer.sendMessage(email, "Fallout password reset", emailBody);
        } catch (UserMessenger.MessengerException e) {
            logger.warn("Failed to send password email", e);
            throw new WebApplicationException("Error sending email, let someone know");
        }
    }
    return Response.ok().build();
}
Also used : User(com.datastax.fallout.service.core.User) WebApplicationException(javax.ws.rs.WebApplicationException) UserMessenger(com.datastax.fallout.util.UserMessenger) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed)

Example 13 with User

use of com.datastax.fallout.service.core.User in project fallout by datastax.

the class AccountResource method doRegistration.

@POST
@Path("/register")
@Timed
@Produces(MediaType.APPLICATION_JSON)
public Response doRegistration(@FormParam("name") @NotEmpty String name, @FormParam("email") @NotEmpty String email, @FormParam("password") @NotEmpty String password, @FormParam("group") String group) {
    validateEmail(email);
    /**
     * Special logic for fallout in production *
     */
    if (configuration.isDatastaxOnly()) {
        if (!email.toLowerCase().endsWith("@datastax.com")) {
            throw new WebApplicationException("Only DataStax employees can register, Sorry!", Response.Status.BAD_REQUEST);
        }
        if (configuration.getIsSharedEndpoint()) {
            // Force users to recover their password
            if (configuration.isDatastaxOnly() && configuration.getIsSharedEndpoint()) {
                password = UUID.randomUUID().toString();
            }
        }
    }
    User existingUser = userDAO.getUser(email);
    if (existingUser != null && existingUser.getSalt() != null) {
        throw new WebApplicationException("Email already registered", Response.Status.BAD_REQUEST);
    }
    Session session;
    try {
        var user = userDAO.createUserIfNotExists(name, email, password, userGroupMapper.validGroupOrOther(group));
        session = userDAO.addSession(user);
    } catch (Exception e) {
        logger.error("UserDAO registration failed", e);
        throw new WebApplicationException(e.getMessage());
    }
    // 2 weeks
    int expires = 60 * 60 * 24 * 14;
    // Login too
    return Response.ok().cookie(new NewCookie(FalloutService.COOKIE_NAME, session.getTokenId().toString(), "/", null, null, expires, false)).build();
}
Also used : User(com.datastax.fallout.service.core.User) WebApplicationException(javax.ws.rs.WebApplicationException) WebApplicationException(javax.ws.rs.WebApplicationException) Session(com.datastax.fallout.service.core.Session) NewCookie(javax.ws.rs.core.NewCookie) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed)

Aggregations

User (com.datastax.fallout.service.core.User)13 POST (javax.ws.rs.POST)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 WebApplicationException (javax.ws.rs.WebApplicationException)6 Timed (com.codahale.metrics.annotation.Timed)5 ReadOnlyTestRun (com.datastax.fallout.service.core.ReadOnlyTestRun)4 TestRun (com.datastax.fallout.service.core.TestRun)4 PerformanceReportDAO (com.datastax.fallout.service.db.PerformanceReportDAO)4 TestDAO (com.datastax.fallout.service.db.TestDAO)4 TestRunDAO (com.datastax.fallout.service.db.TestRunDAO)4 UserGroupMapper (com.datastax.fallout.service.db.UserGroupMapper)4 MainView (com.datastax.fallout.service.views.MainView)4 URI (java.net.URI)4 Paths (java.nio.file.Paths)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Map (java.util.Map)4 Optional (java.util.Optional)4 Set (java.util.Set)4