2013-03-20 08:23:41 -06:00
|
|
|
package controllers
|
|
|
|
|
2013-09-11 04:38:16 -06:00
|
|
|
import play.api.mvc._, Results._
|
|
|
|
|
2013-03-20 08:23:41 -06:00
|
|
|
import lila.app._
|
2013-06-28 05:52:52 -06:00
|
|
|
import lila.common.LilaCookie
|
|
|
|
import lila.db.api.$find
|
2013-03-20 08:23:41 -06:00
|
|
|
import lila.security.Permission
|
2013-05-08 09:41:12 -06:00
|
|
|
import lila.user.tube.userTube
|
2013-06-28 05:52:52 -06:00
|
|
|
import lila.user.{ Context, User ⇒ UserModel, UserRepo }
|
|
|
|
import views._
|
2013-03-20 08:23:41 -06:00
|
|
|
|
|
|
|
object User extends LilaController {
|
|
|
|
|
2013-05-08 09:41:12 -06:00
|
|
|
private def env = Env.user
|
|
|
|
private def gamePaginator = Env.game.paginator
|
2013-03-20 08:23:41 -06:00
|
|
|
private def forms = lila.user.DataForm
|
2013-05-08 09:41:12 -06:00
|
|
|
|
2013-05-20 22:12:10 -06:00
|
|
|
def show(username: String) = Open { implicit ctx ⇒
|
2013-07-26 16:29:07 -06:00
|
|
|
filter(username, "all", 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
def showMini(username: String) = Open { implicit ctx ⇒
|
|
|
|
mini(username)
|
2013-05-20 22:12:10 -06:00
|
|
|
}
|
2013-05-08 09:41:12 -06:00
|
|
|
|
|
|
|
def showFilter(username: String, filterName: String, page: Int) = Open { implicit ctx ⇒
|
2013-05-20 22:12:10 -06:00
|
|
|
filter(username, filterName, page)
|
|
|
|
}
|
|
|
|
|
2013-07-26 04:50:29 -06:00
|
|
|
def online = Open { implicit req ⇒
|
2013-07-27 01:36:57 -06:00
|
|
|
UserRepo.byIdsSortElo(env.onlineUserIdMemo.keys, 1000) map { users ⇒
|
2013-07-26 04:50:29 -06:00
|
|
|
html.user.online(users)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-20 22:12:10 -06:00
|
|
|
private def filter(username: String, filterName: String, page: Int)(implicit ctx: Context) =
|
2013-05-08 09:41:12 -06:00
|
|
|
Reasonable(page) {
|
2013-10-20 02:03:23 -06:00
|
|
|
OptionFuResult(UserRepo named username) { u ⇒
|
|
|
|
(u.enabled || isGranted(_.UserSpy)).fold({
|
|
|
|
userShow(u, filterName, page) map { Ok(_) }
|
|
|
|
}, fuccess(NotFound(html.user.disabled(u))))
|
|
|
|
}
|
2013-05-04 17:12:53 -06:00
|
|
|
}
|
2013-03-20 07:24:47 -06:00
|
|
|
|
2013-10-20 02:03:23 -06:00
|
|
|
private def userShow(u: UserModel, filterName: String, page: Int)(implicit ctx: Context) = for {
|
|
|
|
info ← Env.current.userInfo(u, ctx)
|
|
|
|
filters = mashup.GameFilterMenu(info, ctx.me, filterName)
|
|
|
|
pag ← (filters.query.fold(Env.bookmark.api.gamePaginatorByUser(u, page)) { query ⇒
|
|
|
|
gamePaginator.recentlyCreated(query, filters.cachedNb)(page)
|
|
|
|
})
|
|
|
|
} yield html.user.show(u, info, pag, filters)
|
2013-05-08 09:41:12 -06:00
|
|
|
|
2013-05-20 22:12:10 -06:00
|
|
|
private def mini(username: String)(implicit ctx: Context) =
|
|
|
|
OptionOk(UserRepo named username) { user ⇒
|
2013-05-22 06:49:09 -06:00
|
|
|
Thread sleep 200
|
2013-05-20 22:12:10 -06:00
|
|
|
html.user.mini(user)
|
|
|
|
}
|
|
|
|
|
2013-05-08 09:41:12 -06:00
|
|
|
def list(page: Int) = Open { implicit ctx ⇒
|
|
|
|
Reasonable(page) {
|
2013-07-24 16:59:45 -06:00
|
|
|
val nb = 15
|
2013-12-13 15:49:17 -07:00
|
|
|
env.cached.topElo(nb) zip
|
|
|
|
env.cached.topOnline(nb) zip
|
|
|
|
env.cached.topBullet(nb) zip
|
|
|
|
env.cached.topBlitz(nb) zip
|
|
|
|
env.cached.topSlow(nb) zip
|
|
|
|
env.cached.topNbGame(nb) map {
|
2013-07-24 16:59:45 -06:00
|
|
|
case (((((elo, online), bullet), blitz), slow), nb) ⇒ html.user.list(
|
2013-07-26 04:50:29 -06:00
|
|
|
elo = elo,
|
2013-07-24 16:59:45 -06:00
|
|
|
online = online,
|
|
|
|
bullet = bullet,
|
|
|
|
blitz = blitz,
|
|
|
|
slow = slow,
|
|
|
|
nb = nb)
|
|
|
|
}
|
2013-05-08 09:41:12 -06:00
|
|
|
}
|
|
|
|
}
|
2013-03-20 08:23:41 -06:00
|
|
|
|
2013-05-15 13:28:46 -06:00
|
|
|
def mod(username: String) = Secure(_.UserSpy) { implicit ctx ⇒
|
|
|
|
me ⇒ OptionFuOk(UserRepo named username) { user ⇒
|
|
|
|
Env.security userSpy user.id map { spy ⇒
|
|
|
|
html.user.mod(user, spy)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-19 18:01:20 -06:00
|
|
|
def opponents(username: String) = Open { implicit ctx ⇒
|
|
|
|
OptionFuOk(UserRepo named username) { user ⇒
|
2013-05-23 12:03:43 -06:00
|
|
|
lila.game.BestOpponents(user.id, 50) map { ops ⇒
|
2013-05-19 18:01:20 -06:00
|
|
|
html.user.opponents(user, ops)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-06 15:52:48 -06:00
|
|
|
def autocomplete = Open { implicit ctx ⇒
|
2013-09-19 05:32:12 -06:00
|
|
|
get("term", ctx.req).filter(""!=).fold(BadRequest("No search term provided").fuccess: Fu[SimpleResult]) { term ⇒
|
2013-05-06 15:52:48 -06:00
|
|
|
JsonOk(UserRepo usernamesLike term)
|
|
|
|
}
|
|
|
|
}
|
2013-03-20 08:23:41 -06:00
|
|
|
|
2013-05-10 03:57:18 -06:00
|
|
|
def export(username: String) = Open { implicit ctx ⇒
|
|
|
|
OptionFuResult(UserRepo named username) { u ⇒
|
2013-06-28 05:52:52 -06:00
|
|
|
Env.game export u map { url ⇒
|
|
|
|
Redirect(Env.api.Net.Protocol + Env.api.Net.AssetDomain + url)
|
|
|
|
}
|
2013-05-10 03:57:18 -06:00
|
|
|
}
|
|
|
|
}
|
2013-03-20 08:23:41 -06:00
|
|
|
}
|