mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-09 06:55:54 +01:00
Add Authorization logic to Controller
This commit is contained in:
@@ -2,7 +2,7 @@ package service
|
||||
|
||||
import model.Profile._
|
||||
import profile.simple._
|
||||
import model.AccessToken
|
||||
import model.{Account, AccessToken}
|
||||
import util.StringUtil
|
||||
import scala.util.Random
|
||||
|
||||
@@ -34,6 +34,13 @@ trait AccessTokenService {
|
||||
(tokenId, token)
|
||||
}
|
||||
|
||||
def getAccountByAccessToken(token: String)(implicit s: Session): Option[Account] =
|
||||
Accounts
|
||||
.innerJoin(AccessTokens)
|
||||
.filter{ case (ac, t) => (ac.userName === t.userName) && (t.tokenHash === tokenToHash(token).bind) && (ac.removed === false.bind) }
|
||||
.map{ case (ac, t) => ac }
|
||||
.firstOption
|
||||
|
||||
def getAccessTokens(userName: String)(implicit s: Session): List[AccessToken] =
|
||||
AccessTokens.filter(_.userName === userName.bind).sortBy(_.accessTokenId.desc).list
|
||||
|
||||
@@ -41,3 +48,5 @@ trait AccessTokenService {
|
||||
AccessTokens filter (t => t.userName === userName.bind && t.accessTokenId === accessTokenId) delete
|
||||
|
||||
}
|
||||
|
||||
object AccessTokenService extends AccessTokenService
|
||||
|
||||
Reference in New Issue
Block a user