Skip to content

Commit 98f8972

Browse files
committed
/account/activate: don't show activation form for already activated user.
1 parent 45a4b9a commit 98f8972

File tree

6 files changed

+187
-99
lines changed

6 files changed

+187
-99
lines changed

src/main/resources/ru/mystamps/i18n/Messages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ t_email = E-mail
3131
t_activation_sent_message = Instructions to finish registration sent to your e-mail
3232

3333
# account/activate.jsp
34+
t_already_activated = You already activated account.
3435
t_activation_title = account activation
3536
t_activation_on_site = Account activation
3637
t_activate = Activate

src/main/resources/ru/mystamps/i18n/Messages_ru.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ t_email = E-mail
3131
t_activation_sent_message = На указанный вами адрес было отправлено письмо с инструкциями для завершения регистрации
3232

3333
# account/activate.jsp
34+
t_already_activated = Пользователь уже активирован.
3435
t_activation_title = активация пользователя
3536
t_activation_on_site = Активация пользователя
3637
t_activate = Активировать

src/main/webapp/WEB-INF/pages/account/activate.jsp

Lines changed: 106 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -13,105 +13,112 @@
1313
<h3>
1414
<spring:message code="t_activation_on_site" />
1515
</h3>
16-
<div class="hint">
17-
<span class="hint_item">
18-
<spring:message code="t_required_fields_legend"
19-
arguments="<span class=\"required_field\">*</span>" />
20-
</span>
21-
</div>
22-
<div class="generic_form">
23-
<form:form method="post" action="${activateUrl}" modelAttribute="activateAccountForm">
24-
<table>
25-
<tr>
26-
<td>
27-
<form:label path="login">
28-
<spring:message code="t_login" />
29-
</form:label>
30-
</td>
31-
<td>
32-
<span id="login.required" class="required_field">*</span>
33-
</td>
34-
<td>
35-
<form:input path="login" required="required" />
36-
</td>
37-
<td>
38-
<form:errors path="login" cssClass="error" />
39-
</td>
40-
</tr>
41-
<tr>
42-
<td>
43-
<form:label path="name">
44-
<spring:message code="t_name" />
45-
</form:label>
46-
</td>
47-
<td></td>
48-
<td>
49-
<form:input path="name" />
50-
</td>
51-
<td>
52-
<form:errors path="name" cssClass="error" />
53-
</td>
54-
</tr>
55-
<tr>
56-
<td>
57-
<form:label path="password">
58-
<spring:message code="t_password" />
59-
</form:label>
60-
</td>
61-
<td>
62-
<span id="password.required" class="required_field">*</span>
63-
</td>
64-
<td>
65-
<form:password path="password" required="required" />
66-
</td>
67-
<td>
68-
<form:errors path="password" cssClass="error" />
69-
</td>
70-
</tr>
71-
<tr>
72-
<td>
73-
<form:label path="passwordConfirmation">
74-
<spring:message code="t_password_again" />
75-
</form:label>
76-
</td>
77-
<td>
78-
<span id="passwordConfirmation.required" class="required_field">*</span>
79-
</td>
80-
<td>
81-
<form:password path="passwordConfirmation" required="required" />
82-
</td>
83-
<td>
84-
<form:errors path="passwordConfirmation" cssClass="error" />
85-
</td>
86-
</tr>
87-
<tr>
88-
<td>
89-
<form:label path="activationKey">
90-
<spring:message code="t_activation_key" />
91-
</form:label>
92-
</td>
93-
<td>
94-
<span id="activationKey.required" class="required_field">*</span>
95-
</td>
96-
<td>
97-
<form:input path="activationKey" required="required" />
98-
</td>
99-
<td>
100-
<form:errors path="activationKey" cssClass="error" />
101-
</td>
102-
</tr>
103-
<tr>
104-
<td></td>
105-
<td></td>
106-
<td>
107-
<input type="submit" value="<spring:message code="t_activate" />" />
108-
</td>
109-
<td>
110-
</td>
111-
</tr>
112-
</table>
113-
</form:form>
114-
</div>
16+
17+
<sec:authorize access="isAuthenticated()">
18+
<spring:message code="t_already_activated" />
19+
</sec:authorize>
20+
21+
<sec:authorize access="isAnonymous()">
22+
<div class="hint">
23+
<span class="hint_item">
24+
<spring:message code="t_required_fields_legend"
25+
arguments="<span class=\"required_field\">*</span>" />
26+
</span>
27+
</div>
28+
<div class="generic_form">
29+
<form:form method="post" action="${activateUrl}" modelAttribute="activateAccountForm">
30+
<table>
31+
<tr>
32+
<td>
33+
<form:label path="login">
34+
<spring:message code="t_login" />
35+
</form:label>
36+
</td>
37+
<td>
38+
<span id="login.required" class="required_field">*</span>
39+
</td>
40+
<td>
41+
<form:input path="login" required="required" />
42+
</td>
43+
<td>
44+
<form:errors path="login" cssClass="error" />
45+
</td>
46+
</tr>
47+
<tr>
48+
<td>
49+
<form:label path="name">
50+
<spring:message code="t_name" />
51+
</form:label>
52+
</td>
53+
<td></td>
54+
<td>
55+
<form:input path="name" />
56+
</td>
57+
<td>
58+
<form:errors path="name" cssClass="error" />
59+
</td>
60+
</tr>
61+
<tr>
62+
<td>
63+
<form:label path="password">
64+
<spring:message code="t_password" />
65+
</form:label>
66+
</td>
67+
<td>
68+
<span id="password.required" class="required_field">*</span>
69+
</td>
70+
<td>
71+
<form:password path="password" required="required" />
72+
</td>
73+
<td>
74+
<form:errors path="password" cssClass="error" />
75+
</td>
76+
</tr>
77+
<tr>
78+
<td>
79+
<form:label path="passwordConfirmation">
80+
<spring:message code="t_password_again" />
81+
</form:label>
82+
</td>
83+
<td>
84+
<span id="passwordConfirmation.required" class="required_field">*</span>
85+
</td>
86+
<td>
87+
<form:password path="passwordConfirmation" required="required" />
88+
</td>
89+
<td>
90+
<form:errors path="passwordConfirmation" cssClass="error" />
91+
</td>
92+
</tr>
93+
<tr>
94+
<td>
95+
<form:label path="activationKey">
96+
<spring:message code="t_activation_key" />
97+
</form:label>
98+
</td>
99+
<td>
100+
<span id="activationKey.required" class="required_field">*</span>
101+
</td>
102+
<td>
103+
<form:input path="activationKey" required="required" />
104+
</td>
105+
<td>
106+
<form:errors path="activationKey" cssClass="error" />
107+
</td>
108+
</tr>
109+
<tr>
110+
<td></td>
111+
<td></td>
112+
<td>
113+
<input type="submit" value="<spring:message code="t_activate" />" />
114+
</td>
115+
<td>
116+
</td>
117+
</tr>
118+
</table>
119+
</form:form>
120+
</div>
121+
</sec:authorize>
115122
</div>
116123
<%@ include file="/WEB-INF/segments/footer.jspf" %>
117124
</body>

