Revert line separator from LF to CRLF

This commit is contained in:
yjkony
2014-03-04 10:16:12 +09:00
parent 5e0619b500
commit ce3b6ed7c2
2 changed files with 268 additions and 268 deletions

View File

@@ -1,85 +1,85 @@
package app package app
import util._ import util._
import service._ 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 ActivityService with AccountService with UsersAuthenticator with RepositoryService with ActivityService with AccountService with UsersAuthenticator
trait IndexControllerBase extends ControllerBase { trait IndexControllerBase extends ControllerBase {
self: RepositoryService 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)
val form = mapping( val form = mapping(
"userName" -> trim(label("Username", text(required))), "userName" -> trim(label("Username", text(required))),
"password" -> trim(label("Password", text(required))) "password" -> trim(label("Password", text(required)))
)(SignInForm.apply) )(SignInForm.apply)
get("/"){ get("/"){
val loginAccount = context.loginAccount val loginAccount = context.loginAccount
html.index(getRecentActivities(), html.index(getRecentActivities(),
getVisibleRepositories(loginAccount, baseUrl), getVisibleRepositories(loginAccount, baseUrl),
loadSystemSettings(), loadSystemSettings(),
loginAccount.map{ account => getUserRepositories(account.userName, baseUrl) }.getOrElse(Nil) loginAccount.map{ account => getUserRepositories(account.userName, baseUrl) }.getOrElse(Nil)
) )
} }
get("/signin"){ get("/signin"){
val redirect = params.get("redirect") val redirect = params.get("redirect")
if(redirect.isDefined && redirect.get.startsWith("/")){ if(redirect.isDefined && redirect.get.startsWith("/")){
flash += Keys.Flash.Redirect -> redirect.get flash += Keys.Flash.Redirect -> redirect.get
} }
html.signin(loadSystemSettings()) html.signin(loadSystemSettings())
} }
post("/signin", form){ form => post("/signin", form){ form =>
authenticate(loadSystemSettings(), form.userName, form.password) match { authenticate(loadSystemSettings(), form.userName, form.password) match {
case Some(account) => signin(account) case Some(account) => signin(account)
case None => redirect("/signin") case None => redirect("/signin")
} }
} }
get("/signout"){ get("/signout"){
session.invalidate session.invalidate
redirect("/") redirect("/")
} }
/** /**
* Set account information into HttpSession and redirect. * Set account information into HttpSession and redirect.
*/ */
private def signin(account: model.Account) = { private def signin(account: model.Account) = {
session.setAttribute(Keys.Session.LoginAccount, account) session.setAttribute(Keys.Session.LoginAccount, account)
updateLastLoginDate(account.userName) updateLastLoginDate(account.userName)
if(AccountUtil.hasLdapDummyMailAddress(account)) { if(AccountUtil.hasLdapDummyMailAddress(account)) {
redirect("/" + account.userName + "/_edit") redirect("/" + account.userName + "/_edit")
} }
flash.get(Keys.Flash.Redirect).asInstanceOf[Option[String]].map { redirectUrl => flash.get(Keys.Flash.Redirect).asInstanceOf[Option[String]].map { redirectUrl =>
if(redirectUrl.replaceFirst("/$", "") == request.getContextPath){ if(redirectUrl.replaceFirst("/$", "") == request.getContextPath){
redirect("/") redirect("/")
} else { } else {
redirect(redirectUrl) redirect(redirectUrl)
} }
}.getOrElse { }.getOrElse {
redirect("/") redirect("/")
} }
} }
/** /**
* JSON API for collaborator completion. * JSON API for collaborator completion.
* *
* TODO Move to other controller? * TODO Move to other controller?
*/ */
get("/_user/proposals")(usersOnly { get("/_user/proposals")(usersOnly {
contentType = formats("json") contentType = formats("json")
org.json4s.jackson.Serialization.write( org.json4s.jackson.Serialization.write(
Map("options" -> getAllUsers().filter(!_.isGroupAccount).map(_.userName).toArray) Map("options" -> getAllUsers().filter(!_.isGroupAccount).map(_.userName).toArray)
) )
}) })
} }

View File

