Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Use Velocity to generate email #534

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,17 @@
<enabled>false</enabled>
</snapshots>
</repository>
<!-- Needed for totallylazy -->
<repository>
<id>repo.bodar.com</id>
<url>http://repo.bodar.com</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>

<pluginRepositories>
Expand Down Expand Up @@ -760,6 +771,7 @@
<allowedRepositories combine.children="append">
<allowedRepository>jboss-public-repository-group</allowedRepository>
<allowedRepository>okapi-cloudbees-release</allowedRepository>
<allowedRepository>repo.bodar.com</allowedRepository>
</allowedRepositories>
<allowedPluginRepositories combine.children="append">
<allowedPluginRepository>cobertura-it-maven-plugin-maven2-release</allowedPluginRepository>
Expand Down
44 changes: 44 additions & 0 deletions zanata-war/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@
<usedDependency>org.jboss.seam:jboss-seam-debug</usedDependency>
<!-- runtime dependency for email implementations -->
<usedDependency>org.jboss.seam:jboss-seam-mail</usedDependency>
<!-- Used for email unit tests -->
<usedDependency>org.jvnet.mock-javamail:mock-javamail</usedDependency>
<!-- Needed for urlrewrite.xml impl -->
<usedDependency>org.tuckey:urlrewritefilter</usedDependency>
<!-- Need for test scope -->
Expand Down Expand Up @@ -1083,12 +1085,23 @@
</exclusions>
</dependency>

<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.googlecode.totallylazy</groupId>
<artifactId>totallylazy</artifactId>
<version>1.10</version>
</dependency>

<!-- Zanata-specific dependencies -->

Expand Down Expand Up @@ -1322,6 +1335,25 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.googlecode.owasp-java-html-sanitizer</groupId>
<artifactId>owasp-java-html-sanitizer</artifactId>
<version>r239</version>
<exclusions>
<exclusion>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.jvnet.mock-javamail</groupId>
<artifactId>mock-javamail</artifactId>
<version>1.9</version>
<scope>test</scope>
</dependency>

<!-- Richfaces -->

<dependency>
Expand Down Expand Up @@ -1402,6 +1434,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>net.htmlparser.jericho</groupId>
<artifactId>jericho-html</artifactId>
<version>3.3</version>
</dependency>

<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
Expand Down Expand Up @@ -1632,6 +1670,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>javax.annotation</groupId>
<artifactId>jsr250-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
import org.hibernate.validator.constraints.NotEmpty;
import org.jboss.seam.annotations.In;
import org.jboss.seam.faces.FacesMessages;
import org.jboss.seam.faces.Renderer;
import org.jboss.seam.security.management.JpaIdentityStore;
import org.zanata.dao.AccountDAO;
import org.zanata.dao.PersonDAO;
import org.zanata.model.HAccount;
import org.zanata.model.HPerson;
import org.zanata.security.ZanataIdentity;
import com.google.common.base.Strings;

/**
* @author Patrick Huang
Expand All @@ -26,9 +24,6 @@ public abstract class AbstractProfileAction {
protected boolean valid;
private String activationKey;

@In(create = true)
protected Renderer renderer;

@In
ZanataIdentity identity;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,9 @@ public void sendActivationEmail() {

String message =
emailServiceImpl.sendActivationEmail(
EmailService.ACTIVATION_ACCOUNT_EMAIL_TEMPLATE, account
.getPerson().getName(), account.getPerson()
.getEmail(), account.getAccountActivationKey()
.getKeyHash());
account.getPerson().getName(),
account.getPerson().getEmail(),
account.getAccountActivationKey().getKeyHash());
FacesMessages.instance().add(message);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import lombok.Setter;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
Expand All @@ -40,6 +41,7 @@
* @author Alex Eng <a href="mailto:aeng@redhat.com">aeng@redhat.com</a>
*/

