mirror of
https://github.com/lichess-org/lila.git
synced 2026-05-26 13:51:00 +00:00
34 lines
1.1 KiB
Scala
34 lines
1.1 KiB
Scala
package controllers
|
|
|
|
import lila.app.*
|
|
import lila.common.HTTPRequest
|
|
import lila.push.WebSubscription
|
|
import lila.oauth.AccessToken
|
|
|
|
final class Push(env: Env) extends LilaController(env):
|
|
|
|
def mobileRegister(platform: String, deviceId: String) = AuthOrScoped(_.Web.Mobile, _.Web.Takex3) {
|
|
ctx ?=> me ?=>
|
|
env.push.registerDevice(me, platform, deviceId).inject(NoContent)
|
|
}
|
|
|
|
def mobileUnregister = AuthOrScoped(_.Web.Mobile, _.Web.Takex3) { ctx ?=> me ?=>
|
|
env.push.unregisterDevices(me).inject(NoContent)
|
|
}
|
|
|
|
def webSubscribe = AuthOrScopedBodyWithParser(parse.json)(_.Web.Mobile, _.Web.Takex3) { ctx ?=> me ?=>
|
|
val currentSessionId =
|
|
if ctx.isMobileOauth then HTTPRequest.bearer(ctx.req).map(AccessToken.idFrom)
|
|
else env.security.api.reqSessionId(ctx.req)
|
|
|
|
currentSessionId match
|
|
case Some(currentSessionId) =>
|
|
ctx.body.body
|
|
.validate[WebSubscription]
|
|
.fold(
|
|
err => BadRequest(err.toString),
|
|
data => env.push.webSubscriptionApi.subscribe(me, data, currentSessionId).inject(NoContent)
|
|
)
|
|
case None => BadRequest("Session ID is missing")
|
|
}
|