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;
});
}
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();
}
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();
}
Aggregations