Add the password field to the account editing page.

This commit is contained in:
takezoe
2013-06-29 02:23:32 +09:00
parent f170aa0a04
commit 7da39b4785
2 changed files with 17 additions and 11 deletions

View File

@@ -12,7 +12,7 @@ trait AccountControllerBase extends ControllerBase {
case class AccountNewForm(userName: String, password: String,mailAddress: String, url: Option[String])
case class AccountEditForm(mailAddress: String, url: Option[String])
case class AccountEditForm(password: Option[String], mailAddress: String, url: Option[String])
val newForm = mapping(
"userName" -> trim(label("User name" , text(required, maxlength(100)))),
@@ -22,6 +22,7 @@ trait AccountControllerBase extends ControllerBase {
)(AccountNewForm.apply)
val editForm = mapping(
"password" -> trim(label("Password" , optional(text(maxlength(20))))),
"mailAddress" -> trim(label("Mail Address" , text(required, maxlength(100)))),
"url" -> trim(label("URL" , optional(text(maxlength(200)))))
)(AccountEditForm.apply)
@@ -45,6 +46,7 @@ trait AccountControllerBase extends ControllerBase {
val userName = params("userName")
getAccountByUserName(userName).map { account =>
updateAccount(account.copy(
password = form.password.getOrElse(account.password),
mailAddress = form.mailAddress,
url = form.url))
redirect("/%s".format(userName))

View File

@@ -1,27 +1,31 @@
@(account: Option[model.Account])(implicit context: app.Context)
@import context._
@import view.helpers._
@html.main(account.map(_.userName).getOrElse("Create account")){
<form action="@if(account.isDefined){url(account.get.userName)/_edit}else{/register}" method="POST" validate="true">
@html.main((if(account.isDefined) "Your Profile" else "Create account")){
<form action="@if(account.isDefined){@url(account.get.userName)/_edit}else{/register}" method="POST" validate="true">
@if(account.isEmpty){
<fieldset>
<label><strong>User name</strong></label>
<label for="userName"><strong>User name</strong></label>
<input type="text" name="userName" id="userName" value=""/>
<span id="error-userName" class="error"></span>
</fieldset>
<fieldset>
<label><strong>Password</strong></label>
<input type="password" name="password" id="password" value=""/>
<span id="error-password" class="error"></span>
</fieldset>
}
<fieldset>
<label><strong>Mail Address</strong></label>
<label for="password"><strong>Password</strong>
@if(account.nonEmpty){
(Input if you want to change password)
}
</label>
<input type="password" name="password" id="password" value=""/>
<span id="error-password" class="error"></span>
</fieldset>
<fieldset>
<label for="mailAddress"><strong>Mail Address</strong></label>
<input type="text" name="mailAddress" id="mailAddress" value="@account.map(_.mailAddress)"/>
<span id="error-mailAddress" class="error"></span>
</fieldset>
<fieldset>
<label><strong>URL (Optional)</strong></label>
<label for="url"><strong>URL (Optional)</strong></label>
<input type="text" name="url" id="url" style="width: 400px;" value="@account.map(_.url)"/>
<span id="error-url" class="error"></span>
</fieldset>