mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-06 21:45:50 +01:00
(refs #28)Fix information message.
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
@@ -6,25 +6,28 @@ import util.StringUtil._
|
|||||||
import util.Directory._
|
import util.Directory._
|
||||||
import jp.sf.amateras.scalatra.forms._
|
import jp.sf.amateras.scalatra.forms._
|
||||||
import org.apache.commons.io.FileUtils
|
import org.apache.commons.io.FileUtils
|
||||||
|
import org.scalatra.FlashMapSupport
|
||||||
|
|
||||||
class AccountController extends AccountControllerBase
|
class AccountController extends AccountControllerBase
|
||||||
with SystemSettingsService with AccountService with RepositoryService with ActivityService
|
with SystemSettingsService with AccountService with RepositoryService with ActivityService
|
||||||
with OneselfAuthenticator
|
with OneselfAuthenticator
|
||||||
|
|
||||||
trait AccountControllerBase extends ControllerBase {
|
trait AccountControllerBase extends ControllerBase with FlashMapSupport {
|
||||||
self: SystemSettingsService with AccountService with RepositoryService with ActivityService
|
self: SystemSettingsService with AccountService with RepositoryService with ActivityService
|
||||||
with OneselfAuthenticator =>
|
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],
|
case class AccountEditForm(password: Option[String], mailAddress: String,
|
||||||
fileId: Option[String], clearImage: Boolean)
|
url: Option[String], fileId: Option[String], clearImage: Boolean)
|
||||||
|
|
||||||
val newForm = mapping(
|
val newForm = mapping(
|
||||||
"userName" -> trim(label("User name" , text(required, maxlength(100), identifier, uniqueUserName))),
|
"userName" -> trim(label("User name" , text(required, maxlength(100), identifier, uniqueUserName))),
|
||||||
"password" -> trim(label("Password" , text(required, maxlength(20)))),
|
"password" -> trim(label("Password" , text(required, maxlength(20)))),
|
||||||
"mailAddress" -> trim(label("Mail Address" , text(required, maxlength(100), uniqueMailAddress()))),
|
"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)
|
)(AccountNewForm.apply)
|
||||||
|
|
||||||
val editForm = mapping(
|
val editForm = mapping(
|
||||||
@@ -63,7 +66,7 @@ trait AccountControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
get("/:userName/_edit")(oneselfOnly {
|
get("/:userName/_edit")(oneselfOnly {
|
||||||
val userName = params("userName")
|
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 =>
|
post("/:userName/_edit", editForm)(oneselfOnly { form =>
|
||||||
@@ -80,7 +83,30 @@ trait AccountControllerBase extends ControllerBase {
|
|||||||
updateAvatarImage(userName, None)
|
updateAvatarImage(userName, None)
|
||||||
}
|
}
|
||||||
} else {
|
} 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)
|
val filename = "avatar." + FileUtil.getExtension(FileUploadUtil.getUploadedFilename(fileId).get)
|
||||||
FileUtils.moveFile(
|
FileUtils.moveFile(
|
||||||
FileUploadUtil.getTemporaryFile(fileId),
|
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
|
// TODO Merge with UserManagementController
|
||||||
private def uniqueUserName: Constraint = new Constraint(){
|
private def uniqueUserName: Constraint = new Constraint(){
|
||||||
def validate(name: String, value: String): Option[String] =
|
def validate(name: String, value: String): Option[String] =
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ trait RepositorySettingsControllerBase extends ControllerBase with FlashMapSuppo
|
|||||||
*/
|
*/
|
||||||
post("/:owner/:repository/settings/options", optionsForm)(ownerOnly { (form, repository) =>
|
post("/:owner/:repository/settings/options", optionsForm)(ownerOnly { (form, repository) =>
|
||||||
saveRepositoryOptions(repository.owner, repository.name, form.description, form.defaultBranch, form.isPrivate)
|
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))
|
redirect("/%s/%s/settings/options".format(repository.owner, repository.name))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ trait SystemSettingsControllerBase extends ControllerBase with FlashMapSupport {
|
|||||||
|
|
||||||
post("/admin/system", form)(adminOnly { form =>
|
post("/admin/system", form)(adminOnly { form =>
|
||||||
saveSystemSettings(SystemSettings(form.allowAccountRegistration))
|
saveSystemSettings(SystemSettings(form.allowAccountRegistration))
|
||||||
flash += "info" -> "Settings updated."
|
flash += "info" -> "System settings has been updated."
|
||||||
redirect("/admin/system")
|
redirect("/admin/system")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ object FileUploadUtil {
|
|||||||
def getTemporaryFile(fileId: String)(implicit session: HttpSession): java.io.File =
|
def getTemporaryFile(fileId: String)(implicit session: HttpSession): java.io.File =
|
||||||
new java.io.File(TemporaryDir, fileId)
|
new java.io.File(TemporaryDir, fileId)
|
||||||
|
|
||||||
def removeTemporaryFile(fileId: String)(implicit session: HttpSession): Unit =
|
// def removeTemporaryFile(fileId: String)(implicit session: HttpSession): Unit =
|
||||||
getTemporaryFile(fileId).delete()
|
// getTemporaryFile(fileId).delete()
|
||||||
|
|
||||||
def removeTemporaryFiles()(implicit session: HttpSession): Unit =
|
def removeTemporaryFiles()(implicit session: HttpSession): Unit =
|
||||||
FileUtils.deleteDirectory(TemporaryDir)
|
FileUtils.deleteDirectory(TemporaryDir)
|
||||||
|
|||||||
@@ -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 context._
|
||||||
@import view.helpers._
|
@import view.helpers._
|
||||||
@html.main((if(account.isDefined) "Edit your profile" else "Create your account")){
|
@html.main((if(account.isDefined) "Edit your profile" else "Create your account")){
|
||||||
@@ -7,7 +7,10 @@
|
|||||||
} else {
|
} else {
|
||||||
<h3>Create your account</h3>
|
<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">
|
<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){
|
@if(account.isEmpty){
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<label for="userName"><strong>User name</strong></label>
|
<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)"/>
|
<input type="text" name="url" id="url" style="width: 400px;" value="@account.map(_.url)"/>
|
||||||
<span id="error-url" class="error"></span>
|
<span id="error-url" class="error"></span>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
</div>
|
||||||
|
<div class="span6">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<label for="avatar"><strong>Image (Optional)</strong></label>
|
<label for="avatar"><strong>Image (Optional)</strong></label>
|
||||||
<div id="avatar" class="muted">
|
<div id="avatar" class="muted">
|
||||||
@@ -50,6 +55,8 @@
|
|||||||
}
|
}
|
||||||
<input type="hidden" name="fileId" value=""/>
|
<input type="hidden" name="fileId" value=""/>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<fieldset class="margin">
|
<fieldset class="margin">
|
||||||
@if(account.isDefined){
|
@if(account.isDefined){
|
||||||
<input type="submit" class="btn btn-success" value="Save"/>
|
<input type="submit" class="btn btn-success" value="Save"/>
|
||||||
|
|||||||
@@ -3,12 +3,7 @@
|
|||||||
@import view.helpers._
|
@import view.helpers._
|
||||||
@html.main("System Settings"){
|
@html.main("System Settings"){
|
||||||
@menu("system"){
|
@menu("system"){
|
||||||
@if(info.isDefined){
|
@helper.html.information(info)
|
||||||
<div class="alert alert-info">
|
|
||||||
<button type="button" class="close" data-dismiss="alert">×</button>
|
|
||||||
@info
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
<form action="@path/admin/system" method="POST" validate="true">
|
<form action="@path/admin/system" method="POST" validate="true">
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<div class="box-header">System Settings</div>
|
<div class="box-header">System Settings</div>
|
||||||
|
|||||||
7
src/main/twirl/helper/information.scala.html
Normal file
7
src/main/twirl/helper/information.scala.html
Normal 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>
|
||||||
|
}
|
||||||
@@ -4,12 +4,7 @@
|
|||||||
@html.main("Settings"){
|
@html.main("Settings"){
|
||||||
@html.header("settings", repository)
|
@html.header("settings", repository)
|
||||||
@menu("options", repository){
|
@menu("options", repository){
|
||||||
@if(info.isDefined){
|
@helper.html.information(info)
|
||||||
<div class="alert alert-info">
|
|
||||||
<button type="button" class="close" data-dismiss="alert">×</button>
|
|
||||||
@info
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
<form id="form" method="post" action="@url(repository)/settings/options" validate="true">
|
<form id="form" method="post" action="@url(repository)/settings/options" validate="true">
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<div class="box-header">Settings</div>
|
<div class="box-header">Settings</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user