Browse Source

username password bug修复

main
pixelqm 5 years ago
parent
commit
176ff03324
  1. 6
      QMPlusServer/controller/api/user.go
  2. 8
      QMPlusServer/model/dbModel/user.go

6
QMPlusServer/controller/api/user.go

@ -39,7 +39,7 @@ func Regist(c *gin.Context) {
"user": user, "user": user,
}) })
} else { } else {
servers.ReportFormat(c, false, "创建成功", gin.H{
servers.ReportFormat(c, true, "创建成功", gin.H{
"user": user, "user": user,
}) })
} }
@ -74,7 +74,7 @@ func tokenNext(c *gin.Context, user dbModel.User) {
AuthorityId: user.AuthorityId, AuthorityId: user.AuthorityId,
StandardClaims: jwt.StandardClaims{ StandardClaims: jwt.StandardClaims{
NotBefore: int64(time.Now().Unix() - 1000), // 签名生效时间 NotBefore: int64(time.Now().Unix() - 1000), // 签名生效时间
ExpiresAt: int64(time.Now().Unix() + 3600*7), // 过期时间 一周
ExpiresAt: int64(time.Now().Unix() + 60*60*24*7), // 过期时间 一周
Issuer: "qmPlus", //签名的发行者 Issuer: "qmPlus", //签名的发行者
}, },
} }
@ -82,7 +82,7 @@ func tokenNext(c *gin.Context, user dbModel.User) {
if err != nil { if err != nil {
servers.ReportFormat(c, false, "获取token失败", gin.H{}) servers.ReportFormat(c, false, "获取token失败", gin.H{})
} else { } 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})
} }
} }

8
QMPlusServer/model/dbModel/user.go

@ -31,7 +31,7 @@ type User struct {
func (u *User) Regist() (err error, userInter *User) { func (u *User) Regist() (err error, userInter *User) {
var user 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表明读取到了 不能注册 //err为nil表明读取到了 不能注册
if findErr == nil { if findErr == nil {
return errors.New("用户名已注册"), nil return errors.New("用户名已注册"), nil
@ -49,7 +49,7 @@ func (u *User) ChangePassword(newPassword string) (err error, userInter *User) {
var user User var user User
//后期修改jwt+password模式 //后期修改jwt+password模式
u.Password = tools.MD5V(u.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 return err, u
} }
@ -63,7 +63,7 @@ func (u *User) UpdataUser() (err error, userInter *User) {
func (u *User) Login() (err error, userInter *User) { func (u *User) Login() (err error, userInter *User) {
var user User var user User
u.Password = tools.MD5V(u.Password) 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 err = qmsql.DEFAULTDB.Where("authority_id = ?", user.AuthorityId).First(&user.Authority).Error
return err, &user 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) { func (u *User) UploadHeaderImg(username string, filePath string) (err error, userInter *User) {
var user 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 return err, &user
} }

Loading…
Cancel
Save