Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/Application.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import repositories.UserRepository
class Application extends Controller {

def index = Action {
UserRepository.insert(User(Some(1), "testtest"))
UserRepository.insert(User(Some(1), "testtest", "bla", "blaa"))
Ok(views.html.index("Your new application is ready."))
}

Expand Down
15 changes: 15 additions & 0 deletions app/controllers/Sessions.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package controllers

import play.api.mvc._
import org.mindrot.jbcrypt.BCrypt

class Sessions extends Controller {
def create = Action(parse.urlFormEncoded) { implicit request =>
val email = request.body.get("email").get.head
val password = request.body.get("password").get.head

val user = UserRepository.findByEmail(email)

Ok(s"$email $password")
}
}
11 changes: 11 additions & 0 deletions app/controllers/Users.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package controllers

import play.api.mvc._

class Users extends Controller {
def login = Action {
Ok(views.html.main("login") {
views.html.users.login()
})
}
}
2 changes: 1 addition & 1 deletion app/models/User.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package models

case class User(id: Option[Int] = None, name: String)
case class User(id: Option[Int] = None, email: String, password: String, salt: String)
17 changes: 15 additions & 2 deletions app/repositories/UserRepository.scala
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
package repositories

import slick.driver.PostgresDriver.simple._
import slick.driver.JdbcProfile

import play.api.Play.current
import play.api.db.slick.DatabaseConfigProvider
import play.api.db.DBApi

import scala.concurrent.Future

import models.User
import tables.UserTable

object UserRepository extends UserTable {
val db = Database.forConfig("testdb")
val users = TableQuery[Users]
protected val dbConfig = DatabaseConfigProvider.get[JdbcProfile]("testdb")(current)
import dbConfig._
import dbConfig.driver.api._

def insert(user: User) = {
db.withSession { implicit session =>
users.insert(user)
}
}

def findByEmail(email: String) : Option[User] = {

}
}
11 changes: 8 additions & 3 deletions app/tables/UserTable.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package tables

import models.User
import slick.driver.PostgresDriver.api._
import models.User

trait UserTable {
class Users(tag: Tag) extends Table[User](tag, "users") {
def id = column[Int]("id", O.PrimaryKey, O.AutoInc)
def name = column[String]("name")
def email = column[String]("email")
def password = column[String]("password")
def salt = column[String]("salt")

def * =
(id.?, name) <> (User.tupled, User.unapply)
(id.?, email, password, salt) <> (User.tupled, User.unapply)
}

val users = TableQuery[Users]
}
4 changes: 1 addition & 3 deletions app/views/index.scala.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
@(message: String)

@main("Welcome to Play") {

@play20.welcome(message)

Test
}
24 changes: 15 additions & 9 deletions app/views/main.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@
<!DOCTYPE html>

<html lang="en">
<head>
<title>@title</title>
<link rel="stylesheet" media="screen" href="@routes.Assets.versioned("stylesheets/main.css")">
<link rel="shortcut icon" type="image/png" href="@routes.Assets.versioned("images/favicon.png")">
<script src="@routes.Assets.versioned("javascripts/hello.js")" type="text/javascript"></script>
</head>
<body>
@content
</body>
<head>
<title>@title</title>
<link rel="stylesheet" media="screen" href="@routes.Assets.versioned("stylesheets/main.css")">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="shortcut icon" type="image/png" href="@routes.Assets.versioned("images/favicon.png")">
<script src="@routes.Assets.versioned("javascripts/hello.js")" type="text/javascript"></script>
</head>
<body>
<div class="navbar">
@navbar()
</div>
<div class="main-content container">
@content
</div>
</body>
</html>
7 changes: 7 additions & 0 deletions app/views/navbar.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<nav class="navbar navbar-inverse">
<ul class="nav navbar-nav">
<li>
<a href="/users/login"> Login </a>
</li>
</ul>
</nav>
11 changes: 11 additions & 0 deletions app/views/users/login.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<form action="/sessions/create" method="POST" enctype="application/x-www-form-urlencoded">
<div class="form-group">
<label> E-Mail </label>
<input type="email" name="email" class="form-control" required />
</div>
<div class="form-group">
<label> Password </label>
<input type="password" name="password" class="form-control" required />
</div>
<input type="submit" value="Login" />
</form>
6 changes: 4 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.11.6"

libraryDependencies ++= Seq(
jdbc,
cache,
ws,
specs2 % Test,
"com.typesafe.play" %% "play-slick" % "1.0.0",
"org.postgresql" % "postgresql" % "9.4-1200-jdbc4"
"com.typesafe.play" %% "play-slick-evolutions" % "1.0.0",
"org.postgresql" % "postgresql" % "9.4-1200-jdbc4",
"org.mindrot" % "jbcrypt" % "0.3m"
)

resolvers += "scalaz-bintray" at "http://dl.bintray.com/scalaz/releases"
resolvers += "jbcrypt repo" at "http://mvnrepository.com/"

// Play provides two styles of routers, one expects its actions to be injected, the
// other, legacy style, accesses its actions statically.
Expand Down
57 changes: 11 additions & 46 deletions conf/application.conf
Original file line number Diff line number Diff line change
@@ -1,51 +1,16 @@
# This is the main configuration file for the application.
# ~~~~~

# Secret key
# ~~~~~
# The secret key is used to secure cryptographics functions.
#
# This must be changed for production, but we recommend not changing it in this file.
#
# See http://www.playframework.com/documentation/latest/ApplicationSecret for more details.
play.crypto.secret = "changeme"

# The application languages
# ~~~~~
play.i18n.langs = [ "en" ]

# Router
# ~~~~~
# Define the Router object to use for this application.
# This router will be looked up first when the application is starting up,
# so make sure this is the entry point.
# Furthermore, it's assumed your route file is named properly.
# So for an application router like `my.application.Router`,
# you may need to define a router file `conf/my.application.routes`.
# Default to Routes in the root package (and conf/routes)
# play.http.router = my.application.Routes

# 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"
# db.default.user=sa
# db.default.password=""

testdb: {
driver: "org.postgresql.Driver",
url: "jdbc:postgresql://localhost:5432/play_app",
user: "fh",
password: ""
slick.dbs {
testdb: {
driver: "slick.driver.PostgresDriver$"

db: {
driver: "org.postgresql.Driver",
url: "jdbc:postgresql://localhost:5432/play_app",
username: "fh",
password: ""
}
}
}

# Evolutions
# ~~~~~
# You can disable evolutions if needed
# play.evolutions.enabled=false

# You can disable evolutions for a specific datasource if necessary
# play.evolutions.db.default.enabled=false
14 changes: 14 additions & 0 deletions conf/evolutions/testdb/1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Users schema

# --- !Ups

CREATE TABLE "users" (
id bigserial primary key,
email varchar(255) not null,
password varchar(255) not null,
salt varchar(255) not null
);

# --- !Downs

DROP TABLE "users";
10 changes: 5 additions & 5 deletions conf/routes
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~

# Home page
GET / controllers.Application.index

# User routes
GET /users/login controllers.Users.login

POST /sessions/create controllers.Sessions.create

# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)