diff --git a/src/main/scala/app/AccountController.scala b/src/main/scala/app/AccountController.scala index 3c98f8d..61594f7 100644 --- a/src/main/scala/app/AccountController.scala +++ b/src/main/scala/app/AccountController.scala @@ -5,14 +5,23 @@ 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 @@ 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 + } } diff --git a/src/main/scala/app/SignInController.scala b/src/main/scala/app/SignInController.scala index ab626cb..babc1fd 100644 --- a/src/main/scala/app/SignInController.scala +++ b/src/main/scala/app/SignInController.scala @@ -3,9 +3,9 @@ import service._ import jp.sf.amateras.scalatra.forms._ -class SignInController extends SignInControllerBase with AccountService +class SignInController extends SignInControllerBase with SystemSettingsService with AccountService -trait SignInControllerBase extends ControllerBase { self: AccountService => +trait SignInControllerBase extends ControllerBase { self: SystemSettingsService with AccountService => case class SignInForm(userName: String, password: String) @@ -15,7 +15,7 @@ )(SignInForm.apply) get("/signin"){ - html.signin() + html.signin(loadSystemSettings()) } post("/signin", form){ form => diff --git a/src/main/twirl/account/useredit.scala.html b/src/main/twirl/account/useredit.scala.html index 69459e3..0a30dab 100644 --- a/src/main/twirl/account/useredit.scala.html +++ b/src/main/twirl/account/useredit.scala.html @@ -1,21 +1,37 @@ -@(account: model.Account)(implicit context: app.Context) +@(account: Option[model.Account])(implicit context: app.Context) @import context._ @import view.helpers._ -@html.main(account.userName){ -
} diff --git a/src/main/twirl/signin.scala.html b/src/main/twirl/signin.scala.html index d673224..0d0a659 100644 --- a/src/main/twirl/signin.scala.html +++ b/src/main/twirl/signin.scala.html @@ -1,4 +1,4 @@ -@()(implicit context: app.Context) +@(systemSettings: service.SystemSettingsService.SystemSettings)(implicit context: app.Context) @import context._ @main("Sign in"){ }