models/token: generate bindata and simplify code (#5820)

pull/5827/head
Unknwon 2019-10-15 14:36:52 -07:00
parent ffbb0f6a60
commit a04de87584
No known key found for this signature in database
GPG Key ID: B43718D76E30A238
4 changed files with 243 additions and 245 deletions

View File

@ -16,7 +16,7 @@ import (
"github.com/gogs/gogs/pkg/setting" "github.com/gogs/gogs/pkg/setting"
) )
const Version = "0.11.94.1003" const Version = "0.11.95.1015"
func init() { func init() {
setting.AppVer = Version setting.AppVer = Version

View File

@ -5,7 +5,6 @@
package models package models
import ( import (
"fmt"
"time" "time"
"github.com/go-xorm/xorm" "github.com/go-xorm/xorm"
@ -48,16 +47,15 @@ func (t *AccessToken) AfterSet(colName string, _ xorm.Cell) {
} }
} }
func isAccessTokenNameExist(uid int64, name string) (bool, error) {
return x.Where("uid=?", uid).And("name=?", name).Get(&AccessToken{})
}
// NewAccessToken creates new access token. // NewAccessToken creates new access token.
func NewAccessToken(t *AccessToken) error { func NewAccessToken(t *AccessToken) error {
t.Sha1 = tool.SHA1(gouuid.NewV4().String()) t.Sha1 = tool.SHA1(gouuid.NewV4().String())
has, err := isAccessTokenNameExist(t.UID, t.Name) has, err := x.Get(&AccessToken{
UID: t.UID,
Name: t.Name,
})
if err != nil { if err != nil {
return fmt.Errorf("IsAccessTokenNameExists: %v", err) return err
} else if has { } else if has {
return errors.AccessTokenNameAlreadyExist{t.Name} return errors.AccessTokenNameAlreadyExist{t.Name}
} }

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
0.11.94.1003 0.11.95.1015