mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-06 13:35:50 +01:00
(refs #279)Add configuration to specify the base URL. But still one problem has not been resolved.
This commit is contained in:
@@ -9,12 +9,10 @@ import org.scalatra.FlashMapSupport
|
|||||||
import org.apache.commons.io.FileUtils
|
import org.apache.commons.io.FileUtils
|
||||||
|
|
||||||
class AccountController extends AccountControllerBase
|
class AccountController extends AccountControllerBase
|
||||||
with SystemSettingsService with AccountService with RepositoryService with ActivityService
|
with AccountService with RepositoryService with ActivityService with OneselfAuthenticator
|
||||||
with OneselfAuthenticator
|
|
||||||
|
|
||||||
trait AccountControllerBase extends AccountManagementControllerBase with FlashMapSupport {
|
trait AccountControllerBase extends AccountManagementControllerBase with FlashMapSupport {
|
||||||
self: SystemSettingsService with AccountService with RepositoryService with ActivityService
|
self: AccountService with RepositoryService with ActivityService with OneselfAuthenticator =>
|
||||||
with OneselfAuthenticator =>
|
|
||||||
|
|
||||||
case class AccountNewForm(userName: String, password: String, fullName: String, mailAddress: String,
|
case class AccountNewForm(userName: String, password: String, fullName: String, mailAddress: String,
|
||||||
url: Option[String], fileId: Option[String])
|
url: Option[String], fileId: Option[String])
|
||||||
|
|||||||
@@ -10,8 +10,7 @@ import org.json4s._
|
|||||||
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 model.Account
|
import model.Account
|
||||||
import scala.Some
|
import service.{SystemSettingsService, AccountService}
|
||||||
import service.AccountService
|
|
||||||
import javax.servlet.http.{HttpServletResponse, HttpSession, HttpServletRequest}
|
import javax.servlet.http.{HttpServletResponse, HttpSession, HttpServletRequest}
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import javax.servlet.{FilterChain, ServletResponse, ServletRequest}
|
import javax.servlet.{FilterChain, ServletResponse, ServletRequest}
|
||||||
@@ -21,7 +20,7 @@ import org.scalatra.i18n._
|
|||||||
* Provides generic features for controller implementations.
|
* Provides generic features for controller implementations.
|
||||||
*/
|
*/
|
||||||
abstract class ControllerBase extends ScalatraFilter
|
abstract class ControllerBase extends ScalatraFilter
|
||||||
with ClientSideValidationFormSupport with JacksonJsonSupport with I18nSupport with Validations {
|
with ClientSideValidationFormSupport with JacksonJsonSupport with I18nSupport with Validations with SystemSettingsService {
|
||||||
|
|
||||||
implicit val jsonFormats = DefaultFormats
|
implicit val jsonFormats = DefaultFormats
|
||||||
|
|
||||||
@@ -58,8 +57,9 @@ abstract class ControllerBase extends ScalatraFilter
|
|||||||
/**
|
/**
|
||||||
* Returns the context object for the request.
|
* Returns the context object for the request.
|
||||||
*/
|
*/
|
||||||
implicit def context: Context = Context(servletContext.getContextPath, LoginAccount, currentURL, request)
|
implicit def context: Context = Context(servletContext.getContextPath, LoginAccount, request)
|
||||||
|
|
||||||
|
// TODO This method should be remvoved.
|
||||||
private def currentURL: String = defining(request.getQueryString){ queryString =>
|
private def currentURL: String = defining(request.getQueryString){ queryString =>
|
||||||
request.getRequestURI + (if(queryString != null) "?" + queryString else "")
|
request.getRequestURI + (if(queryString != null) "?" + queryString else "")
|
||||||
}
|
}
|
||||||
@@ -107,13 +107,16 @@ abstract class ControllerBase extends ScalatraFilter
|
|||||||
if(request.getMethod.toUpperCase == "POST"){
|
if(request.getMethod.toUpperCase == "POST"){
|
||||||
org.scalatra.Unauthorized(redirect("/signin"))
|
org.scalatra.Unauthorized(redirect("/signin"))
|
||||||
} else {
|
} else {
|
||||||
|
// TODO This URL may not be same as the front URL...
|
||||||
org.scalatra.Unauthorized(redirect("/signin?redirect=" + StringUtil.urlEncode(currentURL)))
|
org.scalatra.Unauthorized(redirect("/signin?redirect=" + StringUtil.urlEncode(currentURL)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected def baseUrl = defining(request.getRequestURL.toString){ url =>
|
protected def baseUrl = loadSystemSettings().baseUrl.getOrElse {
|
||||||
url.substring(0, url.length - (request.getRequestURI.length - request.getContextPath.length))
|
defining(request.getRequestURL.toString){ url =>
|
||||||
|
url.substring(0, url.length - (request.getRequestURI.length - request.getContextPath.length))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -121,13 +124,7 @@ abstract class ControllerBase extends ScalatraFilter
|
|||||||
/**
|
/**
|
||||||
* Context object for the current request.
|
* Context object for the current request.
|
||||||
*/
|
*/
|
||||||
case class Context(path: String, loginAccount: Option[Account], currentUrl: String, request: HttpServletRequest){
|
case class Context(path: String, loginAccount: Option[Account], request: HttpServletRequest){
|
||||||
|
|
||||||
def redirectUrl = if(request.getParameter("redirect") != null){
|
|
||||||
request.getParameter("redirect")
|
|
||||||
} else {
|
|
||||||
currentUrl
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get object from cache.
|
* Get object from cache.
|
||||||
|
|||||||
@@ -6,11 +6,10 @@ import service._
|
|||||||
import jp.sf.amateras.scalatra.forms._
|
import jp.sf.amateras.scalatra.forms._
|
||||||
|
|
||||||
class IndexController extends IndexControllerBase
|
class IndexController extends IndexControllerBase
|
||||||
with RepositoryService with SystemSettingsService with ActivityService with AccountService
|
with RepositoryService with ActivityService with AccountService with UsersAuthenticator
|
||||||
with UsersAuthenticator
|
|
||||||
|
|
||||||
trait IndexControllerBase extends ControllerBase {
|
trait IndexControllerBase extends ControllerBase {
|
||||||
self: RepositoryService with SystemSettingsService with ActivityService with AccountService with UsersAuthenticator =>
|
self: RepositoryService with ActivityService with AccountService with UsersAuthenticator =>
|
||||||
|
|
||||||
case class SignInForm(userName: String, password: String)
|
case class SignInForm(userName: String, password: String)
|
||||||
|
|
||||||
|
|||||||
@@ -6,13 +6,10 @@ import service._
|
|||||||
import jp.sf.amateras.scalatra.forms._
|
import jp.sf.amateras.scalatra.forms._
|
||||||
|
|
||||||
class SearchController extends SearchControllerBase
|
class SearchController extends SearchControllerBase
|
||||||
with RepositoryService with AccountService with SystemSettingsService with ActivityService
|
with RepositoryService with AccountService with ActivityService with RepositorySearchService with IssuesService with ReferrerAuthenticator
|
||||||
with RepositorySearchService with IssuesService
|
|
||||||
with ReferrerAuthenticator
|
|
||||||
|
|
||||||
trait SearchControllerBase extends ControllerBase { self: RepositoryService
|
trait SearchControllerBase extends ControllerBase { self: RepositoryService
|
||||||
with SystemSettingsService with ActivityService with RepositorySearchService
|
with ActivityService with RepositorySearchService with ReferrerAuthenticator =>
|
||||||
with ReferrerAuthenticator =>
|
|
||||||
|
|
||||||
val searchForm = mapping(
|
val searchForm = mapping(
|
||||||
"query" -> trim(text(required)),
|
"query" -> trim(text(required)),
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ trait SystemSettingsControllerBase extends ControllerBase with FlashMapSupport {
|
|||||||
self: SystemSettingsService with AccountService with AdminAuthenticator =>
|
self: SystemSettingsService with AccountService with AdminAuthenticator =>
|
||||||
|
|
||||||
private val form = mapping(
|
private val form = mapping(
|
||||||
|
"baseUrl" -> trim(label("Base URL", optional(text()))),
|
||||||
"allowAccountRegistration" -> trim(label("Account registration", boolean())),
|
"allowAccountRegistration" -> trim(label("Account registration", boolean())),
|
||||||
"gravatar" -> trim(label("Gravatar", boolean())),
|
"gravatar" -> trim(label("Gravatar", boolean())),
|
||||||
"notification" -> trim(label("Notification", boolean())),
|
"notification" -> trim(label("Notification", boolean())),
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ trait SystemSettingsService {
|
|||||||
|
|
||||||
def saveSystemSettings(settings: SystemSettings): Unit = {
|
def saveSystemSettings(settings: SystemSettings): Unit = {
|
||||||
defining(new java.util.Properties()){ props =>
|
defining(new java.util.Properties()){ props =>
|
||||||
|
settings.baseUrl.foreach(props.setProperty(BaseURL, _))
|
||||||
props.setProperty(AllowAccountRegistration, settings.allowAccountRegistration.toString)
|
props.setProperty(AllowAccountRegistration, settings.allowAccountRegistration.toString)
|
||||||
props.setProperty(Gravatar, settings.gravatar.toString)
|
props.setProperty(Gravatar, settings.gravatar.toString)
|
||||||
props.setProperty(Notification, settings.notification.toString)
|
props.setProperty(Notification, settings.notification.toString)
|
||||||
@@ -48,6 +49,7 @@ trait SystemSettingsService {
|
|||||||
props.load(new java.io.FileInputStream(GitBucketConf))
|
props.load(new java.io.FileInputStream(GitBucketConf))
|
||||||
}
|
}
|
||||||
SystemSettings(
|
SystemSettings(
|
||||||
|
getOptionValue(props, BaseURL, None),
|
||||||
getValue(props, AllowAccountRegistration, false),
|
getValue(props, AllowAccountRegistration, false),
|
||||||
getValue(props, Gravatar, true),
|
getValue(props, Gravatar, true),
|
||||||
getValue(props, Notification, false),
|
getValue(props, Notification, false),
|
||||||
@@ -89,6 +91,7 @@ object SystemSettingsService {
|
|||||||
import scala.reflect.ClassTag
|
import scala.reflect.ClassTag
|
||||||
|
|
||||||
case class SystemSettings(
|
case class SystemSettings(
|
||||||
|
baseUrl: Option[String],
|
||||||
allowAccountRegistration: Boolean,
|
allowAccountRegistration: Boolean,
|
||||||
gravatar: Boolean,
|
gravatar: Boolean,
|
||||||
notification: Boolean,
|
notification: Boolean,
|
||||||
@@ -120,6 +123,7 @@ object SystemSettingsService {
|
|||||||
val DefaultSmtpPort = 25
|
val DefaultSmtpPort = 25
|
||||||
val DefaultLdapPort = 389
|
val DefaultLdapPort = 389
|
||||||
|
|
||||||
|
private val BaseURL = "base_url"
|
||||||
private val AllowAccountRegistration = "allow_account_registration"
|
private val AllowAccountRegistration = "allow_account_registration"
|
||||||
private val Gravatar = "gravatar"
|
private val Gravatar = "gravatar"
|
||||||
private val Notification = "notification"
|
private val Notification = "notification"
|
||||||
|
|||||||
@@ -15,6 +15,21 @@
|
|||||||
<label class="strong">GITBUCKET_HOME</label>
|
<label class="strong">GITBUCKET_HOME</label>
|
||||||
@GitBucketHome
|
@GitBucketHome
|
||||||
<!--====================================================================-->
|
<!--====================================================================-->
|
||||||
|
<!-- Base URL -->
|
||||||
|
<!--====================================================================-->
|
||||||
|
<hr>
|
||||||
|
<label><span class="strong">Base URL</span> (e.g. <code>http://example.com/gitbucket</code>)</label>
|
||||||
|
<fieldset>
|
||||||
|
<div class="controls">
|
||||||
|
<input type="text" name="baseUrl" id="baseUrl" style="width: 400px" value="@settings.baseUrl"/>
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
<p>
|
||||||
|
The base URL is used for redirect, notification email, git repository URL box and more.
|
||||||
|
If the base URL is empty, GitBucket generates URL from request information.
|
||||||
|
You can use this property to adjust URL difference between the reverse proxy and GitBucket.
|
||||||
|
</p>
|
||||||
|
<!--====================================================================-->
|
||||||
<!-- Account registration -->
|
<!-- Account registration -->
|
||||||
<!--====================================================================-->
|
<!--====================================================================-->
|
||||||
<hr>
|
<hr>
|
||||||
|
|||||||
@@ -61,7 +61,7 @@
|
|||||||
}
|
}
|
||||||
<a href="@path/signout" class="menu-last" data-toggle="tooltip" data-placement="bottom" title="Sign out"><i class="icon-share-alt"></i></a>
|
<a href="@path/signout" class="menu-last" data-toggle="tooltip" data-placement="bottom" title="Sign out"><i class="icon-share-alt"></i></a>
|
||||||
} else {
|
} else {
|
||||||
<a href="@path/signin?redirect=@redirectUrl" class="btn btn-last">Sign in</a>
|
<a href="@path/signin" class="btn btn-last" id="signin">Sign in</a>
|
||||||
}
|
}
|
||||||
</div><!--/.nav-collapse -->
|
</div><!--/.nav-collapse -->
|
||||||
</div>
|
</div>
|
||||||
@@ -76,6 +76,7 @@
|
|||||||
$('#search').submit(function(){
|
$('#search').submit(function(){
|
||||||
return $.trim($(this).find('input[name=query]').val()) != '';
|
return $.trim($(this).find('input[name=query]').val()) != '';
|
||||||
});
|
});
|
||||||
|
$('#signin').attr('href', '@path/signin?redirect=' + encodeURIComponent(location.pathname + location.search + location.hash));
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user