Search in sources :

Example 1 with Link

use of com.autentia.tnt.businessobject.Link in project TNTConcept by autentia.

the class LinkBean method generateLink.

public Link generateLink(String name) {
    // Generate random string for verification link
    StringBuilder buffer = new StringBuilder();
    char[] characters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".toCharArray();
    Random random = new Random();
    for (int i = 0; i < 30; i++) {
        buffer.append(characters[random.nextInt(characters.length)]);
    }
    Link link = new Link();
    link.setLink(buffer.toString());
    link.setUser(name);
    return link;
}
Also used : Random(java.util.Random) Link(com.autentia.tnt.businessobject.Link)

Example 2 with Link

use of com.autentia.tnt.businessobject.Link in project TNTConcept by autentia.

the class LinkBean method passwordResetRequest.

public String passwordResetRequest() {
    try {
        User user = getUserByName(this.name);
        if (user.isActive()) {
            Link link = generateLink(this.name);
            manager.insertEntityWithoutUser(link);
            sendMail(link, user.getEmail());
            setResetEmailFailed(false);
            return "emailSent";
        } else {
            setResetEmailFailed(true);
            return "emailSentFailed";
        }
    } catch (DataNotFoundException ex) {
        setResetEmailFailed(true);
        return "emailSentFailed";
    }
}
Also used : DataNotFoundException(com.autentia.tnt.dao.DataNotFoundException) User(com.autentia.tnt.businessobject.User) Link(com.autentia.tnt.businessobject.Link)

Example 3 with Link

use of com.autentia.tnt.businessobject.Link in project TNTConcept by autentia.

the class LinkBeanTest method shouldGenerateRandomLink.

@Test
public void shouldGenerateRandomLink() {
    String name = "test";
    Link result = sut.generateLink(name);
    assertThat(result.getUser(), equalTo(name));
    assertThat(result.getLink(), is(notNullValue()));
}
Also used : Link(com.autentia.tnt.businessobject.Link) Test(org.junit.Test)

Example 4 with Link

use of com.autentia.tnt.businessobject.Link in project TNTConcept by autentia.

the class LinkBeanTest method shouldFailWhenCheckingWithNonExistentUser.

@Test
public void shouldFailWhenCheckingWithNonExistentUser() {
    Link testLink = new Link();
    testLink.setLink("linkTest");
    testLink.setUser("testUser");
    testLink.setInsertDate(new Date());
    doReturn(Arrays.asList(testLink)).when(sutMock).getLinksWithLink("linkTest");
    doReturn(new User()).when(sutMock).getUserByName("testUser");
    String result = sutMock.checkLinkAndResetPassword(testLink.getLink());
    assertThat(result, equalTo("<p>El enlace no existe o ha caducado</p>"));
}
Also used : User(com.autentia.tnt.businessobject.User) Link(com.autentia.tnt.businessobject.Link) Date(java.util.Date) Test(org.junit.Test)

Example 5 with Link

use of com.autentia.tnt.businessobject.Link in project TNTConcept by autentia.

the class LinkBeanTest method shouldCheckLinkIsOnTime.

@Test
public void shouldCheckLinkIsOnTime() {
    Link onTimeLink = new Link();
    onTimeLink.setInsertDate(new Date());
    boolean isOnTime = sut.isOnTime(onTimeLink);
    assertThat(isOnTime, is(true));
}
Also used : Link(com.autentia.tnt.businessobject.Link) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Link (com.autentia.tnt.businessobject.Link)12 Test (org.junit.Test)9 User (com.autentia.tnt.businessobject.User)6 Date (java.util.Date)6 Calendar (java.util.Calendar)2 DataNotFoundException (com.autentia.tnt.dao.DataNotFoundException)1 Random (java.util.Random)1