Skip to content

Commit

Permalink
Merge pull request #43 from NJUPT-SAST/dev-windpo
Browse files Browse the repository at this point in the history
fix: Unified modification of token type
  • Loading branch information
windpo authored Sep 24, 2023
2 parents 405e3c6 + c7ec109 commit acbee94
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions api/v1/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func OauthUserInfo(c *gin.Context) {
}

c.JSON(http.StatusOK, result.Success(gin.H{
"email": user.Email,
"email": user.Email,
"userId": user.Uid,
}))
}
Expand Down Expand Up @@ -260,7 +260,7 @@ func userAuthorizeHandler(w http.ResponseWriter, r *http.Request) (userID string
return
}

username, err := util.GetUsername(token, model.LOGIN_SUB)
username, err := util.GetUsername(token, model.LOGIN_TOKEN_SUB)
if err != nil || username == "" {
if r.Form == nil {
_ = r.ParseForm()
Expand Down
4 changes: 2 additions & 2 deletions api/v1/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func Login(ctx *gin.Context) {
func ChangePassword(ctx *gin.Context) {
// Get username from token
token := ctx.GetHeader("TOKEN")
username, err := util.GetUsername(token, model.LOGIN_SUB)
username, err := util.GetUsername(token, model.LOGIN_TOKEN_SUB)
if err != nil || username == "" {
ctx.JSON(http.StatusBadRequest, result.Failed(result.TicketNotCorrect))
return
Expand Down Expand Up @@ -306,7 +306,7 @@ func Logout(ctx *gin.Context) {
return
}
//remove Token from username
username, err := util.GetUsername(token, model.LOGIN_SUB)
username, err := util.GetUsername(token, model.LOGIN_TOKEN_SUB)
if err != nil || username == "" {
ctx.JSON(http.StatusOK, result.TicketNotCorrect)
return
Expand Down
8 changes: 4 additions & 4 deletions model/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ const (
LOGIN_TOKEN_EXP = time.Hour * 24 * 7
// Login token key in redis
LOGIN_TOKEN_IN_REDIS = "LOGIN"
LOGIN_SUB = "login"
LOGIN_TOKEN_SUB = "loginToken"
LOGIN_TICKET_SUB = "loginTicket"
RESETPWD_TICKET_SUB = "resetPwd"
REGIST_TICKET_SUB = "register"
REGIST_TICKET_SUB = "registerTicket"
RESETPWD_TICKET_SUB = "resetPwdTicket"
)

var (
Expand Down Expand Up @@ -50,7 +50,7 @@ func LoginTicketJWTSubKey(username string) string {
}

func LoginJWTSubKey(username string) string {
return fmt.Sprintf("%s-%s", username, LOGIN_SUB)
return fmt.Sprintf("%s-%s", username, LOGIN_TOKEN_SUB)
}

func LoginTokenKey(username string) string {
Expand Down
2 changes: 1 addition & 1 deletion service/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func ResetPassword(username, newPassword string) error {
func UserInfo(ctx *gin.Context) (*model.User, error) {
token := ctx.GetHeader("TOKEN")
nilUser := &model.User{}
username, err := util.GetUsername(token, model.LOGIN_SUB)
username, err := util.GetUsername(token, model.LOGIN_TOKEN_SUB)
if err != nil {
return nilUser, err
}
Expand Down

0 comments on commit acbee94

Please sign in to comment.