I have created sample seed project with help of existing activator seed samples.
Project basically does User/Password authentication with role based authorization. You can find full source code at https://github.com/pariksheet/dribble.
Technologies:
- Play 2.5.3
- play-silhouette 4.0.0
- play2-reactivemongo 0.11.14
- play-mailer 5.0.5
- Scala 2.11
- Mongo 3.2
Though this code works perfectly, I am not able to use latest features of play/silhouette/mongo. I have few doubts on using those.
Question 1: silhouette
In Module.scala:
Environment[JWTEnv](
identityService,
authenticatorService,
Seq(),
eventBus
)
Here, how to pass Credential Provider Object in Seq()
? As, I am not able to figure out the solution. I am injecting Credential Provider in my all controller classes.
Question 2: ReactiveMongo:
In my UserDao.scala I am using old mongo api to get collection object:
val users = reactiveMongoApi.db.collection[JSONCollection]("users")
Code throws warning:
method db in trait ReactiveMongoApi is deprecated: Use [[database]]
How to use database method? I can see another thread How to setup Play!2.5 with ReactiveMongo, but it does not have a solution.
Question 3: mailer
I am using below config to send email through play app:
smtp.mock=false
smtp {
host="smtp.mail.yahoo.com"
port="465"
ssl=true
user="pari.test@yahoo.com"
password="XXXXXXXXXXX"
from="pari.test@yahoo.com"
}
Code works all good. However, I am getting warning:
smtp is deprecated, use play.mailer instead.
When I use play.mailer configs code fails. Play Mailer plugin with Play 2.5
Question 4: form
How to add validation in play form?
@(tokenId: String, form: Form[ResetPassword])(implicit messages: play.api.i18n.Messages, request: RequestHeader)
@main("Reset Password") {
@helper.form(routes.Application.handleResetPassword(tokenId)) {
@helper.inputText(form("password1"))
@helper.inputText(form("password2"))
<button type="submit">Submit</button>
}
}
In above form, I would like to add validation that will check if password1
and password2
are same or not.