mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-06 05:25:50 +01:00
Add the account editing page.
This commit is contained in:
50
src/main/scala/app/AccountController.scala
Normal file
50
src/main/scala/app/AccountController.scala
Normal file
@@ -0,0 +1,50 @@
|
||||
package app
|
||||
|
||||
import service._
|
||||
import util.OwnerOnlyAuthenticator
|
||||
import jp.sf.amateras.scalatra.forms._
|
||||
|
||||
class AccountController extends AccountControllerBase
|
||||
with AccountService with RepositoryService with OwnerOnlyAuthenticator
|
||||
|
||||
trait AccountControllerBase extends ControllerBase {
|
||||
self: AccountService with RepositoryService with OwnerOnlyAuthenticator =>
|
||||
|
||||
case class AccountEditForm(mailAddress: String, url: Option[String])
|
||||
|
||||
val form = mapping(
|
||||
"mailAddress" -> trim(label("Mail Address" , text(required, maxlength(100)))),
|
||||
"url" -> trim(label("URL" , optional(text(maxlength(200)))))
|
||||
)(AccountEditForm.apply)
|
||||
|
||||
/**
|
||||
* Displays user information.
|
||||
*/
|
||||
get("/:userName") {
|
||||
val userName = params("userName")
|
||||
getAccountByUserName(userName) match {
|
||||
case Some(a) => account.html.userinfo(a, getRepositoriesOfUser(userName, servletContext))
|
||||
case None => NotFound()
|
||||
}
|
||||
}
|
||||
|
||||
get("/:userName/_edit")(ownerOnly {
|
||||
val userName = params("userName")
|
||||
getAccountByUserName(userName) match {
|
||||
case Some(a) => account.html.useredit(a)
|
||||
case None => NotFound()
|
||||
}
|
||||
})
|
||||
|
||||
post("/:userName/_edit", form)(ownerOnly { form =>
|
||||
val userName = params("userName")
|
||||
val currentDate = new java.sql.Date(System.currentTimeMillis)
|
||||
updateAccount(getAccountByUserName(userName).get.copy(
|
||||
mailAddress = form.mailAddress,
|
||||
url = form.url,
|
||||
updatedDate = currentDate))
|
||||
|
||||
redirect("/%s".format(userName))
|
||||
})
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user