Skip to content
Alvin Prieto edited this page May 9, 2014 · 2 revisions

###Dependencies

Plugins

The following should already be included in the build.sbt

  "mysql" % "mysql-connector-java" % "5.1.21",
  "org.mindrot" % "jbcrypt" % "0.3m",
  "com.typesafe" %% "play-plugins-mailer" % "2.2.0"

*Note: If the build.sbt plugins are not downloaded during the install process run play update

###Download the Source Download the zip file, or clone the repository

$ git clone https://github.com/hawaiihoopsnetwork/HawaiiHoopsNetwork.git
Cloning into 'HawaiiHoopsNetwork'...
remote: Reusing existing pack: 774, done.
remote: Counting objects: 109, done.
remote: Compressing objects: 100% (102/102), done.
remote: Total 883 (delta 42), reused 0 (delta 0)
Receiving objects: 100% (883/883), 1.60 MiB | 215.00 KiB/s, done.
Resolving deltas: 100% (429/429), done.
Checking connectivity... done.

###Configure In conf/application.conf edit the default database and mailer settings

# Database configuration
# ~~~~~
# You can declare as many datasources as you want.
# By convention, the default datasource is named `default`
#
 db.default.driver=org.h2.Driver
 db.default.url="jdbc:h2:mem:play;MODE=MYSQL"
 db.default.user=user
 db.default.password=password

# Mailer:
smtp.host=smtp.gmail.com
smtp.port=587
smtp.ssl=yes
smtp.user=user
smtp.password=password

The application uses the h2 database for development, but when deploying to a production environment the database should be switched to another database (mysql, postgres).

In Application.java, replace mail.setRecipient("HiHoops <hawaiihoopsnetwork@gmail.com>", "hawaiihoopsnetwork@gmail.com"); with your own email account.

public static Result sendMessage() {

        Form<ContactUsForm> formData = Form.form(ContactUsForm.class).bindFromRequest();

        if (formData.hasErrors()) {
            return badRequest(ContactUs.render("Contact Us", formData, Secured.isLoggedIn(ctx())));
        }
        else {
            ContactUsForm message = formData.get();

            MailerAPI mail = play.Play.application().plugin(MailerPlugin.class).email();
            mail.setSubject("New message from: " + message.name);
            mail.setRecipient("HiHoops <hawaiihoopsnetwork@gmail.com>", "hawaiihoopsnetwork@gmail.com");
            mail.setFrom(message.email);
            mail.send(message.message);

            return ok(MessageSent.render("Message Sent", Secured.isLoggedIn(ctx())));
        }
    }

###Run the System To run the application type play run

$ play run
[info] Loading project definition from /home/taylorak/Downloads/HawaiiHoopsNetwork/project

This project uses Play 2.2.0!
Update the Play sbt-plugin version to 2.2.2 (usually in project/plugins.sbt)
        
[info] Set current project to HawaiiHoopsNetwork (in build file:/home/taylorak/Downloads/HawaiiHoopsNetwork/)
[info] Updating {file:/home/taylorak/Downloads/HawaiiHoopsNetwork/}hawaiihoopsnetwork...
[info] Resolving org.hibernate.javax.persistence#hibernate-jpa-2.0-api;1.0.1.Fin[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] downloading http://repo1.maven.org/maven2/org/mindrot/jbcrypt/0.3m/jbcrypt-0.3m.jar ...
[info] 	[SUCCESSFUL ] org.mindrot#jbcrypt;0.3m!jbcrypt.jar (490ms)
[info] downloading http://repo.typesafe.com/typesafe/releases/com/typesafe/play-plugins-mailer_2.10/2.2.0/play-plugins-mailer_2.10-2.2.0.jar ...
[info] 	[SUCCESSFUL ] com.typesafe#play-plugins-mailer_2.10;2.2.0!play-plugins-mailer_2.10.jar (912ms)
[info] downloading http://repo1.maven.org/maven2/org/apache/commons/commons-email/1.2/commons-email-1.2.jar ...
[info] 	[SUCCESSFUL ] org.apache.commons#commons-email;1.2!commons-email.jar (503ms)
[info] downloading http://repo.typesafe.com/typesafe/releases/com/typesafe/play-plugins-util_2.10/2.2.0/play-plugins-util_2.10-2.2.0.jar ...
[info] 	[SUCCESSFUL ] com.typesafe#play-plugins-util_2.10;2.2.0!play-plugins-util_2.10.jar (813ms)
[info] downloading http://repo1.maven.org/maven2/javax/mail/mail/1.4.1/mail-1.4.1.jar ...
[info] 	[SUCCESSFUL ] javax.mail#mail;1.4.1!mail.jar (1599ms)
[info] downloading http://repo1.maven.org/maven2/javax/activation/activation/1.1/activation-1.1.jar ...
[info] 	[SUCCESSFUL ] javax.activation#activation;1.1!activation.jar (641ms)
[info] Done updating.

--- (Running the application from SBT, auto-reloading is enabled) ---

[info] play - Listening for HTTP on /0:0:0:0:0:0:0:0:9000

(Server started, use Ctrl+D to stop and go back to the console...)

To view the running application open a web browser and go to localhost:9000

###The Global File Global.java contains test data that will be initialized when the application is started. To change this behavior delete the onStart method or edit the content.