作者 yangfu

auth.accessToken fix

... ... @@ -169,6 +169,9 @@ func CheckToken(ctx *context.Context) (result bool) {
var (
msg *protocol.ResponseMessage
)
if strings.HasSuffix(ctx.Request.RequestURI,"login"){
return true
}
result = true
defer func() {
if msg != nil {
... ...
... ... @@ -17,7 +17,7 @@ type Chance struct {
ChanceTypeId int `orm:"column(chance_type_id)" description:"表cfg_chance_type.id 机会类型 1:产品 2:渠道 3.客户 4.区域 5.其他 "`
Content string `orm:"column(content)" description:"内容"`
CommentTotal int `orm:"column(comment_total)" description:"评论总数"`
FavoriteTotal int `orm:"column(favorite_total)" description:"点赞总数"`
ZanTotal int `orm:"column(zan_total)" description:"点赞总数"`
ReviewStatus int8 `orm:"column(review_status)" description:"审核状态 0:待审核 1:被退回 2:已通过 3:草稿箱"`
EnableStatus int8 `orm:"column(enable_status)" description:"有效状态 0:无效 1:有效 "`
UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"`
... ...
... ... @@ -158,7 +158,7 @@ func DeleteUserAuth(id int) (err error) {
func GetUserByAuthCode(authCode string) (v *UserAuth, err error) {
o := orm.NewOrm()
sql := "select * from user_auth where auth_code=? and auth_exp >= Now()"
sql := "select * from user_auth where auth_code=? and auth_code_exp >= Now()"
if err = o.Raw(sql, authCode).QueryRow(&v); err == nil {
return v, nil
}
... ... @@ -167,7 +167,7 @@ func GetUserByAuthCode(authCode string) (v *UserAuth, err error) {
func GetUserAuthByRefreshToken(refreshToken string) (v *UserAuth, err error) {
o := orm.NewOrm()
sql := "select * from user_auth where refresh_token=? and auth_exp >= Now()" // TODO: and enabled = 1
sql := "select * from user_auth where refresh_token=? and refresh_token_exp >= Now()" // TODO: and enabled = 1
if err = o.Raw(sql, refreshToken).QueryRow(&v); err == nil {
return v, nil
}
... ... @@ -176,7 +176,7 @@ func GetUserAuthByRefreshToken(refreshToken string) (v *UserAuth, err error) {
func GetUserAuthByToken(refreshToken string) (v *UserAuth, err error) {
o := orm.NewOrm()
sql := "select * from user_auth where refresh_token=? and auth_exp >= Now()" // TODO: and enabled = 1
sql := "select * from user_auth where access_token=? and access_token_exp >= Now()" // TODO: and enabled = 1
if err = o.Raw(sql, refreshToken).QueryRow(&v); err == nil {
return v, nil
}
... ...
... ... @@ -117,7 +117,7 @@ Success:
if user.CsAccount == 0 {
user.CsAccount = imGetRandomCSAccount()
}
userAuth.AccessTokenExp = time.Now().Add(time.Second * protocol.TokenExpire)
userAuth.AuthCodeExp = time.Now().Add(time.Second * protocol.TokenExpire)
if err = repository.UserAuth.UpdateUserAuthById(userAuth); err != nil {
return
}
... ... @@ -149,6 +149,8 @@ func (s *AuthService) AccessToken(request *protocol.AccessTokenRequest) (rsp *pr
}
userAuth.AccessToken = uid.NewV1().StringNoDash()
userAuth.RefreshToken = uid.NewV1().StringNoDash()
userAuth.AccessTokenExp = time.Now().Add(protocol.TokenExpire*time.Second)
userAuth.RefreshTokenExp = time.Now().Add(protocol.TokenExpire*time.Second)
if err = repository.UserAuth.UpdateUserAuthById(userAuth); err != nil {
log.Error(err)
return
... ...