mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-07 05:55:51 +01:00
Add AccountService#updateAccount()
This commit is contained in:
@@ -55,7 +55,14 @@ trait UsersControllerBase extends ControllerBase { self: AccountService =>
|
|||||||
}
|
}
|
||||||
|
|
||||||
post("/admin/users/:name/_edit", editForm){ form =>
|
post("/admin/users/:name/_edit", editForm){ form =>
|
||||||
// TODO Update Account
|
val userName = params("userName")
|
||||||
|
val currentDate = new java.sql.Date(System.currentTimeMillis)
|
||||||
|
updateAccount(getAccountByUserName(userName).get.copy(
|
||||||
|
password = form.password,
|
||||||
|
mailAddress = form.mailAddress,
|
||||||
|
userType = form.userType,
|
||||||
|
url = form.url,
|
||||||
|
updatedDate = currentDate))
|
||||||
|
|
||||||
redirect("/admin/users")
|
redirect("/admin/users")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,14 +6,28 @@ import Database.threadLocalSession
|
|||||||
|
|
||||||
trait AccountService {
|
trait AccountService {
|
||||||
|
|
||||||
def getAccountByUserName(userName: String): Option[Account] =
|
def getAccountByUserName(userName: String): Option[Account] =
|
||||||
Query(Accounts) filter(_.userName is userName.bind) firstOption
|
Query(Accounts) filter(_.userName is userName.bind) firstOption
|
||||||
|
|
||||||
def getAllUsers(): List[Account] =
|
def getAllUsers(): List[Account] = Query(Accounts) sortBy(_.userName) list
|
||||||
Query(Accounts) sortBy(_.userName) list
|
|
||||||
|
|
||||||
def createAccount(account: Account): Unit = Accounts.* insert account
|
def createAccount(account: Account): Unit = Accounts.* insert account
|
||||||
|
|
||||||
|
def updateAccount(account: Account): Unit = {
|
||||||
|
val q = for {
|
||||||
|
a <- Accounts if a.userName is account.userName.bind
|
||||||
|
} yield a.password ~ a.mailAddress ~ a.userType ~ a.url.? ~ a.registeredDate ~ a.updatedDate ~ a.lastLoginDate.?
|
||||||
|
|
||||||
|
q.update(
|
||||||
|
account.password,
|
||||||
|
account.mailAddress,
|
||||||
|
account.userType,
|
||||||
|
account.url,
|
||||||
|
account.registeredDate,
|
||||||
|
account.updatedDate,
|
||||||
|
account.lastLoginDate)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
object AccountService {
|
object AccountService {
|
||||||
|
|||||||
Reference in New Issue
Block a user