mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-07 14:05:52 +01:00
Merge SignInController into IndexController
This commit is contained in:
@@ -17,7 +17,6 @@ class ScalatraBootstrap extends LifeCycle {
|
|||||||
context.mount(new IndexController, "/")
|
context.mount(new IndexController, "/")
|
||||||
context.mount(new SearchController, "/")
|
context.mount(new SearchController, "/")
|
||||||
context.mount(new FileUploadController, "/upload")
|
context.mount(new FileUploadController, "/upload")
|
||||||
context.mount(new SignInController, "/*")
|
|
||||||
context.mount(new DashboardController, "/*")
|
context.mount(new DashboardController, "/*")
|
||||||
context.mount(new UserManagementController, "/*")
|
context.mount(new UserManagementController, "/*")
|
||||||
context.mount(new SystemSettingsController, "/*")
|
context.mount(new SystemSettingsController, "/*")
|
||||||
|
|||||||
@@ -1,15 +1,23 @@
|
|||||||
package app
|
package app
|
||||||
|
|
||||||
import util._
|
import util._
|
||||||
|
import util.Implicits._
|
||||||
import service._
|
import service._
|
||||||
|
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 SystemSettingsService with ActivityService with AccountService
|
||||||
with UsersAuthenticator
|
with UsersAuthenticator
|
||||||
|
|
||||||
trait IndexControllerBase extends ControllerBase {
|
trait IndexControllerBase extends ControllerBase {
|
||||||
self: RepositoryService with SystemSettingsService with ActivityService with AccountService
|
self: RepositoryService with SystemSettingsService with ActivityService with AccountService with UsersAuthenticator =>
|
||||||
with UsersAuthenticator =>
|
|
||||||
|
case class SignInForm(userName: String, password: String)
|
||||||
|
|
||||||
|
val form = mapping(
|
||||||
|
"userName" -> trim(label("Username", text(required))),
|
||||||
|
"password" -> trim(label("Password", text(required)))
|
||||||
|
)(SignInForm.apply)
|
||||||
|
|
||||||
get("/"){
|
get("/"){
|
||||||
val loginAccount = context.loginAccount
|
val loginAccount = context.loginAccount
|
||||||
@@ -21,6 +29,44 @@ trait IndexControllerBase extends ControllerBase {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get("/signin"){
|
||||||
|
val redirect = params.get("redirect")
|
||||||
|
if(redirect.isDefined && redirect.get.startsWith("/")){
|
||||||
|
session.setAttribute(Keys.Session.Redirect, redirect.get)
|
||||||
|
}
|
||||||
|
html.signin(loadSystemSettings())
|
||||||
|
}
|
||||||
|
|
||||||
|
post("/signin", form){ form =>
|
||||||
|
authenticate(loadSystemSettings(), form.userName, form.password) match {
|
||||||
|
case Some(account) => signin(account)
|
||||||
|
case None => redirect("/signin")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get("/signout"){
|
||||||
|
session.invalidate
|
||||||
|
redirect("/")
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set account information into HttpSession and redirect.
|
||||||
|
*/
|
||||||
|
private def signin(account: model.Account) = {
|
||||||
|
session.setAttribute(Keys.Session.LoginAccount, account)
|
||||||
|
updateLastLoginDate(account.userName)
|
||||||
|
|
||||||
|
session.getAndRemove[String](Keys.Session.Redirect).map { redirectUrl =>
|
||||||
|
if(redirectUrl.replaceFirst("/$", "") == request.getContextPath){
|
||||||
|
redirect("/")
|
||||||
|
} else {
|
||||||
|
redirect(redirectUrl)
|
||||||
|
}
|
||||||
|
}.getOrElse {
|
||||||
|
redirect("/")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JSON API for collaborator completion.
|
* JSON API for collaborator completion.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,58 +0,0 @@
|
|||||||
package app
|
|
||||||
|
|
||||||
import service._
|
|
||||||
import jp.sf.amateras.scalatra.forms._
|
|
||||||
import util.Implicits._
|
|
||||||
import util.StringUtil._
|
|
||||||
import util.Keys
|
|
||||||
|
|
||||||
class SignInController extends SignInControllerBase with SystemSettingsService with AccountService
|
|
||||||
|
|
||||||
trait SignInControllerBase extends ControllerBase { self: SystemSettingsService with AccountService =>
|
|
||||||
|
|
||||||
case class SignInForm(userName: String, password: String)
|
|
||||||
|
|
||||||
val form = mapping(
|
|
||||||
"userName" -> trim(label("Username", text(required))),
|
|
||||||
"password" -> trim(label("Password", text(required)))
|
|
||||||
)(SignInForm.apply)
|
|
||||||
|
|
||||||
get("/signin"){
|
|
||||||
val redirect = params.get("redirect")
|
|
||||||
if(redirect.isDefined && redirect.get.startsWith("/")){
|
|
||||||
session.setAttribute(Keys.Session.Redirect, redirect.get)
|
|
||||||
}
|
|
||||||
html.signin(loadSystemSettings())
|
|
||||||
}
|
|
||||||
|
|
||||||
post("/signin", form){ form =>
|
|
||||||
authenticate(loadSystemSettings(), form.userName, form.password) match {
|
|
||||||
case Some(account) => signin(account)
|
|
||||||
case None => redirect("/signin")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
get("/signout"){
|
|
||||||
session.invalidate
|
|
||||||
redirect("/")
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set account information into HttpSession and redirect.
|
|
||||||
*/
|
|
||||||
private def signin(account: model.Account) = {
|
|
||||||
session.setAttribute(Keys.Session.LoginAccount, account)
|
|
||||||
updateLastLoginDate(account.userName)
|
|
||||||
|
|
||||||
session.getAndRemove[String](Keys.Session.Redirect).map { redirectUrl =>
|
|
||||||
if(redirectUrl.replaceFirst("/$", "") == request.getContextPath){
|
|
||||||
redirect("/")
|
|
||||||
} else {
|
|
||||||
redirect(redirectUrl)
|
|
||||||
}
|
|
||||||
}.getOrElse {
|
|
||||||
redirect("/")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user