forked from lichess-org/lila
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Users.scala
38 lines (32 loc) · 1.04 KB
/
Users.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package lila.cli
import lila.user.{ User, UserRepo }
import lila.security.Store
import scalaz.effects._
case class Users(userRepo: UserRepo, securityStore: Store) {
def enable(username: String): IO[Unit] =
perform(username, "Enable", userRepo.enable)
def disable(username: String): IO[Unit] =
perform(username, "Disable", user ⇒
userRepo disable user map { _ ⇒
securityStore deleteUsername username
}
)
def perform(username: String, action: String, op: User ⇒ IO[Unit]) = for {
_ ← putStrLn(action + " " + username)
userOption ← userRepo byId username
_ ← userOption.fold(
u ⇒ op(u) flatMap { _ ⇒ putStrLn("Success") },
putStrLn("Not found")
)
} yield ()
def info(username: String) =
securityStore.userInfo(username).fold(
info ⇒ for {
_ ← putStrLn("USER " + info.user)
_ ← putStrLn("IP " + info.ip)
_ ← putStrLn("UA " + info.ua)
_ ← putStrLn("DATE " + info.date)
} yield (),
putStrLn("Not found")
)
}