diff --git a/src/main/scala/gitbucket/core/controller/IndexController.scala b/src/main/scala/gitbucket/core/controller/IndexController.scala index f5390b4..1cb7838 100644 --- a/src/main/scala/gitbucket/core/controller/IndexController.scala +++ b/src/main/scala/gitbucket/core/controller/IndexController.scala @@ -25,6 +25,7 @@ with PrioritiesService with UsersAuthenticator with ReferrerAuthenticator + with AccessTokenService with AccountFederationService with OpenIDConnectService @@ -36,6 +37,8 @@ with RepositorySearchService with UsersAuthenticator with ReferrerAuthenticator + with AccessTokenService + with AccountFederationService with OpenIDConnectService => case class SignInForm(userName: String, password: String, hash: Option[String]) @@ -59,9 +62,17 @@ get("/"){ context.loginAccount.map { account => val visibleOwnerSet: Set[String] = Set(account.userName) ++ getGroupsByUserName(account.userName) - gitbucket.core.html.index(getRecentActivitiesByOwners(visibleOwnerSet), Nil, getUserRepositories(account.userName, withoutPhysicalInfo = true)) + gitbucket.core.html.index( + getRecentActivitiesByOwners(visibleOwnerSet), + Nil, + getUserRepositories(account.userName, withoutPhysicalInfo = true), + showBannerToCreatePersonalAccessToken = hasAccountFederation(account.userName) && !hasAccessToken(account.userName)) }.getOrElse { - gitbucket.core.html.index(getRecentActivities(), getVisibleRepositories(None, withoutPhysicalInfo = true), Nil) + gitbucket.core.html.index( + getRecentActivities(), + getVisibleRepositories(None, withoutPhysicalInfo = true), + Nil, + showBannerToCreatePersonalAccessToken = false) } } diff --git a/src/main/scala/gitbucket/core/service/AccessTokenService.scala b/src/main/scala/gitbucket/core/service/AccessTokenService.scala index 14cb0fa..8c123c5 100644 --- a/src/main/scala/gitbucket/core/service/AccessTokenService.scala +++ b/src/main/scala/gitbucket/core/service/AccessTokenService.scala @@ -2,7 +2,7 @@ import gitbucket.core.model.Profile._ import gitbucket.core.model.Profile.profile.blockingApi._ -import gitbucket.core.model.{Account, AccessToken} +import gitbucket.core.model.{AccessToken, Account} import gitbucket.core.util.StringUtil import scala.util.Random @@ -48,6 +48,9 @@ def getAccessTokens(userName: String)(implicit s: Session): List[AccessToken] = AccessTokens.filter(_.userName === userName.bind).sortBy(_.accessTokenId.desc).list + def hasAccessToken(userName: String)(implicit s: Session): Boolean = + AccessTokens.filter(_.userName === userName.bind).exists.run + def deleteAccessToken(userName: String, accessTokenId: Int)(implicit s: Session): Unit = AccessTokens filter (t => t.userName === userName.bind && t.accessTokenId === accessTokenId) delete diff --git a/src/main/scala/gitbucket/core/service/AccountFederationService.scala b/src/main/scala/gitbucket/core/service/AccountFederationService.scala index bfb574c..a560127 100644 --- a/src/main/scala/gitbucket/core/service/AccountFederationService.scala +++ b/src/main/scala/gitbucket/core/service/AccountFederationService.scala @@ -70,6 +70,9 @@ .map { case _ ~ ac => ac } .firstOption + def hasAccountFederation(userName: String)(implicit s: Session): Boolean = + AccountFederations.filter(_.userName === userName.bind).exists.run + def createAccountFederation(issuer: String, subject: String, userName: String)(implicit s: Session): Unit = AccountFederations insert AccountFederation(issuer, subject, userName) } diff --git a/src/main/twirl/gitbucket/core/index.scala.html b/src/main/twirl/gitbucket/core/index.scala.html index c0db851..83ca41c 100644 --- a/src/main/twirl/gitbucket/core/index.scala.html +++ b/src/main/twirl/gitbucket/core/index.scala.html @@ -1,6 +1,7 @@ @(activities: List[gitbucket.core.model.Activity], recentRepositories: List[gitbucket.core.service.RepositoryService.RepositoryInfo], - userRepositories: List[gitbucket.core.service.RepositoryService.RepositoryInfo])(implicit context: gitbucket.core.controller.Context) + userRepositories: List[gitbucket.core.service.RepositoryService.RepositoryInfo], + showBannerToCreatePersonalAccessToken: Boolean)(implicit context: gitbucket.core.controller.Context) @import gitbucket.core.view.helpers @gitbucket.core.html.main("GitBucket"){ @gitbucket.core.dashboard.html.sidebar(recentRepositories, userRepositories){ @@ -10,6 +11,15 @@ @Html(information) } + @if(showBannerToCreatePersonalAccessToken){ +
+ + You can + + create a personal access token + and use it in place of a password on the git command line. +
+ } @gitbucket.core.dashboard.html.tab()