Skip to content

Commit

Permalink
reformat ALL the code, using sbt-scalariform
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Feb 14, 2017
1 parent 66cfd08 commit 54cdf0c
Show file tree
Hide file tree
Showing 636 changed files with 5,950 additions and 4,472 deletions.
15 changes: 10 additions & 5 deletions app/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ final class Env(
config: Config,
val scheduler: lila.common.Scheduler,
val system: ActorSystem,
appPath: String) {
appPath: String
) {

val CliUsername = config getString "cli.username"

Expand All @@ -26,7 +27,8 @@ final class Env(
countRounds = Env.round.count,
lobbyApi = Env.api.lobbyApi,
getPlayban = Env.playban.api.currentBan _,
lightUserApi = Env.user.lightUserApi)
lightUserApi = Env.user.lightUserApi
)

lazy val userInfo = mashup.UserInfo(
bookmarkApi = Env.bookmark.api,
Expand All @@ -44,13 +46,15 @@ final class Env(
fetchIsCoach = Env.coach.api.isListedCoach,
insightShare = Env.insight.share,
getPlayTime = Env.game.playTime.apply,
completionRate = Env.playban.api.completionRate) _
completionRate = Env.playban.api.completionRate
) _

lazy val teamInfo = new mashup.TeamInfoApi(
api = Env.team.api,
getForumNbPosts = Env.forum.categApi.teamNbPosts _,
getForumPosts = Env.forum.recent.team _,
asyncCache = Env.memo.asyncCache)
asyncCache = Env.memo.asyncCache
)

private def tryDailyPuzzle(): Fu[Option[lila.puzzle.DailyPuzzle]] =
scala.concurrent.Future {
Expand Down Expand Up @@ -115,7 +119,8 @@ object Env {
config = lila.common.PlayApp.loadConfig,
scheduler = lila.common.PlayApp.scheduler,
system = lila.common.PlayApp.system,
appPath = lila.common.PlayApp withApp (_.path.getCanonicalPath))
appPath = lila.common.PlayApp withApp (_.path.getCanonicalPath)
)

def api = lila.api.Env.current
def db = lila.db.Env.current
Expand Down
9 changes: 3 additions & 6 deletions app/Global.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ object Global extends GlobalSettings {
else if (niceError(req)) {
lila.mon.http.response.code400()
controllers.Lobby.handleStatus(req, Results.BadRequest)
}
else fuccess(BadRequest(error))
} else fuccess(BadRequest(error))

