Search in sources :

Example 1 with NoSuchTicketException

use of com.liferay.portal.NoSuchTicketException in project liferay-ide by liferay.

the class UserLocalServiceImpl method verifyEmailAddress.

/**
 * Verifies the email address of the ticket.
 *
 * @param  ticketKey the ticket key
 * @throws PortalException if a ticket matching the ticket key could not be
 *         found, if the ticket has expired, if the ticket is an email
 *         address ticket, or if the email address is invalid
 * @throws SystemException if a system exception occurred
 */
@Override
public void verifyEmailAddress(String ticketKey) throws PortalException, SystemException {
    Ticket ticket = ticketLocalService.getTicket(ticketKey);
    if (ticket.isExpired() || (ticket.getType() != TicketConstants.TYPE_EMAIL_ADDRESS)) {
        throw new NoSuchTicketException("{ticketKey=" + ticketKey + "}");
    }
    User user = userPersistence.findByPrimaryKey(ticket.getClassPK());
    String emailAddress = ticket.getExtraInfo();
    emailAddress = StringUtil.toLowerCase(emailAddress).trim();
    if (!emailAddress.equals(user.getEmailAddress())) {
        if (userPersistence.fetchByC_EA(user.getCompanyId(), emailAddress) != null) {
            throw new DuplicateUserEmailAddressException("{userId=" + user.getUserId() + "}");
        }
        setEmailAddress(user, StringPool.BLANK, user.getFirstName(), user.getMiddleName(), user.getLastName(), emailAddress);
        Contact contact = user.getContact();
        contact.setEmailAddress(user.getEmailAddress());
        contactPersistence.update(contact);
    }
    user.setEmailAddressVerified(true);
    userPersistence.update(user);
    ticketLocalService.deleteTicket(ticket);
}
Also used : Ticket(com.liferay.portal.model.Ticket) NoSuchTicketException(com.liferay.portal.NoSuchTicketException) User(com.liferay.portal.model.User) DuplicateUserEmailAddressException(com.liferay.portal.DuplicateUserEmailAddressException) Contact(com.liferay.portal.model.Contact)

Aggregations

DuplicateUserEmailAddressException (com.liferay.portal.DuplicateUserEmailAddressException)1 NoSuchTicketException (com.liferay.portal.NoSuchTicketException)1 Contact (com.liferay.portal.model.Contact)1 Ticket (com.liferay.portal.model.Ticket)1 User (com.liferay.portal.model.User)1