From 176ff03324cc98266b843141e79157d30f791f9e Mon Sep 17 00:00:00 2001 From: pixelqm <303176530@qq.com> Date: Sat, 14 Sep 2019 22:30:28 +0800 Subject: [PATCH] =?UTF-8?q?username=20password=20bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- QMPlusServer/controller/api/user.go | 10 +++++----- QMPlusServer/model/dbModel/user.go | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/QMPlusServer/controller/api/user.go b/QMPlusServer/controller/api/user.go index 835fa370..b1e27fa5 100644 --- a/QMPlusServer/controller/api/user.go +++ b/QMPlusServer/controller/api/user.go @@ -39,7 +39,7 @@ func Regist(c *gin.Context) { "user": user, }) } else { - servers.ReportFormat(c, false, "创建成功", gin.H{ + servers.ReportFormat(c, true, "创建成功", gin.H{ "user": user, }) } @@ -73,16 +73,16 @@ func tokenNext(c *gin.Context, user dbModel.User) { NickName: user.NickName, AuthorityId: user.AuthorityId, StandardClaims: jwt.StandardClaims{ - NotBefore: int64(time.Now().Unix() - 1000), // 签名生效时间 - ExpiresAt: int64(time.Now().Unix() + 3600*7), // 过期时间 一周 - Issuer: "qmPlus", //签名的发行者 + NotBefore: int64(time.Now().Unix() - 1000), // 签名生效时间 + ExpiresAt: int64(time.Now().Unix() + 60*60*24*7), // 过期时间 一周 + Issuer: "qmPlus", //签名的发行者 }, } token, err := j.CreateToken(clams) if err != nil { servers.ReportFormat(c, false, "获取token失败", gin.H{}) } else { - servers.ReportFormat(c, true, "登录成功", gin.H{"user": user, "token": token}) + servers.ReportFormat(c, true, "登录成功", gin.H{"user": user, "token": token, "expiresAt": clams.StandardClaims.ExpiresAt * 1000}) } } diff --git a/QMPlusServer/model/dbModel/user.go b/QMPlusServer/model/dbModel/user.go index e61f0e2e..c73aa4a5 100644 --- a/QMPlusServer/model/dbModel/user.go +++ b/QMPlusServer/model/dbModel/user.go @@ -31,7 +31,7 @@ type User struct { func (u *User) Regist() (err error, userInter *User) { var user User //判断用户名是否注册 - findErr := qmsql.DEFAULTDB.Where("user_name = ?", u.Username).First(&user).Error + findErr := qmsql.DEFAULTDB.Where("username = ?", u.Username).First(&user).Error //err为nil表明读取到了 不能注册 if findErr == nil { return errors.New("用户名已注册"), nil @@ -49,7 +49,7 @@ func (u *User) ChangePassword(newPassword string) (err error, userInter *User) { var user User //后期修改jwt+password模式 u.Password = tools.MD5V(u.Password) - err = qmsql.DEFAULTDB.Where("user_name = ? AND pass_word = ?", u.Username, u.Password).First(&user).Update("pass_word", tools.MD5V(newPassword)).Error + err = qmsql.DEFAULTDB.Where("username = ? AND password = ?", u.Username, u.Password).First(&user).Update("password", tools.MD5V(newPassword)).Error return err, u } @@ -63,7 +63,7 @@ func (u *User) UpdataUser() (err error, userInter *User) { func (u *User) Login() (err error, userInter *User) { var user User u.Password = tools.MD5V(u.Password) - err = qmsql.DEFAULTDB.Where("user_name = ? AND pass_word = ?", u.Username, u.Password).First(&user).Error + err = qmsql.DEFAULTDB.Where("username = ? AND password = ?", u.Username, u.Password).First(&user).Error err = qmsql.DEFAULTDB.Where("authority_id = ?", user.AuthorityId).First(&user.Authority).Error return err, &user } @@ -71,7 +71,7 @@ func (u *User) Login() (err error, userInter *User) { // 用户头像上传更新地址 func (u *User) UploadHeaderImg(username string, filePath string) (err error, userInter *User) { var user User - err = qmsql.DEFAULTDB.Where("user_name = ?", username).First(&user).Update("header_img", filePath).First(&user).Error + err = qmsql.DEFAULTDB.Where("username = ?", username).First(&user).Update("header_img", filePath).First(&user).Error return err, &user }