Search in sources :

Example 1 with LogException

use of org.activityinfo.server.util.logging.LogException in project activityinfo by bedatadriven.

the class RenderReportHtmlHandler method execute.

@Override
@LogException
public CommandResult execute(RenderReportHtml cmd, User user) throws CommandException {
    ReportElement model = cmd.getModel();
    LOGGER.fine("Model: " + model);
    // don't show the title: it will be rendered by the container
    model.setTitle(null);
    generator.generateElement(user, model, new Filter(), new DateRange());
    StringWriter writer = new StringWriter();
    try {
        renderer.render(model, writer);
    } catch (IOException e) {
        throw new CommandException(e);
    }
    return new HtmlResult(writer.toString());
}
Also used : DateRange(org.activityinfo.shared.report.model.DateRange) StringWriter(java.io.StringWriter) Filter(org.activityinfo.shared.command.Filter) HtmlResult(org.activityinfo.shared.command.result.HtmlResult) ReportElement(org.activityinfo.shared.report.model.ReportElement) IOException(java.io.IOException) CommandException(org.activityinfo.shared.exception.CommandException) LogException(org.activityinfo.server.util.logging.LogException)

Example 2 with LogException

use of org.activityinfo.server.util.logging.LogException in project activityinfo by bedatadriven.

the class ChangePasswordController method changePassword.

@POST
@LogException(emailAlert = true)
public Response changePassword(@Context UriInfo uri, @FormParam("key") String key, @FormParam("password") String password) throws IOException, ServletException {
    User user = null;
    try {
        user = userDAO.get().findUserByChangePasswordKey(key);
    } catch (NoResultException e) {
        return Response.ok().entity(new InvalidInvitePageModel().asViewable()).type(MediaType.TEXT_HTML).build();
    }
    changePassword(user, password);
    return Response.seeOther(uri.getAbsolutePathBuilder().replacePath("/").build()).cookie(authTokenProvider.createNewAuthCookies(user)).build();
}
Also used : User(org.activityinfo.server.database.hibernate.entity.User) NoResultException(javax.persistence.NoResultException) InvalidInvitePageModel(org.activityinfo.server.login.model.InvalidInvitePageModel) POST(javax.ws.rs.POST) LogException(org.activityinfo.server.util.logging.LogException)

Example 3 with LogException

use of org.activityinfo.server.util.logging.LogException in project activityinfo by bedatadriven.

the class ConfirmInviteController method confirm.

@POST
@LogException(emailAlert = true)
public Response confirm(@Context UriInfo uri, @FormParam("key") String key, @FormParam("locale") String locale, @FormParam("password") String password, @FormParam("name") String name, @FormParam("newsletter") boolean newsletter) throws Exception {
    User user = null;
    try {
        user = userDAO.get().findUserByChangePasswordKey(key);
        user.setName(checkNonEmpty(name));
        user.setLocale(checkNonEmpty(locale));
        user.changePassword(checkNonEmpty(password));
        user.clearChangePasswordKey();
        user.setEmailNotification(true);
        if (newsletter) {
            mailingList.subscribe(user);
        }
        return Response.seeOther(uri.getAbsolutePathBuilder().replacePath("/").build()).cookie(authTokenProvider.createNewAuthCookies(user)).build();
    } catch (EntityNotFoundException e) {
        return Response.ok(new InvalidInvitePageModel().asViewable()).type(MediaType.TEXT_HTML).build();
    } catch (IllegalArgumentException e) {
        return Response.ok(ConfirmInvitePageModel.incompleteForm(user).asViewable()).type(MediaType.TEXT_HTML).build();
    }
}
Also used : User(org.activityinfo.server.database.hibernate.entity.User) EntityNotFoundException(javax.persistence.EntityNotFoundException) InvalidInvitePageModel(org.activityinfo.server.login.model.InvalidInvitePageModel) POST(javax.ws.rs.POST) LogException(org.activityinfo.server.util.logging.LogException)

Example 4 with LogException

use of org.activityinfo.server.util.logging.LogException in project activityinfo by bedatadriven.

the class SignUpConfirmationController method addUserToDefaultDatabase.

@LogException(emailAlert = true)
protected void addUserToDefaultDatabase(User user) {
    UserDatabase database = databaseDAO.get().findById(DEFAULT_DATABASE_ID);
    Partner partner = partnerDAO.get().findById(DEFAULT_PARTNER_ID);
    UserPermission permission = new UserPermission(database, user);
    permission.setPartner(partner);
    permission.setAllowView(true);
    permission.setAllowViewAll(true);
    permission.setLastSchemaUpdate(new Date());
    permissionDAO.get().persist(permission);
}
Also used : UserDatabase(org.activityinfo.server.database.hibernate.entity.UserDatabase) Partner(org.activityinfo.server.database.hibernate.entity.Partner) Date(java.util.Date) UserPermission(org.activityinfo.server.database.hibernate.entity.UserPermission) LogException(org.activityinfo.server.util.logging.LogException)

Example 5 with LogException

use of org.activityinfo.server.util.logging.LogException in project activityinfo by bedatadriven.

the class ResetPasswordController method resetPassword.

@POST
@Produces(MediaType.TEXT_HTML)
@LogException(emailAlert = true)
@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();
    }
}
Also used : User(org.activityinfo.server.database.hibernate.entity.User) ResetPasswordPageModel(org.activityinfo.server.login.model.ResetPasswordPageModel) NoResultException(javax.persistence.NoResultException) Date(java.util.Date) ServletException(javax.servlet.ServletException) NoResultException(javax.persistence.NoResultException) IOException(java.io.IOException) LogException(org.activityinfo.server.util.logging.LogException) ResetPasswordMessage(org.activityinfo.server.mail.ResetPasswordMessage) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) LogException(org.activityinfo.server.util.logging.LogException) Transactional(org.activityinfo.server.database.hibernate.dao.Transactional)

Aggregations

LogException (org.activityinfo.server.util.logging.LogException)12 POST (javax.ws.rs.POST)6 User (org.activityinfo.server.database.hibernate.entity.User)6 NoResultException (javax.persistence.NoResultException)4 Produces (javax.ws.rs.Produces)4 IOException (java.io.IOException)3 Date (java.util.Date)3 Transactional (org.activityinfo.server.database.hibernate.dao.Transactional)3 CommandException (org.activityinfo.shared.exception.CommandException)3 ServletException (javax.servlet.ServletException)2 InvalidInvitePageModel (org.activityinfo.server.login.model.InvalidInvitePageModel)2 SignUpAddressExistsPageModel (org.activityinfo.server.login.model.SignUpAddressExistsPageModel)2 ResetPasswordMessage (org.activityinfo.server.mail.ResetPasswordMessage)2 CommandResult (org.activityinfo.shared.command.result.CommandResult)2 StringWriter (java.io.StringWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 DataHandler (javax.activation.DataHandler)1