2013-03-20 08:23:41 -06:00
|
|
|
package controllers
|
|
|
|
|
|
|
|
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 }
|
2013-04-10 04:17:58 -06:00
|
|
|
import play.api.mvc._, Results._
|
2013-06-28 05:52:52 -06:00
|
|
|
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 ⇒
|
|
|
|
isXhr.fold(mini(username), filter(username, "all", 1))
|
|
|
|
}
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
private def filter(username: String, filterName: String, page: Int)(implicit ctx: Context) =
|
2013-05-08 09:41:12 -06:00
|
|
|
Reasonable(page) {
|
2013-05-14 21:59:04 -06:00
|
|
|
OptionFuOk(UserRepo named username) { userShow(_, filterName, page) }
|
2013-05-04 17:12:53 -06:00
|
|
|
}
|
2013-03-20 07:24:47 -06:00
|
|
|
|
2013-05-08 09:41:12 -06:00
|
|
|
private def userShow(u: UserModel, filterName: String, page: Int)(implicit ctx: Context) =
|
2013-05-15 13:28:46 -06:00
|
|
|
(u.enabled || isGranted(_.UserSpy)).fold({
|
2013-05-08 09:41:12 -06:00
|
|
|
for {
|
2013-05-23 12:03:43 -06:00
|
|
|
info ← Env.current.userInfo(u, ctx)
|
2013-05-08 09:41:12 -06:00
|
|
|
filters = mashup.GameFilterMenu(info, ctx.me, filterName)
|
|
|
|
pag ← (filters.query.fold(Env.bookmark.api.gamePaginatorByUser(u, page)) { query ⇒
|
|
|
|
gamePaginator.recentlyCreated(query, filters.cachedNb)(page)
|
|
|
|
})
|
2013-05-23 12:03:43 -06:00
|
|
|
} yield html.user.show(u, info, pag, filters)
|
2013-05-08 09:41:12 -06:00
|
|
|
}, fuccess(html.user.disabled(u)))
|
|
|
|
|
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-23 05:04:15 -06:00
|
|
|
UserRepo.topElo(10) map {
|
|
|
|
case topElo ⇒ html.user.list(topElo)
|
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 ⇒
|
|
|
|
get("term", ctx.req).filter(""!=).fold(BadRequest("No search term provided").fuccess: Fu[Result]) { term ⇒
|
|
|
|
JsonOk(UserRepo usernamesLike term)
|
|
|
|
}
|
|
|
|
}
|
2013-03-20 08:23:41 -06:00
|
|
|
|
2013-05-08 09:41:12 -06:00
|
|
|
def setBio = AuthBody { ctx ⇒
|
|
|
|
me ⇒
|
|
|
|
implicit val req = ctx.body
|
2013-05-25 07:31:27 -06:00
|
|
|
forms.bio.bindFromRequest.fold(
|
2013-05-08 09:41:12 -06:00
|
|
|
f ⇒ fulogwarn(f.errors.toString) inject ~me.bio,
|
|
|
|
bio ⇒ UserRepo.setBio(me.id, bio) inject bio
|
2013-05-25 07:31:27 -06:00
|
|
|
) map { Ok(_) }
|
2013-05-08 09:41:12 -06:00
|
|
|
}
|
2013-03-20 08:23:41 -06:00
|
|
|
|
2013-05-08 09:41:12 -06:00
|
|
|
def passwd = Auth { implicit ctx ⇒
|
|
|
|
me ⇒
|
|
|
|
Ok(html.user.passwd(me, forms.passwd)).fuccess
|
|
|
|
}
|
2013-03-20 08:23:41 -06:00
|
|
|
|
2013-05-08 09:41:12 -06:00
|
|
|
def passwdApply = AuthBody { implicit ctx ⇒
|
|
|
|
me ⇒
|
|
|
|
implicit val req = ctx.body
|
|
|
|
FormFuResult(forms.passwd) { err ⇒
|
2013-05-08 10:15:55 -06:00
|
|
|
fuccess(html.user.passwd(me, err))
|
2013-05-08 09:41:12 -06:00
|
|
|
} { passwd ⇒
|
|
|
|
for {
|
|
|
|
ok ← UserRepo.checkPassword(me.id, passwd.oldPasswd)
|
|
|
|
_ ← ok ?? UserRepo.passwd(me.id, passwd.newPasswd1)
|
|
|
|
} yield ok.fold(
|
|
|
|
Redirect(routes.User show me.username),
|
|
|
|
BadRequest(html.user.passwd(me, forms.passwd))
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2013-03-20 08:23:41 -06:00
|
|
|
|
2013-05-08 09:41:12 -06:00
|
|
|
def close = Auth { implicit ctx ⇒
|
|
|
|
me ⇒
|
|
|
|
Ok(html.user.close(me)).fuccess
|
|
|
|
}
|
2013-03-20 08:23:41 -06:00
|
|
|
|
2013-05-08 09:41:12 -06:00
|
|
|
def closeConfirm = Auth { ctx ⇒
|
|
|
|
me ⇒
|
|
|
|
implicit val req = ctx.req
|
2013-05-15 13:28:46 -06:00
|
|
|
(UserRepo disable me.id) >>
|
|
|
|
Env.team.api.quitAll(me.id) >>
|
2013-05-15 19:53:16 -06:00
|
|
|
(Env.security disconnect me.id) inject {
|
2013-05-15 13:28:46 -06:00
|
|
|
Redirect(routes.User show me.username) withCookies LilaCookie.newSession
|
|
|
|
}
|
2013-05-08 09:41:12 -06:00
|
|
|
}
|
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
|
|
|
}
|