Add account creation page for users.

This commit is contained in:
takezoe
2013-06-28 14:13:58 +09:00
parent 00ad0c1745
commit c308e1993a
4 changed files with 62 additions and 18 deletions

View File

@@ -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
}
}