@AutoCreate
@Name("languageJoinUpdateRoleAction")
@Scope(ScopeType.PAGE)
public class LanguageJoinUpdateRoleAction implements Serializable {
Expand Down Expand Up @@ -119,6 +121,10 @@ public String getTitle() {
return title;
}

public boolean requestingTranslator() {
return requestAsTranslator != null && requestAsTranslator && !isTranslator();
}

public boolean isTranslator() {
HLocaleMember member = getLocaleMember();
if (member != null) {
Expand All @@ -127,6 +133,10 @@ public boolean isTranslator() {
return false;
}

public boolean requestingReviewer() {
return requestAsReviewer != null && requestAsReviewer && !isReviewer();
}

public boolean isReviewer() {
HLocaleMember member = getLocaleMember();
if (member != null) {
Expand All @@ -135,6 +145,10 @@ public boolean isReviewer() {
return false;
}

public boolean requestingCoordinator() {
return requestAsCoordinator != null && requestAsCoordinator && !isCoordinator();
}

public boolean isCoordinator() {
HLocaleMember member = getLocaleMember();
if (member != null) {
Expand Down
16 changes: 11 additions & 5 deletions zanata-war/src/main/java/org/zanata/action/NewProfileAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package org.zanata.action;

import java.io.Serializable;

import lombok.extern.slf4j.Slf4j;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Create;
Expand All @@ -30,8 +31,10 @@
import org.jboss.seam.annotations.Transactional;
import org.jboss.seam.faces.FacesMessages;
import org.zanata.ApplicationConfiguration;
import org.zanata.i18n.Messages;
import org.zanata.security.AuthenticationType;
import org.zanata.security.ZanataOpenId;
import org.zanata.service.EmailService;
import org.zanata.service.RegisterService;

/**
Expand All @@ -47,6 +50,11 @@ public class NewProfileAction extends AbstractProfileAction implements Serializa
@In
private ZanataOpenId zanataOpenId;

@In
private EmailService emailServiceImpl;
@In
Messages msgs;

@In
RegisterService registerServiceImpl;

Expand Down Expand Up @@ -92,12 +100,10 @@ public void createUser() {
.getAuthResult().getAuthenticatedId(),
AuthenticationType.OPENID, this.name, this.email);
}
setActivationKey(key);
renderer.render("/WEB-INF/facelets/email/email_activation.xhtml");
String message =
emailServiceImpl.sendActivationEmail(this.name, this.email, key);
identity.unAuthenticate();
FacesMessages
.instance()
.add("You will soon receive an email with a link to activate your account.");
FacesMessages.instance().add(message);
}

public void cancel() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,36 @@
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotEmpty;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.End;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.faces.FacesMessages;
import org.jboss.seam.faces.Renderer;
import org.zanata.dao.AccountDAO;
import org.zanata.model.HAccount;
import org.zanata.model.HAccountResetPasswordKey;
import org.zanata.service.EmailService;
import org.zanata.service.UserAccountService;

@Name("passwordResetRequest")
@NoArgsConstructor
@Scope(ScopeType.EVENT)
@Slf4j
public class PasswordResetRequestAction implements Serializable {
private static final long serialVersionUID = 1L;

@In
private AccountDAO accountDAO;

@In
private EmailService emailServiceImpl;
@In
private UserAccountService userAccountServiceImpl;

@In(create = true)
private Renderer renderer;

private String username;
private String email;
private String activationKey;
Expand All @@ -61,7 +60,7 @@ public void setEmail(String email) {
this.email = email;
}

@Email
@org.hibernate.validator.constraints.Email
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for the fully qualified name? There doesn't seem to be a conflicting import.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I seem to recall running into a class name collision, perhaps with the other mock-email library, but it doesn't seem to be a problem now. In any case, I think this makes it clear that it is a validator constraint, which @Email doesn't quite achieve by itself.

@NotEmpty
public String getEmail() {
return email;
Expand All @@ -77,13 +76,10 @@ public String requestReset() {
FacesMessages.instance().add("No such account found");
return null;
} else {
setActivationKey(key.getKeyHash());
renderer.render("/WEB-INF/facelets/email/password_reset.xhtml");
log.info("Sent password reset key to {} ({})", account
.getPerson().getName(), account.getUsername());
FacesMessages
.instance()
.add("You will soon receive an email with a link to reset your password.");
String message =
emailServiceImpl.sendPasswordResetEmail(account.getPerson(),
key.getKeyHash());
FacesMessages.instance().add(message);
return "/home.xhtml";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ public String register() {
log.info("get register key:" + key);

String message =
emailServiceImpl.sendActivationEmail(
EmailService.ACTIVATION_ACCOUNT_EMAIL_TEMPLATE, user,
email, key);
emailServiceImpl.sendActivationEmail(user, email, key);
FacesMessages.instance().add(message);

return "/home.xhtml";
Expand Down