aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2015-02-08 15:47:07 +0100
committerPacien TRAN-GIRARD2015-02-08 15:47:07 +0100
commita022850963552096dab032fb57c16d3b1d3ac51a (patch)
tree2404424261057b9d0d60daf7c3f34c49dc482f68 /app
parent1dd7d1dd1a796592b4448eba878ddcae8e063407 (diff)
downloadminibay-a022850963552096dab032fb57c16d3b1d3ac51a.tar.gz
Add sign up form and AutoInc on tables uuid
Diffstat (limited to 'app')
-rw-r--r--app/controllers/Account.scala19
-rw-r--r--app/controllers/Application.scala9
-rw-r--r--app/controllers/Console.scala7
-rw-r--r--app/controllers/Profile.scala141
-rw-r--r--app/models/Tables.scala22
-rw-r--r--app/views/fragments/accountInfos.scala.html2
-rw-r--r--app/views/fragments/forms/inputField.scala.html1
-rw-r--r--app/views/fragments/forms/inputLabel.scala.html3
-rw-r--r--app/views/fragments/forms/labeledField.scala.html4
-rw-r--r--app/views/pages/signupForm.scala.html43
10 files changed, 226 insertions, 25 deletions
diff --git a/app/controllers/Account.scala b/app/controllers/Account.scala
new file mode 100644
index 0000000..ff1d44d
--- /dev/null
+++ b/app/controllers/Account.scala
@@ -0,0 +1,19 @@
1package controllers
2
3import play.api._
4import play.api.data._
5import play.api.data.Forms._
6import play.api.mvc._
7
8import play.api.db.slick._
9import play.api.db.slick.Config.driver.simple._
10import play.api.Play.current
11
12import scala.concurrent.Future
13
14import models._
15
16
17object Account {
18
19}
diff --git a/app/controllers/Application.scala b/app/controllers/Application.scala
index 93bba51..deb96d8 100644
--- a/app/controllers/Application.scala
+++ b/app/controllers/Application.scala
@@ -13,20 +13,13 @@ import scala.concurrent.Future
13 13
14import models._ 14import models._
15 15
16
16object Application extends Controller { 17object Application extends Controller {
17 18
18 def index = Auth { implicit request => 19 def index = Auth { implicit request =>
19 Ok(views.html.pages.ebeHomepage()) 20 Ok(views.html.pages.ebeHomepage())
20 } 21 }
21 22
22 def ebe = Auth { implicit request =>
23 Ok(views.html.pages.ebeHomepage())
24 }
25
26 def pepal = Auth { implicit request =>
27 Ok(views.html.pages.pepalHomepage())
28 }
29
30 def terms = Auth { implicit request => 23 def terms = Auth { implicit request =>
31 Ok(views.html.pages.terms()) 24 Ok(views.html.pages.terms())
32 } 25 }
diff --git a/app/controllers/Console.scala b/app/controllers/Console.scala
index 58a2478..5c576b5 100644
--- a/app/controllers/Console.scala
+++ b/app/controllers/Console.scala
@@ -1,7 +1,5 @@
1package controllers 1package controllers
2 2
3import java.sql.Timestamp
4
5import play.api._ 3import play.api._
6import play.api.data._ 4import play.api.data._
7import play.api.data.Forms._ 5import play.api.data.Forms._
@@ -42,11 +40,10 @@ object Console extends Controller {
42 40
43 if (grant > 0) { 41 if (grant > 0) {
44 Tables.Transactions += Tables.Transaction( 42 Tables.Transactions += Tables.Transaction(
45 uuid = java.util.UUID.randomUUID.toString,
46 userUuid = request.account.get.userUuid.get, 43 userUuid = request.account.get.userUuid.get,
47 transactionDate = new Timestamp(new java.util.Date().getTime), 44 transactionDate = new java.sql.Timestamp(new java.util.Date().getTime),
48 amount = grant, 45 amount = grant,
49 label = commandData.command 46 label = "GRANT " + commandData.command
50 ) 47 )
51 48
52 Redirect(routes.Application.index()).flashing("success" -> commandData.command) 49 Redirect(routes.Application.index()).flashing("success" -> commandData.command)
diff --git a/app/controllers/Profile.scala b/app/controllers/Profile.scala
new file mode 100644
index 0000000..a41b3e9
--- /dev/null
+++ b/app/controllers/Profile.scala
@@ -0,0 +1,141 @@
1package controllers
2
3import play.api._
4import play.api.data._
5import play.api.data.Forms._
6import play.api.mvc._
7
8import play.api.db.slick._
9import play.api.db.slick.Config.driver.simple._
10import play.api.Play.current
11
12import scala.concurrent.Future
13
14import models._
15
16
17case class SignupData(username: String,
18 email: String,
19 password: String,
20 passwordCheck: String,
21 firstName: String,
22 lastName: String,
23 country: String,
24 postalCode: String,
25 address: String,
26 phone: String,
27 birthdate: java.sql.Date)
28
29case class ProfileData(email: String,
30 password: String,
31 passwordCheck: String,
32 country: String,
33 postalCode: String,
34 address: String,
35 phone: String)
36
37
38object Profile extends Controller {
39
40 val signupForm = Form(
41 mapping(
42 "username" -> nonEmptyText(minLength = 3, maxLength = 20),
43 "email" -> email,
44 "password" -> nonEmptyText(minLength = 5, maxLength = 255),
45 "passwordCheck" -> nonEmptyText(minLength = 5, maxLength = 255),
46 "firstName" -> nonEmptyText(minLength = 1, maxLength = 255),
47 "lastName" -> nonEmptyText(minLength = 1, maxLength = 255),
48 "country" -> nonEmptyText(minLength = 2, maxLength = 2),
49 "postalCode" -> nonEmptyText(minLength = 4, maxLength = 20),
50 "address" -> nonEmptyText(minLength = 5, maxLength = 255),
51 "phone" -> nonEmptyText(minLength = 5, maxLength = 20),
52 "birthdate" -> sqlDate
53 )(SignupData.apply)(SignupData.unapply)
54 .verifying("Password mismatch", fields => fields match {
55 case profileData => checkPasswordCoherence(profileData.password, profileData.passwordCheck)
56 })
57 .verifying("Username already registered", fields => fields match {
58 case profileData => !checkUsernameUse(profileData.username)
59 })
60 .verifying("Email address already in use", fields => fields match {
61 case profileData => !checkEmailUse(profileData.email)
62 })
63 )
64
65 val profileForm = Form(
66 mapping(
67 "email" -> email,
68 "password" -> text(maxLength = 255),
69 "passwordCheck" -> text(maxLength = 255),
70 "country" -> nonEmptyText(minLength = 2, maxLength = 2),
71 "postalCode" -> nonEmptyText(minLength = 4, maxLength = 20),
72 "address" -> nonEmptyText(minLength = 5, maxLength = 255),
73 "phone" -> nonEmptyText(minLength = 5, maxLength = 20)
74 )(ProfileData.apply)(ProfileData.unapply)
75 .verifying("Password mismatch", fields => fields match {
76 case profileData => checkPasswordCoherence(profileData.password, profileData.passwordCheck)
77 })
78 .verifying("Email address already in use", fields => fields match {
79 case profileData => !checkEmailUse(profileData.email)
80 })
81 )
82
83
84 def checkPasswordCoherence(p1: String, p2: String) = {
85 p1 == p2
86 }
87
88 def checkUsernameUse(username: String) = DB.withSession { implicit session =>
89 Tables.Users.filter(_.username === username).length.run > 0
90 }
91
92 def checkEmailUse(email: String) = DB.withSession { implicit session =>
93 Tables.Users.filter(_.email === email).length.run > 0
94 }
95
96
97 def signup = Auth { implicit request =>
98 if (request.account.nonEmpty) {
99 Redirect(routes.Application.index())
100 } else {
101 Ok(views.html.pages.signupForm(signupForm))
102 }
103 }
104
105 def signupSubmit = Auth { implicit request =>
106 if (request.account.nonEmpty) {
107 Redirect(routes.Application.index())
108 } else {
109 DB.withSession { implicit session =>
110 signupForm.bindFromRequest.fold(
111 formWithErrors => {
112 BadRequest(views.html.pages.signupForm(formWithErrors))
113 },
114 validForm => {
115
116 val users = Tables.Users returning Tables.Users.map(_.uuid)
117 val uuid = users += Tables.User(
118 username = validForm.username,
119 email = validForm.email,
120 userPassword = validForm.password,
121 creationDate = new java.sql.Timestamp(new java.util.Date().getTime),
122 firstName = validForm.firstName,
123 lastName = validForm.lastName,
124 countryCode = validForm.country,
125 postalCode = validForm.postalCode,
126 address = validForm.address,
127 phone = validForm.phone,
128 birthdate = new java.sql.Timestamp(validForm.birthdate.getTime)
129 )
130
131 Redirect(routes.Application.index())
132 .withSession(Security.username -> uuid)
133 .flashing("success" -> "You are now registered. Welcome! You may now spend your money.")
134
135 }
136 )
137 }
138 }
139 }
140
141}
diff --git a/app/models/Tables.scala b/app/models/Tables.scala
index ff1f267..24e0aeb 100644
--- a/app/models/Tables.scala
+++ b/app/models/Tables.scala
@@ -22,7 +22,7 @@ trait Tables {
22 * @param userUuid Database column user_uuid DBType(varchar), Length(36,true) 22 * @param userUuid Database column user_u