mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-05 21:15:49 +01:00
Add account creation page for users.
This commit is contained in:
@@ -5,14 +5,23 @@ import util.OwnerOnlyAuthenticator
|
||||
import jp.sf.amateras.scalatra.forms._
|
||||
|
||||
class AccountController extends AccountControllerBase
|
||||
with AccountService with RepositoryService with OwnerOnlyAuthenticator
|
||||
with SystemSettingsService with AccountService with RepositoryService with OwnerOnlyAuthenticator
|
||||
|
||||
trait AccountControllerBase extends ControllerBase {
|
||||
self: AccountService with RepositoryService with OwnerOnlyAuthenticator =>
|
||||
self: SystemSettingsService with AccountService with RepositoryService with OwnerOnlyAuthenticator =>
|
||||
|
||||
case class AccountNewForm(userName: String, password: String,mailAddress: String, url: Option[String])
|
||||
|
||||
case class AccountEditForm(mailAddress: String, url: Option[String])
|
||||
|
||||
val form = mapping(
|
||||
val newForm = mapping(
|
||||
"userName" -> trim(label("User name" , text(required, maxlength(100)))),
|
||||
"password" -> trim(label("Password" , text(required, maxlength(20)))),
|
||||
"mailAddress" -> trim(label("Mail Address" , text(required, maxlength(100)))),
|
||||
"url" -> trim(label("URL" , optional(text(maxlength(200)))))
|
||||
)(AccountNewForm.apply)
|
||||
|
||||
val editForm = mapping(
|
||||
"mailAddress" -> trim(label("Mail Address" , text(required, maxlength(100)))),
|
||||
"url" -> trim(label("URL" , optional(text(maxlength(200)))))
|
||||
)(AccountEditForm.apply)
|
||||
@@ -29,13 +38,29 @@ trait AccountControllerBase extends ControllerBase {
|
||||
|
||||
get("/:userName/_edit")(ownerOnly {
|
||||
val userName = params("userName")
|
||||
getAccountByUserName(userName).map(account.html.useredit(_)) getOrElse NotFound
|
||||
getAccountByUserName(userName).map(x => account.html.useredit(Some(x))) getOrElse NotFound
|
||||
})
|
||||
|
||||
post("/:userName/_edit", form)(ownerOnly { form =>
|
||||
post("/:userName/_edit", editForm)(ownerOnly { form =>
|
||||
val userName = params("userName")
|
||||
updateAccount(getAccountByUserName(userName).get.copy(mailAddress = form.mailAddress, url = form.url))
|
||||
redirect("/%s".format(userName))
|
||||
getAccountByUserName(userName).map { account =>
|
||||
updateAccount(account.copy(
|
||||
mailAddress = form.mailAddress,
|
||||
url = form.url))
|
||||
redirect("/%s".format(userName))
|
||||
} getOrElse NotFound
|
||||
})
|
||||
|
||||
get("/register"){
|
||||
if(loadSystemSettings().allowAccountRegistration){
|
||||
account.html.useredit(None)
|
||||
} else NotFound
|
||||
}
|
||||
|
||||
post("/register", newForm){ newForm =>
|
||||
if(loadSystemSettings().allowAccountRegistration){
|
||||
createAccount(newForm.userName, newForm.password, newForm.mailAddress, false, newForm.url)
|
||||
redirect("/signin")
|
||||
} else NotFound
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user