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;
}
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";
}
}
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()));
}
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>"));
}
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));
}