override def onError(req: RequestHeader, ex: Throwable) =
if (niceError(req)) {
Expand All @@ -47,8 +46,6 @@ object Global extends GlobalSettings {
fuccess(InternalServerError(views.html.base.errorPage(ex) {
lila.api.Context(req, lila.app.Env.api.assetVersion.get)
}))
}
else super.onError(req, ex)
}
else fuccess(InternalServerError(ex.getMessage))
} else super.onError(req, ex)
} else fuccess(InternalServerError(ex.getMessage))
}
207 changes: 98 additions & 109 deletions app/controllers/Account.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,125 +15,118 @@ object Account extends LilaController {
private def relationEnv = Env.relation
private def forms = lila.user.DataForm

def profile = Auth { implicit ctx =>
me =>
Ok(html.account.profile(me, forms profileOf me)).fuccess
def profile = Auth { implicit ctx => me =>
Ok(html.account.profile(me, forms profileOf me)).fuccess
}

def profileApply = AuthBody { implicit ctx =>
me =>
implicit val req: Request[_] = ctx.body
FormFuResult(forms.profile) { err =>
fuccess(html.account.profile(me, err))
} { profile =>
UserRepo.setProfile(me.id, profile) inject Redirect(routes.User show me.username)
}
def profileApply = AuthBody { implicit ctx => me =>
implicit val req: Request[_] = ctx.body
FormFuResult(forms.profile) { err =>
fuccess(html.account.profile(me, err))
} { profile =>
UserRepo.setProfile(me.id, profile) inject Redirect(routes.User show me.username)
}
}

def info = Open { implicit ctx =>
negotiate(
html = notFound,
api = _ => ctx.me match {
case None => fuccess(unauthorizedApiResult)
case Some(me) =>
relationEnv.api.countFollowers(me.id) zip
relationEnv.api.countFollowing(me.id) zip
Env.pref.api.getPref(me) zip
lila.game.GameRepo.urgentGames(me) zip
Env.challenge.api.countInFor.get(me.id) map {
case ((((nbFollowers, nbFollowing), prefs), povs), nbChallenges) =>
Env.current.bus.publish(lila.user.User.Active(me), 'userActive)
Ok {
import play.api.libs.json._
import lila.pref.JsonView._
Env.user.jsonView(me) ++ Json.obj(
"prefs" -> prefs,
"nowPlaying" -> JsArray(povs take 20 map Env.api.lobbyApi.nowPlaying),
"nbFollowing" -> nbFollowing,
"nbFollowers" -> nbFollowers,
"kid" -> me.kid.option(true),
"troll" -> me.troll.option(true),
"nbChallenges" -> nbChallenges
).noNull
}
}
}
case None => fuccess(unauthorizedApiResult)
case Some(me) =>
relationEnv.api.countFollowers(me.id) zip
relationEnv.api.countFollowing(me.id) zip
Env.pref.api.getPref(me) zip
lila.game.GameRepo.urgentGames(me) zip
Env.challenge.api.countInFor.get(me.id) map {
case ((((nbFollowers, nbFollowing), prefs), povs), nbChallenges) =>
Env.current.bus.publish(lila.user.User.Active(me), 'userActive)
Ok {
import play.api.libs.json._
import lila.pref.JsonView._
Env.user.jsonView(me) ++ Json.obj(
"prefs" -> prefs,
"nowPlaying" -> JsArray(povs take 20 map Env.api.lobbyApi.nowPlaying),
"nbFollowing" -> nbFollowing,
"nbFollowers" -> nbFollowers,
"kid" -> me.kid.option(true),
"troll" -> me.troll.option(true),
"nbChallenges" -> nbChallenges
).noNull
}
}
}
) map ensureSessionId(ctx.req)
}

def passwd = Auth { implicit ctx =>
me =>
Ok(html.account.passwd(me, forms.passwd)).fuccess
def passwd = Auth { implicit ctx => me =>
Ok(html.account.passwd(me, forms.passwd)).fuccess
}

def passwdApply = AuthBody { implicit ctx =>
me =>
implicit val req = ctx.body
FormFuResult(forms.passwd) { err =>
fuccess(html.account.passwd(me, err))
} { data =>
for {
ok UserRepo.authenticateById(me.id, data.oldPasswd).map(_.isDefined)
_ ok ?? UserRepo.passwd(me.id, data.newPasswd1)
} yield {
val content = html.account.passwd(me, forms.passwd.fill(data), ok.some)
ok.fold(Ok(content), BadRequest(content))
}
def passwdApply = AuthBody { implicit ctx => me =>
implicit val req = ctx.body
FormFuResult(forms.passwd) { err =>
fuccess(html.account.passwd(me, err))
} { data =>
for {
ok UserRepo.authenticateById(me.id, data.oldPasswd).map(_.isDefined)
_ ok ?? UserRepo.passwd(me.id, data.newPasswd1)
} yield {
val content = html.account.passwd(me, forms.passwd.fill(data), ok.some)
ok.fold(Ok(content), BadRequest(content))
}
}
}

private def emailForm(user: UserModel) = UserRepo email user.id map { email =>
Env.security.forms.changeEmail(user).fill(
lila.security.DataForm.ChangeEmail(~email, ""))
lila.security.DataForm.ChangeEmail(~email, "")
)
}

def email = Auth { implicit ctx =>
me =>
emailForm(me) map { form =>
Ok(html.account.email(me, form))
}
def email = Auth { implicit ctx => me =>
emailForm(me) map { form =>
Ok(html.account.email(me, form))
}
}

def emailApply = AuthBody { implicit ctx =>
me =>
UserRepo hasEmail me.id flatMap {
case true => notFound
case false =>
implicit val req = ctx.body
FormFuResult(Env.security.forms.changeEmail(me)) { err =>
fuccess(html.account.email(me, err))
} { data =>
val email = Env.security.emailAddress.validate(data.email) err s"Invalid email ${data.email}"
for {
ok UserRepo.authenticateById(me.id, data.passwd).map(_.isDefined)
_ ok ?? UserRepo.email(me.id, email)
form <- emailForm(me)
} yield {
val content = html.account.email(me, form, ok.some)
ok.fold(Ok(content), BadRequest(content))
}
def emailApply = AuthBody { implicit ctx => me =>
UserRepo hasEmail me.id flatMap {
case true => notFound
case false =>
implicit val req = ctx.body
FormFuResult(Env.security.forms.changeEmail(me)) { err =>
fuccess(html.account.email(me, err))
} { data =>
val email = Env.security.emailAddress.validate(data.email) err s"Invalid email ${data.email}"
for {
ok UserRepo.authenticateById(me.id, data.passwd).map(_.isDefined)
_ ok ?? UserRepo.email(me.id, email)
form <- emailForm(me)
} yield {
val content = html.account.email(me, form, ok.some)
ok.fold(Ok(content), BadRequest(content))
}
}
}
}
}

def close = Auth { implicit ctx =>
me =>
Ok(html.account.close(me, Env.security.forms.closeAccount)).fuccess
def close = Auth { implicit ctx => me =>
Ok(html.account.close(me, Env.security.forms.closeAccount)).fuccess
}

def closeConfirm = AuthBody { implicit ctx =>
me =>
implicit val req = ctx.body
FormFuResult(Env.security.forms.closeAccount) { err =>
fuccess(html.account.close(me, err))
} { password =>
UserRepo.authenticateById(me.id, password).map(_.isDefined) flatMap {
case false => BadRequest(html.account.close(me, Env.security.forms.closeAccount)).fuccess
case true => doClose(me) inject {
Redirect(routes.User show me.username) withCookies LilaCookie.newSession
}
def closeConfirm = AuthBody { implicit ctx => me =>
implicit val req = ctx.body
FormFuResult(Env.security.forms.closeAccount) { err =>
fuccess(html.account.close(me, err))
} { password =>
UserRepo.authenticateById(me.id, password).map(_.isDefined) flatMap {
case false => BadRequest(html.account.close(me, Env.security.forms.closeAccount)).fuccess
case true => doClose(me) inject {
Redirect(routes.User show me.username) withCookies LilaCookie.newSession
}
}
}
}

private[controllers] def doClose(user: UserModel) =
Expand All @@ -146,33 +139,29 @@ object Account extends LilaController {
Env.tournament.api.withdrawAll(user) >>
(Env.security disconnect user.id)

def kid = Auth { implicit ctx =>
me =>
Ok(html.account.kid(me)).fuccess
def kid = Auth { implicit ctx => me =>
Ok(html.account.kid(me)).fuccess
}

def kidConfirm = Auth { ctx =>
me =>
(UserRepo toggleKid me) inject Redirect(routes.Account.kid)
def kidConfirm = Auth { ctx => me =>
(UserRepo toggleKid me) inject Redirect(routes.Account.kid)
}

private def currentSessionId(implicit ctx: Context) =
~Env.security.api.reqSessionId(ctx.req)

def security = Auth { implicit ctx =>
me =>
Env.security.api.dedup(me.id, ctx.req) >>
Env.security.api.locatedOpenSessions(me.id, 50) map { sessions =>
Ok(html.account.security(me, sessions, currentSessionId))
}
def security = Auth { implicit ctx => me =>
Env.security.api.dedup(me.id, ctx.req) >>
Env.security.api.locatedOpenSessions(me.id, 50) map { sessions =>
Ok(html.account.security(me, sessions, currentSessionId))
}
}

def signout(sessionId: String) = Auth { implicit ctx =>
me =>
if (sessionId == "all")
lila.security.Store.closeUserExceptSessionId(me.id, currentSessionId) inject
Redirect(routes.Account.security)
else
lila.security.Store.closeUserAndSessionId(me.id, sessionId)
def signout(sessionId: String) = Auth { implicit ctx => me =>
if (sessionId == "all")
lila.security.Store.closeUserExceptSessionId(me.id, currentSessionId) inject
Redirect(routes.Account.security)
else
lila.security.Store.closeUserAndSessionId(me.id, sessionId)
}
}
14 changes: 9 additions & 5 deletions app/controllers/Analyse.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ object Analyse extends LilaController {
userId = me.id.some,
ip = HTTPRequest.lastRemoteAddress(ctx.req).some,
mod = isGranted(_.Hunter),
system = false)) map {
case true => Ok
system = false
)) map {
case true => Ok
case false => Unauthorized
}
}
Expand Down Expand Up @@ -55,7 +56,8 @@ object Analyse extends LilaController {
crosstable,
userTv,
chat,
bookmarked = bookmarked))
bookmarked = bookmarked
))
}
}
}
Expand Down Expand Up @@ -85,7 +87,8 @@ object Analyse extends LilaController {
lila.log("analyse").info(s"RedirectAtFen: ${pov.gameId} $atFen $err")
Redirect(url)
},
ply => Redirect(s"$url#$ply"))
ply => Redirect(s"$url#$ply")
)
}
}

Expand All @@ -101,5 +104,6 @@ object Analyse extends LilaController {
Env.analyse.annotator(pgn, analysis, pov.game.opening, pov.game.winnerColor, pov.game.status, pov.game.clock).toString,
analysis,
simul,
crosstable))
crosstable
))
}
Loading

0 comments on commit 54cdf0c

Please sign in to comment.