Search in sources :

Example 1 with Transactional

use of org.activityinfo.server.database.hibernate.dao.Transactional 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();
    }
}
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) ResetPasswordMessage(org.activityinfo.server.mail.ResetPasswordMessage) Transactional(org.activityinfo.server.database.hibernate.dao.Transactional)

Example 2 with Transactional

use of org.activityinfo.server.database.hibernate.dao.Transactional in project activityinfo by bedatadriven.

the class SignUpAddressExistsController 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));
        return new SignUpAddressExistsPageModel(email).asEmailSent();
    } catch (NoResultException e) {
        return new SignUpAddressExistsPageModel().asLoginError();
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, "Failed to send password reset email", e);
        return new SignUpAddressExistsPageModel().asEmailError();
    }
}
Also used : SignUpAddressExistsPageModel(org.activityinfo.server.login.model.SignUpAddressExistsPageModel) User(org.activityinfo.server.database.hibernate.entity.User) NoResultException(javax.persistence.NoResultException) Date(java.util.Date) NoResultException(javax.persistence.NoResultException) ResetPasswordMessage(org.activityinfo.server.mail.ResetPasswordMessage) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Transactional(org.activityinfo.server.database.hibernate.dao.Transactional)

Example 3 with Transactional

use of org.activityinfo.server.database.hibernate.dao.Transactional in project activityinfo by bedatadriven.

the class SignUpController method signUp.

@POST
@Produces(MediaType.TEXT_HTML)
@Transactional
public Response signUp(@FormParam("name") String name, @FormParam("organization") String organization, @FormParam("jobtitle") String jobtitle, @FormParam("email") String email, @FormParam("locale") String locale) {
    LOGGER.info("New user signing up! [name: " + name + ", email: " + email + ", locale: " + locale + ", organization: " + organization + ", job title: " + jobtitle + "]");
    if (!domainProvider.get().isSignUpAllowed()) {
        LOGGER.severe("Blocked attempt to signup via " + domainProvider.get().getHost());
        return Response.status(Status.FORBIDDEN).build();
    }
    // checking parameter values
    try {
        checkParam(name, true);
        checkParam(organization, false);
        checkParam(jobtitle, false);
        checkParam(email, true);
        checkParam(locale, true);
    } catch (IllegalArgumentException e) {
        LOGGER.log(Level.INFO, "User " + name + " (" + email + ") failed to sign up", e);
        return Response.ok(SignUpPageModel.formErrorModel().set(email, name, organization, jobtitle, locale).asViewable()).build();
    }
    try {
        // check duplicate email
        if (userDAO.get().doesUserExist(email)) {
            return Response.ok(new SignUpAddressExistsPageModel(email).asViewable()).type(MediaType.TEXT_HTML).build();
        }
        // persist new user
        User user = UserDAOImpl.createNewUser(email, name, organization, jobtitle, locale);
        userDAO.get().persist(user);
        // send confirmation email
        mailer.send(new SignUpConfirmationMessage(user));
        // return to page with positive result
        return Response.seeOther(new URI("/signUp/sent")).build();
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, "User " + name + " (" + email + ") failed to sign up", e);
        entityManager.getTransaction().rollback();
        return Response.ok(SignUpPageModel.genericErrorModel().set(email, name, organization, jobtitle, locale).asViewable()).build();
    }
}
Also used : SignUpAddressExistsPageModel(org.activityinfo.server.login.model.SignUpAddressExistsPageModel) User(org.activityinfo.server.database.hibernate.entity.User) SignUpConfirmationMessage(org.activityinfo.server.mail.SignUpConfirmationMessage) URI(java.net.URI) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) Transactional(org.activityinfo.server.database.hibernate.dao.Transactional)

Example 4 with Transactional

use of org.activityinfo.server.database.hibernate.dao.Transactional in project activityinfo by bedatadriven.

the class AuthTokenProvider method createNewAuthToken.

@Transactional
public Authentication createNewAuthToken(User user) {
    Authentication auth = new Authentication(user);
    authDAO.get().persist(auth);
    return auth;
}
Also used : Authentication(org.activityinfo.server.database.hibernate.entity.Authentication) Transactional(org.activityinfo.server.database.hibernate.dao.Transactional)

Aggregations

Transactional (org.activityinfo.server.database.hibernate.dao.Transactional)4 User (org.activityinfo.server.database.hibernate.entity.User)3 IOException (java.io.IOException)2 Date (java.util.Date)2 NoResultException (javax.persistence.NoResultException)2 ServletException (javax.servlet.ServletException)2 SignUpAddressExistsPageModel (org.activityinfo.server.login.model.SignUpAddressExistsPageModel)2 ResetPasswordMessage (org.activityinfo.server.mail.ResetPasswordMessage)2 URI (java.net.URI)1 POST (javax.ws.rs.POST)1 Produces (javax.ws.rs.Produces)1 Authentication (org.activityinfo.server.database.hibernate.entity.Authentication)1 ResetPasswordPageModel (org.activityinfo.server.login.model.ResetPasswordPageModel)1 SignUpConfirmationMessage (org.activityinfo.server.mail.SignUpConfirmationMessage)1