(refs #28)Fix information message.

This commit is contained in:
takezoe
2013-07-10 18:24:46 +09:00
parent 653872df8e
commit 02c015574f
9 changed files with 88 additions and 75 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -6,25 +6,28 @@ import util.StringUtil._
import util.Directory._
import jp.sf.amateras.scalatra.forms._
import org.apache.commons.io.FileUtils
import org.scalatra.FlashMapSupport
class AccountController extends AccountControllerBase
with SystemSettingsService with AccountService with RepositoryService with ActivityService
with OneselfAuthenticator
trait AccountControllerBase extends ControllerBase {
trait AccountControllerBase extends ControllerBase with FlashMapSupport {
self: SystemSettingsService with AccountService with RepositoryService with ActivityService
with OneselfAuthenticator =>
case class AccountNewForm(userName: String, password: String,mailAddress: String, url: Option[String])
case class AccountNewForm(userName: String, password: String,mailAddress: String,
url: Option[String], fileId: Option[String])
case class AccountEditForm(password: Option[String], mailAddress: String, url: Option[String],
fileId: Option[String], clearImage: Boolean)
case class AccountEditForm(password: Option[String], mailAddress: String,
url: Option[String], fileId: Option[String], clearImage: Boolean)
val newForm = mapping(
"userName" -> trim(label("User name" , text(required, maxlength(100), identifier, uniqueUserName))),
"password" -> trim(label("Password" , text(required, maxlength(20)))),
"mailAddress" -> trim(label("Mail Address" , text(required, maxlength(100), uniqueMailAddress()))),
"url" -> trim(label("URL" , optional(text(maxlength(200)))))
"url" -> trim(label("URL" , optional(text(maxlength(200))))),
"fileId" -> trim(label("File ID" , optional(text())))
)(AccountNewForm.apply)
val editForm = mapping(
@@ -63,7 +66,7 @@ trait AccountControllerBase extends ControllerBase {
get("/:userName/_edit")(oneselfOnly {
val userName = params("userName")
getAccountByUserName(userName).map(x => account.html.edit(Some(x))) getOrElse NotFound
getAccountByUserName(userName).map(x => account.html.edit(Some(x), flash.get("info"))) getOrElse NotFound
})
post("/:userName/_edit", editForm)(oneselfOnly { form =>
@@ -80,7 +83,30 @@ trait AccountControllerBase extends ControllerBase {
updateAvatarImage(userName, None)
}
} else {
form.fileId.map { fileId =>
updateImage(userName, form.fileId)
}
flash += "info" -> "Account information has been updated."
redirect("/%s/_edit".format(userName))
} getOrElse NotFound
})
get("/register"){
if(loadSystemSettings().allowAccountRegistration){
account.html.edit(None, None)
} else NotFound
}
post("/register", newForm){ form =>
if(loadSystemSettings().allowAccountRegistration){
createAccount(form.userName, encrypt(form.password), form.mailAddress, false, form.url)
updateImage(form.userName, form.fileId)
redirect("/signin")
} else NotFound
}
private def updateImage(userName: String, fileId: Option[String]): Unit = {
fileId.map { fileId =>
val filename = "avatar." + FileUtil.getExtension(FileUploadUtil.getUploadedFilename(fileId).get)
FileUtils.moveFile(
FileUploadUtil.getTemporaryFile(fileId),
@@ -90,23 +116,6 @@ trait AccountControllerBase extends ControllerBase {
}
}
redirect("/%s".format(userName))
} getOrElse NotFound
})
get("/register"){
if(loadSystemSettings().allowAccountRegistration){
account.html.edit(None)
} else NotFound
}
post("/register", newForm){ newForm =>
if(loadSystemSettings().allowAccountRegistration){
createAccount(newForm.userName, encrypt(newForm.password), newForm.mailAddress, false, newForm.url)
redirect("/signin")
} else NotFound
}
// TODO Merge with UserManagementController
private def uniqueUserName: Constraint = new Constraint(){
def validate(name: String, value: String): Option[String] =

View File

@@ -46,7 +46,7 @@ trait RepositorySettingsControllerBase extends ControllerBase with FlashMapSuppo
*/
post("/:owner/:repository/settings/options", optionsForm)(ownerOnly { (form, repository) =>
saveRepositoryOptions(repository.owner, repository.name, form.description, form.defaultBranch, form.isPrivate)
flash += "info" -> "Settings updated."
flash += "info" -> "Repository settings has been updated."
redirect("/%s/%s/settings/options".format(repository.owner, repository.name))
})

View File

@@ -25,7 +25,7 @@ trait SystemSettingsControllerBase extends ControllerBase with FlashMapSupport {
post("/admin/system", form)(adminOnly { form =>
saveSystemSettings(SystemSettings(form.allowAccountRegistration))
flash += "info" -> "Settings updated."
flash += "info" -> "System settings has been updated."
redirect("/admin/system")
})

View File

@@ -16,8 +16,8 @@ object FileUploadUtil {
def getTemporaryFile(fileId: String)(implicit session: HttpSession): java.io.File =
new java.io.File(TemporaryDir, fileId)
def removeTemporaryFile(fileId: String)(implicit session: HttpSession): Unit =
getTemporaryFile(fileId).delete()
// def removeTemporaryFile(fileId: String)(implicit session: HttpSession): Unit =
// getTemporaryFile(fileId).delete()
def removeTemporaryFiles()(implicit session: HttpSession): Unit =
FileUtils.deleteDirectory(TemporaryDir)

View File

@@ -1,4 +1,4 @@
@(account: Option[model.Account])(implicit context: app.Context)
@(account: Option[model.Account], info: Option[Any])(implicit context: app.Context)
@import context._
@import view.helpers._
@html.main((if(account.isDefined) "Edit your profile" else "Create your account")){
@@ -7,7 +7,10 @@
} else {
<h3>Create your account</h3>
}
@helper.html.information(info)
<form action="@if(account.isDefined){@url(account.get.userName)/_edit}else{@path/register}" method="POST" validate="true">
<div class="row-fluid">
<div class="span6">
@if(account.isEmpty){
<fieldset>
<label for="userName"><strong>User name</strong></label>
@@ -34,6 +37,8 @@
<input type="text" name="url" id="url" style="width: 400px;" value="@account.map(_.url)"/>
<span id="error-url" class="error"></span>
</fieldset>
</div>
<div class="span6">
<fieldset>
<label for="avatar"><strong>Image (Optional)</strong></label>
<div id="avatar" class="muted">
@@ -50,6 +55,8 @@
}
<input type="hidden" name="fileId" value=""/>
</fieldset>
</div>
</div>
<fieldset class="margin">
@if(account.isDefined){
<input type="submit" class="btn btn-success" value="Save"/>

View File

@@ -3,12 +3,7 @@
@import view.helpers._
@html.main("System Settings"){
@menu("system"){
@if(info.isDefined){
<div class="alert alert-info">
<button type="button" class="close" data-dismiss="alert">×</button>
@info
</div>
}
@helper.html.information(info)
<form action="@path/admin/system" method="POST" validate="true">
<div class="box">
<div class="box-header">System Settings</div>

View File

@@ -0,0 +1,7 @@
@(info: Option[Any])
@if(info.isDefined){
<div class="alert alert-info">
<button type="button" class="close" data-dismiss="alert">×</button>
@info
</div>
}

View File

@@ -4,12 +4,7 @@
@html.main("Settings"){
@html.header("settings", repository)
@menu("options", repository){
@if(info.isDefined){
<div class="alert alert-info">
<button type="button" class="close" data-dismiss="alert">×</button>
@info
</div>
}
@helper.html.information(info)
<form id="form" method="post" action="@url(repository)/settings/options" validate="true">
<div class="box">
<div class="box-header">Settings</div>