src/test/config/testng.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
</classes>
2121
</test>
2222

23+
<test name="When authenticated user activate account">
24+
<classes>
25+
<class name="ru.mystamps.web.tests.cases.WhenAuthenticatedUserAtActivateAccountPage" />
26+
</classes>
27+
</test>
28+
2329
<test name="When user activate account">
2430
<classes>
2531
<class name="ru.mystamps.web.tests.cases.WhenUserActivateAccount" />
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright (C) 2012 Slava Semushin <slava.semushin@gmail.com>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17+
*/
18+
19+
package ru.mystamps.web.tests.cases;
20+
21+
import static org.fest.assertions.api.Assertions.assertThat;
22+
23+
import static ru.mystamps.web.tests.TranslationUtils.tr;
24+
25+
import org.springframework.beans.factory.annotation.Value;
26+
import org.testng.annotations.AfterClass;
27+
import org.testng.annotations.BeforeClass;
28+
import org.testng.annotations.Test;
29+
30+
import ru.mystamps.web.tests.page.ActivateAccountPage;
31+
32+
public class WhenAuthenticatedUserAtActivateAccountPage
33+
extends WhenUserAtAnyPageWithForm<ActivateAccountPage> {
34+
35+
@Value("${valid_user_login}")
36+
private String validUserLogin;
37+
38+
@Value("${valid_user_password}")
39+
private String validUserPassword;
40+
41+
public WhenAuthenticatedUserAtActivateAccountPage() {
42+
super(ActivateAccountPage.class);
43+
hasTitle(tr("t_activation_title"));
44+
}
45+
46+
@BeforeClass
47+
public void setUp() {
48+
page.open();
49+
page.login(validUserLogin, validUserPassword);
50+
}
51+
52+
@AfterClass(alwaysRun = true)
53+
public void tearDown() {
54+
page.logout();
55+
}
56+
57+
@Test(groups = "logic")
58+
public void messageShouldBeShown() {
59+
assertThat(page.textPresent(tr("t_already_activated"))).isTrue();
60+
61+
}
62+
63+
@Test(groups = "misc")
64+
public void formWithLegendShouldBeAbsent() {
65+
assertThat(page.activationFormExists()).isFalse();
66+
assertThat(page.getFormHints()).isEmpty();
67+
}
68+
69+
}

src/test/java/ru/mystamps/web/tests/page/ActivateAccountPage.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ public void activateAccount(
9696
submit();
9797
}
9898

99+
public boolean activationFormExists() {
100+
return elementWithIdExists("activateAccountForm");
101+
}
102+
99103
private void fillLogin(final String login) {
100104
if (login != null) {
101105
fillField("login", login);

0 commit comments

Comments
 (0)