diff --git a/src/main/resources/noimage.png b/src/main/resources/noimage.png index 6427ccd..fe83548 100644 --- a/src/main/resources/noimage.png +++ b/src/main/resources/noimage.png Binary files differ diff --git a/src/main/scala/app/AccountController.scala b/src/main/scala/app/AccountController.scala index fee400f..e8880eb 100644 --- a/src/main/scala/app/AccountController.scala +++ b/src/main/scala/app/AccountController.scala @@ -6,25 +6,28 @@ 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 @@ 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,33 +83,39 @@ updateAvatarImage(userName, None) } } else { - form.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)) - } + updateImage(userName, form.fileId) } - redirect("/%s".format(userName)) + flash += "info" -> "Account information has been updated." + redirect("/%s/_edit".format(userName)) } getOrElse NotFound }) get("/register"){ if(loadSystemSettings().allowAccountRegistration){ - account.html.edit(None) + account.html.edit(None, None) } else NotFound } - post("/register", newForm){ newForm => + post("/register", newForm){ form => if(loadSystemSettings().allowAccountRegistration){ - createAccount(newForm.userName, encrypt(newForm.password), newForm.mailAddress, false, newForm.url) + 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), + new java.io.File(getUserUploadDir(userName), filename) + ) + updateAvatarImage(userName, Some(filename)) + } + } + // TODO Merge with UserManagementController private def uniqueUserName: Constraint = new Constraint(){ def validate(name: String, value: String): Option[String] = diff --git a/src/main/scala/app/RepositorySettingsController.scala b/src/main/scala/app/RepositorySettingsController.scala index 6ee1cfd..a5c79b4 100644 --- a/src/main/scala/app/RepositorySettingsController.scala +++ b/src/main/scala/app/RepositorySettingsController.scala @@ -46,7 +46,7 @@ */ 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)) }) diff --git a/src/main/scala/app/SystemSettingsController.scala b/src/main/scala/app/SystemSettingsController.scala index 195fefe..6416374 100644 --- a/src/main/scala/app/SystemSettingsController.scala +++ b/src/main/scala/app/SystemSettingsController.scala @@ -25,7 +25,7 @@ post("/admin/system", form)(adminOnly { form => saveSystemSettings(SystemSettings(form.allowAccountRegistration)) - flash += "info" -> "Settings updated." + flash += "info" -> "System settings has been updated." redirect("/admin/system") }) diff --git a/src/main/scala/util/FileUploadUtil.scala b/src/main/scala/util/FileUploadUtil.scala index 94e3794..61f2718 100644 --- a/src/main/scala/util/FileUploadUtil.scala +++ b/src/main/scala/util/FileUploadUtil.scala @@ -16,8 +16,8 @@ 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) diff --git a/src/main/twirl/account/edit.scala.html b/src/main/twirl/account/edit.scala.html index ecd24c2..649c848 100644 --- a/src/main/twirl/account/edit.scala.html +++ b/src/main/twirl/account/edit.scala.html @@ -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,49 +7,56 @@ } else {