@@ -1,183 +1,183 @@
package service package service
import util.Directory._ import util.Directory._
import util.ControlUtil._ import util.ControlUtil._
import SystemSettingsService._ import SystemSettingsService._
import javax.servlet.http.HttpServletRequest import javax.servlet.http.HttpServletRequest
trait SystemSettingsService { trait SystemSettingsService {
def baseUrl(implicit request: HttpServletRequest): String = loadSystemSettings().baseUrl.getOrElse { def baseUrl(implicit request: HttpServletRequest): String = loadSystemSettings().baseUrl.getOrElse {
defining(request.getRequestURL.toString){ url => defining(request.getRequestURL.toString){ url =>
url.substring(0, url.length - (request.getRequestURI.length - request.getContextPath.length)) url.substring(0, url.length - (request.getRequestURI.length - request.getContextPath.length))
} }
}.replaceFirst("/$", "") }.replaceFirst("/$", "")
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, _)) 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)
if(settings.notification) { if(settings.notification) {
settings.smtp.foreach { smtp => settings.smtp.foreach { smtp =>
props.setProperty(SmtpHost, smtp.host) props.setProperty(SmtpHost, smtp.host)
smtp.port.foreach(x => props.setProperty(SmtpPort, x.toString)) smtp.port.foreach(x => props.setProperty(SmtpPort, x.toString))
smtp.user.foreach(props.setProperty(SmtpUser, _)) smtp.user.foreach(props.setProperty(SmtpUser, _))
smtp.password.foreach(props.setProperty(SmtpPassword, _)) smtp.password.foreach(props.setProperty(SmtpPassword, _))
smtp.ssl.foreach(x => props.setProperty(SmtpSsl, x.toString)) smtp.ssl.foreach(x => props.setProperty(SmtpSsl, x.toString))
smtp.fromAddress.foreach(props.setProperty(SmtpFromAddress, _)) smtp.fromAddress.foreach(props.setProperty(SmtpFromAddress, _))
smtp.fromName.foreach(props.setProperty(SmtpFromName, _)) smtp.fromName.foreach(props.setProperty(SmtpFromName, _))
} }
} }
props.setProperty(LdapAuthentication, settings.ldapAuthentication.toString) props.setProperty(LdapAuthentication, settings.ldapAuthentication.toString)
if(settings.ldapAuthentication){ if(settings.ldapAuthentication){
settings.ldap.map { ldap => settings.ldap.map { ldap =>
props.setProperty(LdapHost, ldap.host) props.setProperty(LdapHost, ldap.host)
ldap.port.foreach(x => props.setProperty(LdapPort, x.toString)) ldap.port.foreach(x => props.setProperty(LdapPort, x.toString))
ldap.bindDN.foreach(x => props.setProperty(LdapBindDN, x)) ldap.bindDN.foreach(x => props.setProperty(LdapBindDN, x))
ldap.bindPassword.foreach(x => props.setProperty(LdapBindPassword, x)) ldap.bindPassword.foreach(x => props.setProperty(LdapBindPassword, x))
props.setProperty(LdapBaseDN, ldap.baseDN) props.setProperty(LdapBaseDN, ldap.baseDN)
props.setProperty(LdapUserNameAttribute, ldap.userNameAttribute) props.setProperty(LdapUserNameAttribute, ldap.userNameAttribute)
ldap.additionalFilterCondition.foreach(x => props.setProperty(LdapAdditionalFilterCondition, x)) ldap.additionalFilterCondition.foreach(x => props.setProperty(LdapAdditionalFilterCondition, x))
ldap.fullNameAttribute.foreach(x => props.setProperty(LdapFullNameAttribute, x)) ldap.fullNameAttribute.foreach(x => props.setProperty(LdapFullNameAttribute, x))
props.setProperty(LdapMailAddressAttribute, ldap.mailAttribute) props.setProperty(LdapMailAddressAttribute, ldap.mailAttribute)
ldap.disableMailResolve.foreach(x => props.setProperty(LdapDisableMailResolve, x.toString)) ldap.disableMailResolve.foreach(x => props.setProperty(LdapDisableMailResolve, x.toString))
ldap.tls.foreach(x => props.setProperty(LdapTls, x.toString)) ldap.tls.foreach(x => props.setProperty(LdapTls, x.toString))
ldap.keystore.foreach(x => props.setProperty(LdapKeystore, x)) ldap.keystore.foreach(x => props.setProperty(LdapKeystore, x))
} }
} }
props.store(new java.io.FileOutputStream(GitBucketConf), null) props.store(new java.io.FileOutputStream(GitBucketConf), null)
} }
} }
def loadSystemSettings(): SystemSettings = { def loadSystemSettings(): SystemSettings = {
defining(new java.util.Properties()){ props => defining(new java.util.Properties()){ props =>
if(GitBucketConf.exists){ if(GitBucketConf.exists){
props.load(new java.io.FileInputStream(GitBucketConf)) props.load(new java.io.FileInputStream(GitBucketConf))
} }
SystemSettings( SystemSettings(
getOptionValue(props, BaseURL, None), 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),
if(getValue(props, Notification, false)){ if(getValue(props, Notification, false)){
Some(Smtp( Some(Smtp(
getValue(props, SmtpHost, ""), getValue(props, SmtpHost, ""),
getOptionValue(props, SmtpPort, Some(DefaultSmtpPort)), getOptionValue(props, SmtpPort, Some(DefaultSmtpPort)),
getOptionValue(props, SmtpUser, None), getOptionValue(props, SmtpUser, None),
getOptionValue(props, SmtpPassword, None), getOptionValue(props, SmtpPassword, None),
getOptionValue[Boolean](props, SmtpSsl, None), getOptionValue[Boolean](props, SmtpSsl, None),
getOptionValue(props, SmtpFromAddress, None), getOptionValue(props, SmtpFromAddress, None),
getOptionValue(props, SmtpFromName, None))) getOptionValue(props, SmtpFromName, None)))
} else { } else {
None None
}, },
getValue(props, LdapAuthentication, false), getValue(props, LdapAuthentication, false),
if(getValue(props, LdapAuthentication, false)){ if(getValue(props, LdapAuthentication, false)){
Some(Ldap( Some(Ldap(
getValue(props, LdapHost, ""), getValue(props, LdapHost, ""),
getOptionValue(props, LdapPort, Some(DefaultLdapPort)), getOptionValue(props, LdapPort, Some(DefaultLdapPort)),
getOptionValue(props, LdapBindDN, None), getOptionValue(props, LdapBindDN, None),
getOptionValue(props, LdapBindPassword, None), getOptionValue(props, LdapBindPassword, None),
getValue(props, LdapBaseDN, ""), getValue(props, LdapBaseDN, ""),
getValue(props, LdapUserNameAttribute, ""), getValue(props, LdapUserNameAttribute, ""),
getOptionValue(props, LdapAdditionalFilterCondition, None), getOptionValue(props, LdapAdditionalFilterCondition, None),
getOptionValue(props, LdapFullNameAttribute, None), getOptionValue(props, LdapFullNameAttribute, None),
getValue(props, LdapMailAddressAttribute, ""), getValue(props, LdapMailAddressAttribute, ""),
getOptionValue[Boolean](props, LdapDisableMailResolve, None), getOptionValue[Boolean](props, LdapDisableMailResolve, None),
getOptionValue[Boolean](props, LdapTls, None), getOptionValue[Boolean](props, LdapTls, None),
getOptionValue(props, LdapKeystore, None))) getOptionValue(props, LdapKeystore, None)))
} else { } else {
None None
} }
) )
} }
} }
} }
object SystemSettingsService { object SystemSettingsService {
import scala.reflect.ClassTag import scala.reflect.ClassTag
case class SystemSettings( case class SystemSettings(
baseUrl: Option[String], baseUrl: Option[String],
allowAccountRegistration: Boolean, allowAccountRegistration: Boolean,
gravatar: Boolean, gravatar: Boolean,
notification: Boolean, notification: Boolean,
smtp: Option[Smtp], smtp: Option[Smtp],
ldapAuthentication: Boolean, ldapAuthentication: Boolean,
ldap: Option[Ldap]) ldap: Option[Ldap])
case class Ldap( case class Ldap(
host: String, host: String,
port: Option[Int], port: Option[Int],
bindDN: Option[String], bindDN: Option[String],
bindPassword: Option[String], bindPassword: Option[String],
baseDN: String, baseDN: String,
userNameAttribute: String, userNameAttribute: String,
additionalFilterCondition: Option[String], additionalFilterCondition: Option[String],
fullNameAttribute: Option[String], fullNameAttribute: Option[String],
mailAttribute: String, mailAttribute: String,
disableMailResolve: Option[Boolean], disableMailResolve: Option[Boolean],
tls: Option[Boolean], tls: Option[Boolean],
keystore: Option[String]) keystore: Option[String])
case class Smtp( case class Smtp(
host: String, host: String,
port: Option[Int], port: Option[Int],
user: Option[String], user: Option[String],
password: Option[String], password: Option[String],
ssl: Option[Boolean], ssl: Option[Boolean],
fromAddress: Option[String], fromAddress: Option[String],
fromName: Option[String]) fromName: Option[String])
val DefaultSmtpPort = 25 val DefaultSmtpPort = 25
val DefaultLdapPort = 389 val DefaultLdapPort = 389
private val BaseURL = "base_url" 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"
private val SmtpHost = "smtp.host" private val SmtpHost = "smtp.host"
private val SmtpPort = "smtp.port" private val SmtpPort = "smtp.port"
private val SmtpUser = "smtp.user" private val SmtpUser = "smtp.user"
private val SmtpPassword = "smtp.password" private val SmtpPassword = "smtp.password"
private val SmtpSsl = "smtp.ssl" private val SmtpSsl = "smtp.ssl"
private val SmtpFromAddress = "smtp.from_address" private val SmtpFromAddress = "smtp.from_address"
private val SmtpFromName = "smtp.from_name" private val SmtpFromName = "smtp.from_name"
private val LdapAuthentication = "ldap_authentication" private val LdapAuthentication = "ldap_authentication"
private val LdapHost = "ldap.host" private val LdapHost = "ldap.host"
private val LdapPort = "ldap.port" private val LdapPort = "ldap.port"
private val LdapBindDN = "ldap.bindDN" private val LdapBindDN = "ldap.bindDN"
private val LdapBindPassword = "ldap.bind_password" private val LdapBindPassword = "ldap.bind_password"
private val LdapBaseDN = "ldap.baseDN" private val LdapBaseDN = "ldap.baseDN"
private val LdapUserNameAttribute = "ldap.username_attribute" private val LdapUserNameAttribute = "ldap.username_attribute"
private val LdapAdditionalFilterCondition = "ldap.additional_filter_condition" private val LdapAdditionalFilterCondition = "ldap.additional_filter_condition"
private val LdapFullNameAttribute = "ldap.fullname_attribute" private val LdapFullNameAttribute = "ldap.fullname_attribute"
private val LdapMailAddressAttribute = "ldap.mail_attribute" private val LdapMailAddressAttribute = "ldap.mail_attribute"
private val LdapDisableMailResolve = "ldap.disable_mail_resolve" private val LdapDisableMailResolve = "ldap.disable_mail_resolve"
private val LdapTls = "ldap.tls" private val LdapTls = "ldap.tls"
private val LdapKeystore = "ldap.keystore" private val LdapKeystore = "ldap.keystore"
private def getValue[A: ClassTag](props: java.util.Properties, key: String, default: A): A = private def getValue[A: ClassTag](props: java.util.Properties, key: String, default: A): A =
defining(props.getProperty(key)){ value => defining(props.getProperty(key)){ value =>
if(value == null || value.isEmpty) default if(value == null || value.isEmpty) default
else convertType(value).asInstanceOf[A] else convertType(value).asInstanceOf[A]
} }
private def getOptionValue[A: ClassTag](props: java.util.Properties, key: String, default: Option[A]): Option[A] = private def getOptionValue[A: ClassTag](props: java.util.Properties, key: String, default: Option[A]): Option[A] =
defining(props.getProperty(key)){ value => defining(props.getProperty(key)){ value =>
if(value == null || value.isEmpty) default if(value == null || value.isEmpty) default
else Some(convertType(value)).asInstanceOf[Option[A]] else Some(convertType(value)).asInstanceOf[Option[A]]
} }
private def convertType[A: ClassTag](value: String) = private def convertType[A: ClassTag](value: String) =
defining(implicitly[ClassTag[A]].runtimeClass){ c => defining(implicitly[ClassTag[A]].runtimeClass){ c =>
if(c == classOf[Boolean]) value.toBoolean if(c == classOf[Boolean]) value.toBoolean
else if(c == classOf[Int]) value.toInt else if(c == classOf[Int]) value.toInt
else value else value
} }
} }