-
Notifications
You must be signed in to change notification settings - Fork 23
/
UsersController.scala
50 lines (39 loc) · 1.6 KB
/
UsersController.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package controllers
import javax.inject.Inject
import com.alexitc.coinalerts.models._
import com.alexitc.coinalerts.services.UserService
import com.alexitc.coinalerts.services.external.ReCaptchaService
import com.alexitc.playsonify.core.FutureOr.Implicits.FutureOps
class UsersController @Inject()(
reCaptchaService: ReCaptchaService,
components: MyJsonControllerComponents,
userService: UserService)
extends MyJsonController(components) {
def create() = publicWithInput(Created) { context: PublicCtxModel[CreateUserModel] =>
val result = for {
_ <- reCaptchaService.verify(context.model.reCaptchaResponse).toFutureOr
createdUser <- userService.create(context.model)(context.lang).toFutureOr
} yield createdUser
result.toFuture
}
def verifyEmail(token: UserVerificationToken) = publicNoInput { _: PublicCtx =>
userService.verifyEmail(token)
}
def loginByEmail() = publicWithInput { context: PublicCtxModel[LoginByEmailModel] =>
val loginModel = context.model
val result = for {
_ <- reCaptchaService.verify(context.model.reCaptchaResponse).toFutureOr
token <- userService.loginByEmail(loginModel.email, loginModel.password).toFutureOr
} yield token
result.toFuture
}
def whoAmI() = authenticatedNoInput { context: AuthCtx =>
userService.userById(context.auth)
}
def getPreferences() = authenticatedNoInput { context =>
userService.getPreferences(context.auth)
}
def setPreferences() = authenticatedWithInput { context: AuthCtxModel[SetUserPreferencesModel] =>
userService.setPreferences(context.auth, context.model)
}
}