mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-06 05:25:50 +01:00
Generalize some methods in AccountController and UserManagementController.
This commit is contained in:
@@ -77,17 +77,10 @@ trait AccountControllerBase extends AccountManagementControllerBase with FlashMa
|
|||||||
mailAddress = form.mailAddress,
|
mailAddress = form.mailAddress,
|
||||||
url = form.url))
|
url = form.url))
|
||||||
|
|
||||||
if(form.clearImage){
|
updateImage(userName, form.fileId, form.clearImage)
|
||||||
account.image.map { image =>
|
|
||||||
new java.io.File(getUserUploadDir(userName), image).delete()
|
|
||||||
updateAvatarImage(userName, None)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
updateImage(userName, form.fileId)
|
|
||||||
}
|
|
||||||
|
|
||||||
flash += "info" -> "Account information has been updated."
|
flash += "info" -> "Account information has been updated."
|
||||||
redirect("/%s/_edit".format(userName))
|
redirect("/%s/_edit".format(userName))
|
||||||
|
|
||||||
} getOrElse NotFound
|
} getOrElse NotFound
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -100,7 +93,7 @@ trait AccountControllerBase extends AccountManagementControllerBase with FlashMa
|
|||||||
post("/register", newForm){ form =>
|
post("/register", newForm){ form =>
|
||||||
if(loadSystemSettings().allowAccountRegistration){
|
if(loadSystemSettings().allowAccountRegistration){
|
||||||
createAccount(form.userName, encrypt(form.password), form.mailAddress, false, form.url)
|
createAccount(form.userName, encrypt(form.password), form.mailAddress, false, form.url)
|
||||||
updateImage(form.userName, form.fileId)
|
updateImage(form.userName, form.fileId, false)
|
||||||
redirect("/signin")
|
redirect("/signin")
|
||||||
} else NotFound
|
} else NotFound
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,14 +101,21 @@ case class Context(path: String, loginAccount: Option[Account], currentUrl: Stri
|
|||||||
*/
|
*/
|
||||||
trait AccountManagementControllerBase extends ControllerBase { self: AccountService =>
|
trait AccountManagementControllerBase extends ControllerBase { self: AccountService =>
|
||||||
|
|
||||||
protected def updateImage(userName: String, fileId: Option[String]): Unit = {
|
protected def updateImage(userName: String, fileId: Option[String], clearImage: Boolean): Unit = {
|
||||||
fileId.map { fileId =>
|
if(clearImage){
|
||||||
val filename = "avatar." + FileUtil.getExtension(FileUploadUtil.getUploadedFilename(fileId).get)
|
getAccountByUserName(userName).flatMap(_.image).map { image =>
|
||||||
FileUtils.moveFile(
|
new java.io.File(getUserUploadDir(userName), image).delete()
|
||||||
FileUploadUtil.getTemporaryFile(fileId),
|
updateAvatarImage(userName, None)
|
||||||
new java.io.File(getUserUploadDir(userName), filename)
|
}
|
||||||
)
|
} else {
|
||||||
updateAvatarImage(userName, Some(filename))
|
fileId.map { fileId =>
|
||||||
|
val filename = "avatar." + FileUtil.getExtension(FileUploadUtil.getUploadedFilename(fileId).get)
|
||||||
|
FileUtils.moveFile(
|
||||||
|
FileUploadUtil.getTemporaryFile(fileId),
|
||||||
|
new java.io.File(getUserUploadDir(userName), filename)
|
||||||
|
)
|
||||||
|
updateAvatarImage(userName, Some(filename))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ trait UserManagementControllerBase extends AccountManagementControllerBase {
|
|||||||
|
|
||||||
post("/admin/users/_new", newForm)(adminOnly { form =>
|
post("/admin/users/_new", newForm)(adminOnly { form =>
|
||||||
createAccount(form.userName, encrypt(form.password), form.mailAddress, form.isAdmin, form.url)
|
createAccount(form.userName, encrypt(form.password), form.mailAddress, form.isAdmin, form.url)
|
||||||
updateImage(form.userName, form.fileId)
|
updateImage(form.userName, form.fileId, false)
|
||||||
redirect("/admin/users")
|
redirect("/admin/users")
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -66,16 +66,9 @@ trait UserManagementControllerBase extends AccountManagementControllerBase {
|
|||||||
isAdmin = form.isAdmin,
|
isAdmin = form.isAdmin,
|
||||||
url = form.url))
|
url = form.url))
|
||||||
|
|
||||||
if(form.clearImage){
|
updateImage(userName, form.fileId, form.clearImage)
|
||||||
account.image.map { image =>
|
|
||||||
new java.io.File(getUserUploadDir(userName), image).delete()
|
|
||||||
updateAvatarImage(userName, None)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
updateImage(userName, form.fileId)
|
|
||||||
}
|
|
||||||
|
|
||||||
redirect("/admin/users")
|
redirect("/admin/users")
|
||||||
|
|
||||||
} getOrElse NotFound
|
} getOrElse NotFound
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user