use of org.activityinfo.server.database.hibernate.entity.User in project activityinfo by bedatadriven.
the class HostController method getHostPage.
@GET
@Produces(MediaType.TEXT_HTML)
public Response getHostPage(@Context UriInfo uri, @Context HttpServletRequest req, @QueryParam("redirect") boolean redirect, @QueryParam("ui") String ui, @QueryParam("locale") String locale, @QueryParam("logging") String logging, @QueryParam("gwt.codesvr") String codeServer) throws Exception {
if (!authProvider.isAuthenticated()) {
// Otherwise, go to the default ActivityInfo root page
return Response.temporaryRedirect(uri.getAbsolutePathBuilder().replacePath("/login").build()).build();
}
if (redirect) {
return Response.seeOther(uri.getAbsolutePathBuilder().replacePath(ENDPOINT).build()).build();
}
String appUri = uri.getAbsolutePathBuilder().replaceQuery("").build().toString();
HostPageModel model = new HostPageModel(appUri);
User authenticatedUser = entityManager.get().find(User.class, authProvider.get().getUserId());
model.setFeatureFlags(authenticatedUser.getFeatures());
model.setNewUI("3".equals(ui) || "3dev".equals(ui));
if ("3dev".equals(ui)) {
model.setBootstrapScript("/App/App.nocache.js");
} else if ("dev".equals(ui)) {
// Running in development mode
// Use the default bootstrap script
model.setBootstrapScript("/ActivityInfo/ActivityInfo.nocache.js");
} else if ("true".equalsIgnoreCase(logging)) {
// Load a special logging version of the Application
model.setBootstrapScript("/ActivityInfoLogging/ActivityInfoLogging.nocache.js");
} else {
// locale or the one explicitly provided
if (Strings.isNullOrEmpty(locale)) {
locale = authProvider.get().getUserLocale();
}
String module;
if (model.isNewUI()) {
module = "App";
} else {
module = "ActivityInfo";
}
model.setBootstrapScript(String.format("/%s/%s.js", module, locale));
model.setAppCacheManifest(String.format("/%s/%s.appcache", module, locale));
}
return Response.ok(model.asViewable()).type(MediaType.TEXT_HTML).cacheControl(CacheControl.valueOf("no-cache")).build();
}
use of org.activityinfo.server.database.hibernate.entity.User in project activityinfo by bedatadriven.
the class LoginController method login.
@POST
public Response login(@Context UriInfo uri, @FormParam("email") String email, @FormParam("password") String password) throws Exception {
User user;
try {
user = userDAO.get().findUserByEmail(email);
checkPassword(password, user);
} catch (Exception e) {
LoginPageModel model = LoginPageModel.unsuccessful(email);
LOGGER.warning("Failed login attempt for user " + email);
return Response.ok(model.asViewable()).type(MediaType.TEXT_HTML).build();
}
return loginAndRedirectToApp(uri.getBaseUri(), user);
}
use of org.activityinfo.server.database.hibernate.entity.User in project activityinfo by bedatadriven.
the class ResetPasswordController method resetPassword.
@POST
@Produces(MediaType.TEXT_HTML)
@Transactional
public Viewable resetPassword(@FormParam("email") String email) {
try {
User user = userDAO.get().findUserByEmail(email);
user.setChangePasswordKey(SecureTokenGenerator.generate());
user.setDateChangePasswordKeyIssued(new Date());
mailer.send(new ResetPasswordMessage(user));
ResetPasswordPageModel model = new ResetPasswordPageModel();
model.setEmailSent(true);
return model.asViewable();
} catch (NoResultException e) {
ResetPasswordPageModel model = new ResetPasswordPageModel();
model.setLoginError(true);
return model.asViewable();
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Failed to send password reset email", e);
ResetPasswordPageModel model = new ResetPasswordPageModel();
model.setEmailError(true);
return model.asViewable();
}
}
use of org.activityinfo.server.database.hibernate.entity.User in project activityinfo by bedatadriven.
the class UsersResource method createUser.
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response createUser(@FormParam("email") String email, @FormParam("name") String name, @FormParam("password") String password, @FormParam("locale") String locale) {
if (!isApiEnabled()) {
return Response.status(Response.Status.SERVICE_UNAVAILABLE).entity("User API is disabled.").build();
}
if (Strings.isNullOrEmpty(email) || Strings.isNullOrEmpty(name) || Strings.isNullOrEmpty(password)) {
return Response.status(Response.Status.BAD_REQUEST).entity("The email, name, and password properties are required.").build();
}
User user = new User();
user.setDateCreated(new Date());
user.setName(name);
user.setEmail(email);
user.setEmailNotification(false);
user.changePassword(password);
if (Strings.isNullOrEmpty(locale)) {
user.setLocale("en");
} else if ("en".equals(locale) || "fr".equals(locale)) {
user.setLocale(locale);
} else {
return Response.status(Response.Status.BAD_REQUEST).entity("Invalid locale").build();
}
entityManager.get().getTransaction().begin();
entityManager.get().persist(user);
entityManager.get().getTransaction().commit();
return Response.status(Response.Status.CREATED).build();
}
use of org.activityinfo.server.database.hibernate.entity.User in project activityinfo by bedatadriven.
the class AuditLogWriter method writeForm.
public void writeForm(FormStorageProvider catalog, ResourceId formId) throws IOException {
FormStorage formStorage = catalog.getForm(formId).get();
FormClass formClass = formStorage.getFormClass();
Key<FormEntity> parentKey = FormEntity.key(formId);
Query<FormRecordSnapshotEntity> query = Hrd.ofy().load().type(FormRecordSnapshotEntity.class).ancestor(parentKey);
for (FormRecordSnapshotEntity snapshot : query) {
User user;
try {
user = userCache.get((int) snapshot.getUserId());
} catch (ExecutionException e) {
throw new RuntimeException(e);
}
csv.writeLine(formatTime(snapshot.getTime()), snapshot.getType().name(), user.getEmail(), user.getName(), databaseId(), db.getName(), formId.asString(), formClass.getLabel(), // Field ID
"", // Field Name
"", snapshot.getRecordId().asString(), partner());
}
}
Aggregations