lila/app/controllers/User.scala

129 lines
4.0 KiB
Scala
Raw Normal View History

2013-03-20 08:23:41 -06:00
package controllers
import lila.app._
import views._
import lila.security.Permission
2013-05-04 17:12:53 -06:00
import lila.user.{ Context, User UserModel, UserRepo }
2013-04-09 12:58:34 -06:00
import lila.common.LilaCookie
2013-03-20 08:23:41 -06:00
2013-04-10 04:17:58 -06:00
import play.api.mvc._, Results._
2013-03-20 08:23:41 -06:00
object User extends LilaController {
2013-04-10 04:17:58 -06:00
private def paginator = Env.user.paginator
2013-03-20 08:23:41 -06:00
// private def gamePaginator = env.game.paginator
private def forms = lila.user.DataForm
2013-04-10 04:17:58 -06:00
private def eloUpdater = Env.user.eloUpdater
2013-03-20 08:23:41 -06:00
// private def bookmarkApi = env.bookmark.api
// private def modApi = env.mod.api
2013-05-04 17:12:53 -06:00
def show(username: String) = Open { implicit ctx =>
UserRepo named username map { userOption =>
println(userOption)
NotFound
}
}
//showFilter(username, "all", 1)
2013-03-20 07:24:47 -06:00
// def showFilter(username: String, filterName: String, page: Int) = Open { implicit ctx ⇒
// Async {
// Akka.future {
// (page < 50).fold(
// IOptionIOk(userRepo byId username) { userShow(_, filterName, page) },
// BadRequest("too old")
// )
// }
// }
// }
// private def userShow(u: UserModel, filterName: String, page: Int)(implicit ctx: Context) =
// (u.enabled || isGranted(_.MarkEngine)).fold({
// val userSpy = isGranted(_.UserSpy) option securityStore.userSpy _
2013-04-10 04:17:58 -06:00
// Env.userInfo(u, bookmarkApi, userSpy, ctx) map { info ⇒
2013-03-20 07:24:47 -06:00
// val filters = GameFilterMenu(info, ctx.me, filterName)
// val paginator = filters.query.fold(bookmarkApi.gamePaginatorByUser(u, page)) { query ⇒
// gamePaginator.recentlyCreated(query, filters.cachedNb)(page)
// }
// html.user.show(u, info, paginator, filters)
// }
// }, io(html.user.disabled(u)))
2013-03-20 08:23:41 -06:00
2013-05-04 17:12:53 -06:00
def list(page: Int) = TODO
2013-03-20 08:23:41 -06:00
// def list(page: Int) = Open { implicit ctx ⇒
// (page < 50).fold(
// IOk(onlineUsers map { html.user.list(paginator elo page, _) }),
// BadRequest("too old")
// )
// }
// val online = Open { implicit ctx ⇒
// IOk(onlineUsers map { html.user.online(_) })
// }
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
// val getBio = Auth { ctx ⇒ me ⇒ Ok(me.bio) }
// val setBio = AuthBody { ctx ⇒
// me ⇒
// implicit val req = ctx.body
// JsonIOk(forms.bio.bindFromRequest.fold(
// f ⇒ putStrLn(f.errors.toString) map { _ ⇒ me.bio | "" },
// bio ⇒ userRepo.setBio(me, bio) map { _ ⇒ bio }
// ) map { bio ⇒ Map("bio" -> bio) })
// }
// val passwd = Auth { implicit ctx ⇒
// me ⇒
// Ok(html.user.passwd(me, forms.passwd))
// }
// val passwdApply = AuthBody { implicit ctx ⇒
// me ⇒
// implicit val req = ctx.body
// FormIOResult(forms.passwd) { err ⇒
// html.user.passwd(me, err)
// } { passwd ⇒
// for {
// ok ← userRepo.checkPassword(me.username, passwd.oldPasswd)
// _ ← userRepo.passwd(me, passwd.newPasswd1) map (_ ⇒ ()) doIf ok
// } yield ok.fold(
// Redirect(routes.User show me.username),
// BadRequest(html.user.passwd(me, forms.passwd))
// )
// }
// }
// val close = Auth { implicit ctx ⇒
// me ⇒
// Ok(html.user.close(me))
// }
// val closeConfirm = Auth { ctx ⇒
// me ⇒
// implicit val req = ctx.req
// IOResult {
// (userRepo disable me) >>
// env.team.api.quitAll(me.id) >>
2013-04-10 04:17:58 -06:00
// (Env.security.store deleteUsername me.username) inject {
2013-03-20 08:23:41 -06:00
// Redirect(routes.User show me.username) withCookies LilaCookie.newSession
// }
// }
// }
// def export(username: String) = Open { implicit ctx ⇒
// IOptionIOResult(userRepo byId username) { u ⇒
// env.game.export(u).apply map { path ⇒
// Redirect(path)
// }
// }
// }
// private val onlineUsers: IO[List[UserModel]] =
2013-04-10 04:17:58 -06:00
// userRepo byIds Env.user.usernameMemo.keys
2013-03-20 08:23:41 -06:00
}