mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-02 03:26:06 +01:00
(refs #78)Authentication moved to AccountService.
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
package app
|
||||
|
||||
import service._
|
||||
import util.StringUtil._
|
||||
import jp.sf.amateras.scalatra.forms._
|
||||
import util.LDAPUtil
|
||||
import service.SystemSettingsService.SystemSettings
|
||||
|
||||
class SignInController extends SignInControllerBase with SystemSettingsService with AccountService
|
||||
|
||||
@@ -27,10 +24,9 @@ trait SignInControllerBase extends ControllerBase { self: SystemSettingsService
|
||||
|
||||
post("/signin", form){ form =>
|
||||
val settings = loadSystemSettings()
|
||||
if(settings.ldapAuthentication){
|
||||
ldapAuthentication(form, settings)
|
||||
} else {
|
||||
defaultAuthentication(form)
|
||||
authenticate(loadSystemSettings(), form.userName, form.password) match {
|
||||
case Some(account) => signin(account)
|
||||
case None => redirect("/signin")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,32 +35,6 @@ trait SignInControllerBase extends ControllerBase { self: SystemSettingsService
|
||||
redirect("/")
|
||||
}
|
||||
|
||||
/**
|
||||
* Authenticate by internal database.
|
||||
*/
|
||||
private def defaultAuthentication(form: SignInForm) = {
|
||||
getAccountByUserName(form.userName).collect {
|
||||
case account if(!account.isGroupAccount && account.password == sha1(form.password)) => signin(account)
|
||||
} getOrElse redirect("/signin")
|
||||
}
|
||||
|
||||
/**
|
||||
* Authenticate by LDAP.
|
||||
*/
|
||||
private def ldapAuthentication(form: SignInForm, settings: SystemSettings) = {
|
||||
LDAPUtil.authenticate(settings.ldap.get, form.userName, form.password) match {
|
||||
case Right(mailAddress) => {
|
||||
// Create or update account by LDAP information
|
||||
getAccountByUserName(form.userName) match {
|
||||
case Some(x) => updateAccount(x.copy(mailAddress = mailAddress))
|
||||
case None => createAccount(form.userName, "", mailAddress, false, None)
|
||||
}
|
||||
signin(getAccountByUserName(form.userName).get)
|
||||
}
|
||||
case Left(errorMessage) => defaultAuthentication(form)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set account information into HttpSession and redirect.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user