Add System Settings page.

This commit is contained in:
takezoe
2013-06-28 13:45:31 +09:00
parent a5cb3bc9cd
commit 00ad0c1745
9 changed files with 195 additions and 70 deletions

View File

@@ -0,0 +1,40 @@
package service
import util.Directory._
import SystemSettingsService._
trait SystemSettingsService {
def saveSystemSettings(settings: SystemSettings): Unit = {
val props = new java.util.Properties()
props.setProperty(AllowAccountRegistration, settings.allowAccountRegistration.toString)
props.store(new java.io.FileOutputStream(GitBucketConf), null)
}
def loadSystemSettings(): SystemSettings = {
val props = new java.util.Properties()
if(GitBucketConf.exists){
props.load(new java.io.FileInputStream(GitBucketConf))
}
SystemSettings(getBoolean(props, "allow_account_registration"))
}
}
object SystemSettingsService {
case class SystemSettings(allowAccountRegistration: Boolean)
private val AllowAccountRegistration = "allow_account_registration"
private def getBoolean(props: java.util.Properties, key: String, default: Boolean = false): Boolean = {
val value = props.getProperty(key)
if(value == null || value.isEmpty){
default
} else {
value.toBoolean
}
}
}