diff --git a/src/main/scala/ScalatraBootstrap.scala b/src/main/scala/ScalatraBootstrap.scala index b8b523c..ea98d6f 100644 --- a/src/main/scala/ScalatraBootstrap.scala +++ b/src/main/scala/ScalatraBootstrap.scala @@ -4,8 +4,9 @@ class ScalatraBootstrap extends LifeCycle { override def init(context: ServletContext) { - context.mount(new CreateRepositoryController, "/new") + context.mount(new IndexController, "/") context.mount(new WikiController, "/*") + context.mount(new CreateRepositoryController, "/*") context.mount(new RepositoryViewerController, "/*") context.addListener(new ServletContextListener(){ diff --git a/src/main/scala/app/ControllerBase.scala b/src/main/scala/app/ControllerBase.scala index 61f4383..48a41d0 100644 --- a/src/main/scala/app/ControllerBase.scala +++ b/src/main/scala/app/ControllerBase.scala @@ -13,11 +13,11 @@ implicit val jsonFormats = DefaultFormats - implicit def context: Context = Context(servletContext.getContextPath) + implicit def context: Context = Context(servletContext.getContextPath, LoginUser) // TODO get from session - val LoginUser = System.getProperty("user.name") + private val LoginUser = System.getProperty("user.name") } -case class Context(path: String) \ No newline at end of file +case class Context(path: String, loginUser: String) \ No newline at end of file diff --git a/src/main/scala/app/CreateRepositoryController.scala b/src/main/scala/app/CreateRepositoryController.scala index 43cecfa..36256eb 100644 --- a/src/main/scala/app/CreateRepositoryController.scala +++ b/src/main/scala/app/CreateRepositoryController.scala @@ -23,15 +23,15 @@ /** * Show the new repository form. */ - get("/") { + get("/new") { html.newrepo() } /** * Create new repository. */ - post("/", form) { form => - val gitdir = getRepositoryDir(LoginUser, form.name) + post("/new", form) { form => + val gitdir = getRepositoryDir(context.loginUser, form.name) val repository = new RepositoryBuilder().setGitDir(gitdir).setBare.build repository.create @@ -40,7 +40,7 @@ config.setBoolean("http", null, "receivepack", true) config.save - val tmpdir = getInitRepositoryDir(LoginUser, form.name) + val tmpdir = getInitRepositoryDir(context.loginUser, form.name) try { // Clone the repository Git.cloneRepository.setURI(gitdir.toURI.toString).setDirectory(tmpdir).call @@ -62,7 +62,7 @@ } // redirect to the repository - redirect("/%s/%s".format(LoginUser, form.name)) + redirect("/%s/%s".format(context.loginUser, form.name)) } /** @@ -72,7 +72,7 @@ def validate(name: String, value: String): Option[String] = { if(!value.matches("^[a-z0-9\\-_]+$")){ Some("Repository name contains invalid character.") - } else if(getRepositories(LoginUser).contains(value)){ + } else if(getRepositories(context.loginUser).contains(value)){ Some("Repository already exists.") } else { None diff --git a/src/main/scala/app/IndexController.scala b/src/main/scala/app/IndexController.scala new file mode 100644 index 0000000..1fffffa --- /dev/null +++ b/src/main/scala/app/IndexController.scala @@ -0,0 +1,9 @@ +package app + +class IndexController extends ControllerBase { + + get("/"){ + html.index() + } + +} \ No newline at end of file diff --git a/src/main/scala/app/WikiController.scala b/src/main/scala/app/WikiController.scala index ecb9718..6e931c3 100644 --- a/src/main/scala/app/WikiController.scala +++ b/src/main/scala/app/WikiController.scala @@ -63,7 +63,7 @@ val repository = params("repository") WikiUtil.savePage(owner, repository, form.currentPageName, form.pageName, - form.content, LoginUser, form.message.getOrElse("")) + form.content, context.loginUser, form.message.getOrElse("")) redirect("%s/%s/wiki/%s".format(owner, repository, form.pageName)) } diff --git a/src/main/twirl/index.scala.html b/src/main/twirl/index.scala.html new file mode 100644 index 0000000..d6f9b38 --- /dev/null +++ b/src/main/twirl/index.scala.html @@ -0,0 +1,9 @@ +@()(implicit context: app.Context) +@import context._ +@main("GitBucket"){ +