token recent activity
This commit is contained in:
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
|
last_used = Last used on
|
||||||
no_activity = No recent activity
|
no_activity = No recent activity
|
||||||
key_state_desc = This key is used in last 7 days
|
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
|
manage_social = Manage Associated Social Accounts
|
||||||
social_desc = This is a list of associated social accounts. Remove any binding that you do not recognize.
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAccessTokenBySha returns access token by given sha1.
|
// GetAccessTokenBySHA returns access token by given sha1.
|
||||||
func GetAccessTokenBySha(sha string) (*AccessToken, error) {
|
func GetAccessTokenBySHA(sha string) (*AccessToken, error) {
|
||||||
t := &AccessToken{Sha1: sha}
|
t := &AccessToken{Sha1: sha}
|
||||||
has, err := x.Get(t)
|
has, err := x.Get(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -62,6 +62,12 @@ func ListAccessTokens(uid int64) ([]*AccessToken, error) {
|
||||||
return tokens, nil
|
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.
|
// DeleteAccessTokenByID deletes access token by given ID.
|
||||||
func DeleteAccessTokenByID(id int64) error {
|
func DeleteAccessTokenByID(id int64) error {
|
||||||
_, err := x.Id(id).Delete(new(AccessToken))
|
_, err := x.Id(id).Delete(new(AccessToken))
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/Unknwon/com"
|
"github.com/Unknwon/com"
|
||||||
"github.com/Unknwon/macaron"
|
"github.com/Unknwon/macaron"
|
||||||
|
@ -37,13 +38,17 @@ func SignedInId(req *http.Request, sess session.Store) int64 {
|
||||||
if len(auHead) > 0 {
|
if len(auHead) > 0 {
|
||||||
auths := strings.Fields(auHead)
|
auths := strings.Fields(auHead)
|
||||||
if len(auths) == 2 && auths[0] == "token" {
|
if len(auths) == 2 && auths[0] == "token" {
|
||||||
t, err := models.GetAccessTokenBySha(auths[1])
|
t, err := models.GetAccessTokenBySHA(auths[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err != models.ErrAccessTokenNotExist {
|
if err != models.ErrAccessTokenNotExist {
|
||||||
log.Error(4, "GetAccessTokenBySha: %v", err)
|
log.Error(4, "GetAccessTokenBySHA: %v", err)
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
t.Updated = time.Now()
|
||||||
|
if err = models.UpdateAccessToekn(t); err != nil {
|
||||||
|
log.Error(4, "UpdateAccessToekn: %v", err)
|
||||||
|
}
|
||||||
return t.UID
|
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.
|
// Assume username now is a token.
|
||||||
token, err := models.GetAccessTokenBySha(authUsername)
|
token, err := models.GetAccessTokenBySHA(authUsername)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == models.ErrAccessTokenNotExist {
|
if err == models.ErrAccessTokenNotExist {
|
||||||
ctx.HandleText(401, "invalid token")
|
ctx.HandleText(401, "invalid token")
|
||||||
|
@ -122,6 +122,10 @@ func Http(ctx *middleware.Context) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
token.Updated = time.Now()
|
||||||
|
if err = models.UpdateAccessToekn(token); err != nil {
|
||||||
|
ctx.Handle(500, "UpdateAccessToekn", err)
|
||||||
|
}
|
||||||
authUser, err = models.GetUserByID(token.UID)
|
authUser, err = models.GetUserByID(token.UID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(500, "GetUserById", err)
|
ctx.Handle(500, "GetUserById", err)
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
{{range .Tokens}}
|
{{range .Tokens}}
|
||||||
<div class="item ui grid">
|
<div class="item ui grid">
|
||||||
<div class="one wide column">
|
<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>
|
||||||
<div class="one wide column">
|
<div class="one wide column">
|
||||||
<i class="fa fa-send fa-2x left"></i>
|
<i class="fa fa-send fa-2x left"></i>
|
||||||
|
|
Reference in a new issue