Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

end to end spike now in place

  • Loading branch information...
commit e89e708384ec2264c832e9002755c822df952b85 1 parent a172eb3
@kouphax authored
View
5 app/controllers/Application.scala
@@ -2,9 +2,10 @@ package controllers
import play.api._
import play.api.mvc._
+import models._
object Application extends Controller {
- def index = Action {
- Ok(views.html.index())
+ def index = Action { implicit request =>
+ Ok(views.html.index(Registrations.all))
}
}
View
9 app/controllers/Register.scala
@@ -21,14 +21,17 @@ object Register extends Controller {
})
)
- def index = Action {
- Ok(views.html.register(registrationForm.fill(Registration("","","",""))))
+ def index = Action { implicit request =>
+ Ok(views.html.register(registrationForm))
}
def register = Action { implicit request =>
registrationForm.bindFromRequest.fold(
form => BadRequest(views.html.register(form)),
- registration => Redirect(routes.Application.index())
+ registration => {
+ Registrations.create(registration)
+ Redirect(routes.Application.index()).flashing("message" -> "User Registered!")
+ }
)
}
}
View
17 app/models/Registration.scala
@@ -1,4 +1,19 @@
package models
-// STEP 1: Define the registration case class
+import com.mongodb.casbah.Imports._
+import com.mongodb.casbah.commons.ValidBSONType.BasicDBList
+import com.novus.salat._
+import com.novus.salat.global._
+import com.mongodb.casbah.Imports._
+import com.novus.salat.annotations._
+
case class Registration(username: String, password: String, confirm: String, realName: String)
+
+object Registrations {
+ val registrations = MongoConnection()("sampleapp")("registrations")
+
+ def all = registrations.map(grater[Registration].asObject(_)).toList
+ def create(registration: Registration) {
+ registrations += grater[Registration].asDBObject(registration)
+ }
+}
View
26 app/views/index.scala.html
@@ -1,3 +1,27 @@
+@(registrations: List[Registration])(implicit flash: Flash)
@main("Super Simple Sample") {
- <a href="@routes.Register.index">Register</a>
+ @if(flash.data.contains("message")){
+ <div class='row'>
+ <div class="alert alert-success" style="margin-left:30px;margin-top:20px;">@flash.get("message")</div>
+ </div>
+ }
+ <div style="margin-top:20px;margin-bottom:20px;">
+ <a href="@routes.Register.index" class="btn btn-primary">Register</a>
+ </div>
+ <table class="table table-bordered">
+ <thead>
+ <tr>
+ <th>Username</th>
+ <th>Real Name</th>
+ </tr>
+ </thead>
+ <tbody>
+ @registrations.map { registration =>
+ <tr>
+ <td>@registration.username</td>
+ <td>@registration.realName</td>
+ </tr>
+ }
+ </tbody>
+ </table>
}
View
18 app/views/register.scala.html
@@ -1,4 +1,4 @@
-@(registrationForm: Form[models.Registration])
+@(registrationForm: Form[models.Registration])(implicit flash: Flash)
@import play.api.i18n._
@import views.html.helper._
@@ -7,7 +7,7 @@
<div class="control-group @if(field.hasErrors) {error}">
<label class="control-label" for="@field.id">@label</label>
<div class="controls">
- <input type="@fieldType" value="@field.value" name="@field.id" />
+ <input type="@fieldType.name" value="@field.value" name="@field.id" />
@if(field.hasErrors){
<span class="help-inline">
@Messages(field.error.head.message)
@@ -19,19 +19,21 @@
@main("Super Simple Sample") {
- @* GLOBAL ERROR/FLASH MESSAGE *@
- @registrationForm.globalError.map { error =>
- <div class="alert alert-error">@error.message</div>
- }
-
@form(action = routes.Register.register, 'class -> "form-horizontal") {
+
<fieldset>
<legend>Registration</legend>
+ @* GLOBAL ERROR/FLASH MESSAGE *@
+ @registrationForm.globalError.map { error =>
+ <div class='row'>
+ <div class="alert alert-error" style="margin-left:30px;margin-top:20px;">@error.message</div>
+ </div>
+ }
@input(registrationForm("username"), "Username")
@input(registrationForm("password"), "Password", 'password)
@input(registrationForm("confirm"), "Confirm Password", 'password)
@input(registrationForm("realName"), "Real Name")
</fieldset>
- <input type="submit" class="btn" value="register"/>
+ <input type="submit" class="btn" value="Register"/>
}
}
View
10 project/Build.scala
@@ -8,11 +8,15 @@ object ApplicationBuild extends Build {
val appVersion = "1.0-SNAPSHOT"
val appDependencies = Seq(
- "com.github.twitter" % "bootstrap" % "2.0.2"
+ "com.github.twitter" % "bootstrap" % "2.0.2",
+ "com.mongodb.casbah" %% "casbah" % "2.1.5-1",
+ "com.novus" %% "salat-core" % "0.0.8-SNAPSHOT"
)
val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings(
- resolvers ++= Seq("webjars" at "http://webjars.github.com/m2")
+ resolvers ++= Seq(
+ "webjars" at "http://webjars.github.com/m2",
+ "repo.novus snaps" at "http://repo.novus.com/snapshots/"
+ )
)
-
}
Please sign in to comment.
Something went wrong with that request. Please try again.