1 package ru
.rentdom
.pages
;
4 import java
.net
.URISyntaxException
;
5 import java
.util
.Calendar
;
7 import net
.aramzamzam
.commons
.tokens
.services
.TokenManager
;
9 import org
.apache
.tapestry5
.Block
;
10 import org
.apache
.tapestry5
.ComponentResources
;
11 import org
.apache
.tapestry5
.Link
;
12 import org
.apache
.tapestry5
.PersistenceConstants
;
13 import org
.apache
.tapestry5
.ValidationException
;
14 import org
.apache
.tapestry5
.annotations
.Persist
;
15 import org
.apache
.tapestry5
.annotations
.Property
;
16 import org
.apache
.tapestry5
.hibernate
.annotations
.CommitAfter
;
17 import org
.apache
.tapestry5
.ioc
.Messages
;
18 import org
.apache
.tapestry5
.ioc
.annotations
.Inject
;
20 import ru
.rentdom
.entities
.User
;
21 import ru
.rentdom
.services
.user
.UserService
;
23 public class Recover
{
25 @SuppressWarnings("unused")
27 private String username
;
30 private String password
;
32 @SuppressWarnings("unused")
34 @Persist(PersistenceConstants
.FLASH
)
35 private URI recoverUrl
;
37 @Property(write
=false)
38 @Persist(PersistenceConstants
.FLASH
)
39 private Block activeBlock
;
41 @Persist(PersistenceConstants
.FLASH
)
45 private UserService userService
;
48 private TokenManager tokenManager
;
51 private Messages messages
;
54 private ComponentResources resources
;
66 private Block invalidToken
;
69 private Block success
;
71 void onActivate(User user
)
73 activeBlock
=tokenManager
.isValid()?step3
:invalidToken
;
80 if (activeBlock
==null)
84 void onValidateFromUsername(String username
) throws ValidationException
86 user
= userService
.findByUserName(username
);
88 throw new ValidationException(messages
.get("not_found"));
91 void onSuccessFromRequestFrom() throws URISyntaxException
93 Link link
= resources
.createPageLink(Recover
.class, true, user
);
94 Calendar expiried
=Calendar
.getInstance();
95 expiried
.add(Calendar
.HOUR
, 48);
96 recoverUrl
=tokenManager
.grant(link
, expiried
.getTime());
101 void onSuccessFromChangePasswordForm() throws URISyntaxException
103 user
.setPassword(password
);
104 userService
.changeUserPassword(user
);