Skip to content

Commit

Permalink
Merge pull request #789 from parallaxinc/demo
Browse files Browse the repository at this point in the history
Version 0.93 251
  • Loading branch information
zfi authored Oct 22, 2016
2 parents 20d1a2a + 7cfd5e2 commit 1ce315a
Show file tree
Hide file tree
Showing 87 changed files with 2,330 additions and 743 deletions.
4 changes: 4 additions & 0 deletions db-updates/0006-add-user-coach.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*
* Add coach email address field to support email cc option.
*/
ALTER TABLE user ADD COLUMN coach_email VARCHAR(250) AFTER screen_name;
24 changes: 24 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,30 @@
<artifactId>metrics-core</artifactId>
<version>${metrics-version}</version>
</dependency>

<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-graphite</artifactId>
<version>${metrics-version}</version>
</dependency>

<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-jvm</artifactId>
<version>${metrics-version}</version>
</dependency>

<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-log4j</artifactId>
<version>${metrics-version}</version>
</dependency>

<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-servlet</artifactId>
<version>${metrics-version}</version>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.google.inject.servlet.GuiceServletContextListener;
import com.parallax.server.blocklyprop.SessionData;
import com.parallax.server.blocklyprop.jsp.Properties;
import com.parallax.server.blocklyprop.monitoring.Monitor;
import com.parallax.server.blocklyprop.utils.HelpFileInitializer;
import java.sql.Driver;
import java.sql.DriverManager;
Expand Down Expand Up @@ -43,6 +44,7 @@ protected void configure() {
bind(Properties.class).asEagerSingleton();

bind(HelpFileInitializer.class).asEagerSingleton();
bind(Monitor.class).asEagerSingleton();

install(new PersistenceModule(configuration));
install(new DaoModule());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.parallax.server.blocklyprop.enums;

/**
*
* @author Michel
*/
public enum ConfirmPage {

ALREADY_CONFIRMED("already-confirmed"),
CONFIRM_REQUESTED("confirm-requested"),
CONFIRMED("confirmed");

private final String page;

private ConfirmPage(String page) {
this.page = page;
}

public String getPage() {
return page;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.parallax.server.blocklyprop.enums;

/**
*
* @author Michel
*/
public enum PasswordResetPage {

RESET_DONE("reset-done"),
RESET_REQUESTED("reset-requested");

private final String page;

private PasswordResetPage(String page) {
this.page = page;
}

public String getPage() {
return page;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.parallax.server.blocklyprop.monitoring;

import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.servlet.InstrumentedFilterContextListener;

/**
*
* @author Michel
*/
public class BlocklyPropInstrumentedFilterContextListener extends InstrumentedFilterContextListener {

@Override
protected MetricRegistry getMetricRegistry() {
return Monitor.metrics();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.parallax.server.blocklyprop.monitoring;

import com.codahale.metrics.ConsoleReporter;
import com.codahale.metrics.MetricFilter;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.graphite.GraphiteReporter;
import com.codahale.metrics.graphite.PickledGraphite;
import com.codahale.metrics.jvm.GarbageCollectorMetricSet;
import com.codahale.metrics.jvm.MemoryUsageGaugeSet;
import com.codahale.metrics.log4j.InstrumentedAppender;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.net.InetSocketAddress;
import java.util.concurrent.TimeUnit;
import org.apache.commons.configuration.Configuration;
import org.apache.log4j.LogManager;

/**
*
* @author Michel
*/
@Singleton
public class Monitor {

private static final MetricRegistry metrics = new MetricRegistry();

private final boolean consoleEnabled;
private final int consoleReportingInterval;

private final boolean graphiteEnabled;
private final String graphitePrefix;
private final String graphiteServerAddress;
private final int graphiteServerPort;
private final int graphiteReportingInterval;

@Inject
public Monitor(Configuration configuration) {
consoleEnabled = configuration.getBoolean("monitor.console.enabled", false);
consoleReportingInterval = configuration.getInt("monitor.console.interval", 300);

graphiteEnabled = configuration.getBoolean("monitor.graphite.enabled", false);
graphitePrefix = configuration.getString("monitor.graphite.prefix", "blocklyprop");
graphiteServerAddress = configuration.getString("monitor.graphite.address", "localhost");
graphiteServerPort = configuration.getInt("monitor.graphite.port", 2003);
graphiteReportingInterval = configuration.getInt("monitor.graphite.interval", 30);

init();
}

private void init() {
if (consoleEnabled) {
ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics).convertDurationsTo(TimeUnit.MILLISECONDS).build();
reporter.start(consoleReportingInterval, TimeUnit.SECONDS);
}

if (graphiteEnabled) {
final PickledGraphite pickledGraphite = new PickledGraphite(new InetSocketAddress(graphiteServerAddress, graphiteServerPort));
final GraphiteReporter graphiteReporter = GraphiteReporter.forRegistry(metrics).prefixedWith(graphitePrefix).convertDurationsTo(TimeUnit.MILLISECONDS).filter(MetricFilter.ALL).build(pickledGraphite);
graphiteReporter.start(graphiteReportingInterval, TimeUnit.SECONDS);
}

InstrumentedAppender appender = new InstrumentedAppender(metrics);
appender.activateOptions();

LogManager.getRootLogger().addAppender(appender);

MemoryUsageGaugeSet memoryUsageGaugeSet = new MemoryUsageGaugeSet();
metrics.registerAll(memoryUsageGaugeSet);

GarbageCollectorMetricSet garbageCollectorMetricSet = new GarbageCollectorMetricSet();
metrics.registerAll(garbageCollectorMetricSet);
}

public static MetricRegistry metrics() {
return metrics;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import com.parallax.client.cloudsession.exceptions.ServerException;
import com.parallax.client.cloudsession.exceptions.UnknownUserException;
import com.parallax.client.cloudsession.exceptions.WrongAuthenticationSourceException;
import com.parallax.server.blocklyprop.enums.ConfirmPage;
import com.parallax.server.blocklyprop.utils.ServletUtils;
import com.parallax.server.blocklyprop.utils.TextileReader;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
Expand All @@ -32,6 +35,8 @@ public class ConfirmRequestServlet extends HttpServlet {

private static Logger log = LoggerFactory.getLogger(ConfirmRequestServlet.class);

private final TextileReader textileFileReader = new TextileReader();

private CloudSessionLocalUserService cloudSessionLocalUserService;
private Configuration configuration;

Expand All @@ -54,7 +59,8 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws S
} else {
try {
if (cloudSessionLocalUserService.requestNewConfirmEmail(email)) {
req.getRequestDispatcher("WEB-INF/servlet/confirm/confirm-requested.jsp").forward(req, resp);
showTextilePage(req, resp, ConfirmPage.CONFIRM_REQUESTED);
//req.getRequestDispatcher("WEB-INF/servlet/confirm/confirm-requested.jsp").forward(req, resp);
} else {
req.setAttribute("error", true);
req.getRequestDispatcher("WEB-INF/servlet/confirm/confirm-request.jsp").forward(req, resp);
Expand All @@ -66,7 +72,8 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws S
req.setAttribute("insufficientTokens", true);
req.getRequestDispatcher("WEB-INF/servlet/confirm/confirm-request.jsp").forward(req, resp);
} catch (EmailAlreadyConfirmedException ex) {
req.getRequestDispatcher("WEB-INF/servlet/confirm/already-confirmed.jsp").forward(req, resp);
showTextilePage(req, resp, ConfirmPage.ALREADY_CONFIRMED);
//req.getRequestDispatcher("WEB-INF/servlet/confirm/already-confirmed.jsp").forward(req, resp);
} catch (ServerException se) {
req.setAttribute("server-exception", "Server exception");
req.getRequestDispatcher("WEB-INF/servlet/confirm/confirm-request.jsp").forward(req, resp);
Expand All @@ -78,4 +85,10 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws S
}
}

public void showTextilePage(HttpServletRequest req, HttpServletResponse resp, ConfirmPage confirmPage) throws ServletException, IOException {
String html = textileFileReader.readFile("confirm/" + confirmPage.getPage(), ServletUtils.getLocale(req), req.isSecure());
req.setAttribute("html", html);
req.getRequestDispatcher("/WEB-INF/servlet/html.jsp").forward(req, resp);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import com.parallax.client.cloudsession.exceptions.UnknownUserException;
import com.parallax.client.cloudsession.exceptions.WrongAuthenticationSourceException;
import com.parallax.server.blocklyprop.db.dao.UserDao;
import com.parallax.server.blocklyprop.enums.ConfirmPage;
import com.parallax.server.blocklyprop.utils.ServletUtils;
import com.parallax.server.blocklyprop.utils.TextileReader;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
Expand All @@ -31,6 +34,8 @@ public class ConfirmServlet extends HttpServlet {

private static Logger log = LoggerFactory.getLogger(ConfirmServlet.class);

private final TextileReader textileFileReader = new TextileReader();

private CloudSessionLocalUserService cloudSessionLocalUserService;
private Configuration configuration;

Expand Down Expand Up @@ -67,7 +72,9 @@ public void confirmToken(HttpServletRequest req, HttpServletResponse resp) throw
} else {
try {
if (cloudSessionLocalUserService.doConfirm(email, token)) {
req.getRequestDispatcher("WEB-INF/servlet/confirm/confirmed.jsp").forward(req, resp);
// req.getRequestDispatcher("WEB-INF/servlet/confirm/confirmed.jsp").forward(req, resp);

showTextilePage(req, resp, ConfirmPage.CONFIRMED);
} else {
req.setAttribute("invalidToken", "Invalid token");
req.getRequestDispatcher("WEB-INF/servlet/confirm/confirm.jsp").forward(req, resp);
Expand All @@ -86,4 +93,10 @@ public void confirmToken(HttpServletRequest req, HttpServletResponse resp) throw
}
}

public void showTextilePage(HttpServletRequest req, HttpServletResponse resp, ConfirmPage confirmPage) throws ServletException, IOException {
String html = textileFileReader.readFile("confirm/" + confirmPage.getPage(), ServletUtils.getLocale(req), req.isSecure());
req.setAttribute("html", html);
req.getRequestDispatcher("/WEB-INF/servlet/html.jsp").forward(req, resp);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import com.parallax.client.cloudsession.exceptions.ServerException;
import com.parallax.client.cloudsession.exceptions.UnknownUserException;
import com.parallax.client.cloudsession.exceptions.WrongAuthenticationSourceException;
import com.parallax.server.blocklyprop.enums.PasswordResetPage;
import com.parallax.server.blocklyprop.utils.ServletUtils;
import com.parallax.server.blocklyprop.utils.TextileReader;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
Expand All @@ -31,6 +34,8 @@ public class PasswordResetRequestServlet extends HttpServlet {

private static Logger log = LoggerFactory.getLogger(PasswordResetRequestServlet.class);

private final TextileReader textileFileReader = new TextileReader();

private CloudSessionLocalUserService cloudSessionLocalUserService;
private Configuration configuration;

Expand All @@ -53,7 +58,8 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws S
} else {
try {
if (cloudSessionLocalUserService.requestPasswordReset(email)) {
req.getRequestDispatcher("WEB-INF/servlet/password-reset/reset-requested.jsp").forward(req, resp);
showTextilePage(req, resp, PasswordResetPage.RESET_REQUESTED);
// req.getRequestDispatcher("WEB-INF/servlet/password-reset/reset-requested.jsp").forward(req, resp);
} else {
req.setAttribute("error", true);
req.getRequestDispatcher("WEB-INF/servlet/password-reset/reset-request.jsp").forward(req, resp);
Expand All @@ -75,4 +81,10 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws S
}
}

public void showTextilePage(HttpServletRequest req, HttpServletResponse resp, PasswordResetPage passwordResetPage) throws ServletException, IOException {
String html = textileFileReader.readFile("password-reset/" + passwordResetPage.getPage(), ServletUtils.getLocale(req), req.isSecure());
req.setAttribute("html", html);
req.getRequestDispatcher("/WEB-INF/servlet/html.jsp").forward(req, resp);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import com.parallax.client.cloudsession.exceptions.ServerException;
import com.parallax.client.cloudsession.exceptions.UnknownUserException;
import com.parallax.client.cloudsession.exceptions.WrongAuthenticationSourceException;
import com.parallax.server.blocklyprop.enums.PasswordResetPage;
import com.parallax.server.blocklyprop.utils.ServletUtils;
import com.parallax.server.blocklyprop.utils.TextileReader;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
Expand All @@ -32,6 +35,8 @@ public class PasswordResetServlet extends HttpServlet {

private static Logger log = LoggerFactory.getLogger(PasswordResetServlet.class);

private final TextileReader textileFileReader = new TextileReader();

private CloudSessionLocalUserService cloudSessionLocalUserService;
private Configuration configuration;

Expand Down Expand Up @@ -63,7 +68,8 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws S
} else {
try {
if (cloudSessionLocalUserService.doPasswordReset(token, email, password, confirmPassword)) {
req.getRequestDispatcher("WEB-INF/servlet/password-reset/reset-done.jsp").forward(req, resp);
showTextilePage(req, resp, PasswordResetPage.RESET_DONE);
//req.getRequestDispatcher("WEB-INF/servlet/password-reset/reset-done.jsp").forward(req, resp);
} else {
req.setAttribute("invalidToken", "Invalid token");
req.getRequestDispatcher("WEB-INF/servlet/password-reset/do-reset.jsp").forward(req, resp);
Expand All @@ -88,4 +94,10 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws S
}
}

public void showTextilePage(HttpServletRequest req, HttpServletResponse resp, PasswordResetPage passwordResetPage) throws ServletException, IOException {
String html = textileFileReader.readFile("password-reset/" + passwordResetPage.getPage(), ServletUtils.getLocale(req), req.isSecure());
req.setAttribute("html", html);
req.getRequestDispatcher("/WEB-INF/servlet/html.jsp").forward(req, resp);
}

}
Loading

0 comments on commit 1ce315a

Please sign in to comment.