1
0
mirror of https://github.com/go-gitea/gitea synced 2024-11-07 09:15:53 +01:00

token recent activity

This commit is contained in:
Unknwon 2015-08-19 06:22:33 +08:00
parent 54b52de6ee
commit 03b85b73af
6 changed files with 24 additions and 8 deletions

@ -278,6 +278,7 @@ add_on = Added on
last_used = Last used on
no_activity = No recent activity
key_state_desc = This key is used in last 7 days
token_state_desc = This token is used in last 7 days
manage_social = Manage Associated Social Accounts
social_desc = This is a list of associated social accounts. Remove any binding that you do not recognize.

@ -35,8 +35,8 @@ func NewAccessToken(t *AccessToken) error {
return err
}
// GetAccessTokenBySha returns access token by given sha1.
func GetAccessTokenBySha(sha string) (*AccessToken, error) {
// GetAccessTokenBySHA returns access token by given sha1.
func GetAccessTokenBySHA(sha string) (*AccessToken, error) {
t := &AccessToken{Sha1: sha}
has, err := x.Get(t)
if err != nil {
@ -62,6 +62,12 @@ func ListAccessTokens(uid int64) ([]*AccessToken, error) {
return tokens, nil
}
// UpdateAccessToekn updates information of access token.
func UpdateAccessToekn(t *AccessToken) error {
_, err := x.Id(t.ID).AllCols().Update(t)
return err
}
// DeleteAccessTokenByID deletes access token by given ID.
func DeleteAccessTokenByID(id int64) error {
_, err := x.Id(id).Delete(new(AccessToken))

@ -8,6 +8,7 @@ import (
"net/http"
"reflect"
"strings"
"time"
"github.com/Unknwon/com"
"github.com/Unknwon/macaron"
@ -37,13 +38,17 @@ func SignedInId(req *http.Request, sess session.Store) int64 {
if len(auHead) > 0 {
auths := strings.Fields(auHead)
if len(auths) == 2 && auths[0] == "token" {
t, err := models.GetAccessTokenBySha(auths[1])
t, err := models.GetAccessTokenBySHA(auths[1])
if err != nil {
if err != models.ErrAccessTokenNotExist {
log.Error(4, "GetAccessTokenBySha: %v", err)
log.Error(4, "GetAccessTokenBySHA: %v", err)
}
return 0
}
t.Updated = time.Now()
if err = models.UpdateAccessToekn(t); err != nil {
log.Error(4, "UpdateAccessToekn: %v", err)
}
return t.UID
}
}

File diff suppressed because one or more lines are too long

@ -113,7 +113,7 @@ func Http(ctx *middleware.Context) {
}
// Assume username now is a token.
token, err := models.GetAccessTokenBySha(authUsername)
token, err := models.GetAccessTokenBySHA(authUsername)
if err != nil {
if err == models.ErrAccessTokenNotExist {
ctx.HandleText(401, "invalid token")
@ -122,6 +122,10 @@ func Http(ctx *middleware.Context) {
}
return
}
token.Updated = time.Now()
if err = models.UpdateAccessToekn(token); err != nil {
ctx.Handle(500, "UpdateAccessToekn", err)
}
authUser, err = models.GetUserByID(token.UID)
if err != nil {
ctx.Handle(500, "GetUserById", err)

@ -19,7 +19,7 @@
{{range .Tokens}}
<div class="item ui grid">
<div class="one wide column">
<i class="ssh-key-state-indicator fa fa-circle{{if .HasRecentActivity}} active invert poping up{{else}}-o{{end}}" {{if .HasRecentActivity}}data-content="{{$.i18n.Tr "settings.key_state_desc"}}" data-variation="inverted"{{end}}></i>
<i class="ssh-key-state-indicator fa fa-circle{{if .HasRecentActivity}} active invert poping up{{else}}-o{{end}}" {{if .HasRecentActivity}}data-content="{{$.i18n.Tr "settings.token_state_desc"}}" data-variation="inverted"{{end}}></i>
</div>
<div class="one wide column">
<i class="fa fa-send fa-2x left"></i>