diff --git a/QMPlusServer/config/config.go b/QMPlusServer/config/config.go index 0a21b08c..e0607ab4 100644 --- a/QMPlusServer/config/config.go +++ b/QMPlusServer/config/config.go @@ -10,7 +10,7 @@ type Config struct { Admin Admin } type Admin struct { - UserName string + Username string Password string Path string Dbname string diff --git a/QMPlusServer/config/dbconfig/config.json b/QMPlusServer/config/dbconfig/config.json index 86082d37..72860b6a 100644 --- a/QMPlusServer/config/dbconfig/config.json +++ b/QMPlusServer/config/dbconfig/config.json @@ -1,6 +1,6 @@ { "admin": { - "userName": "root", + "username": "root", "password": "Aa@6447985", "path": "127.0.0.1:3306", "dbname": "QMPlus", diff --git a/QMPlusServer/controller/api/user.go b/QMPlusServer/controller/api/user.go index e49c1a71..835fa370 100644 --- a/QMPlusServer/controller/api/user.go +++ b/QMPlusServer/controller/api/user.go @@ -18,8 +18,8 @@ var ( ) type RegistAndLoginStuct struct { - UserName string `json:"userName"` - PassWord string `json:"passWord"` + Username string `json:"username"` + Password string `json:"password"` } // @Tags Base @@ -32,7 +32,7 @@ func Regist(c *gin.Context) { var R RegistAndLoginStuct _ = c.BindJSON(&R) - U := &dbModel.User{UserName: R.UserName, PassWord: R.PassWord} + U := &dbModel.User{Username: R.Username, Password: R.Password} err, user := U.Regist() if err != nil { servers.ReportFormat(c, false, fmt.Sprintf("%v", err), gin.H{ @@ -54,9 +54,9 @@ func Regist(c *gin.Context) { func Login(c *gin.Context) { var L RegistAndLoginStuct _ = c.BindJSON(&L) - U := &dbModel.User{UserName: L.UserName, PassWord: L.PassWord} + U := &dbModel.User{Username: L.Username, Password: L.Password} if err, user := U.Login(); err != nil { - servers.ReportFormat(c, false, fmt.Sprintf("用户名密码错误或%v", err), gin.H{"user": user}) + servers.ReportFormat(c, false, fmt.Sprintf("用户名密码错误或%v", err), gin.H{}) } else { tokenNext(c, *user) } @@ -86,24 +86,24 @@ func tokenNext(c *gin.Context, user dbModel.User) { } } -type ChangePassWordStutrc struct { - UserName string `json:"userName"` - PassWord string `json:"passWord"` - NewPassWord string `json:"newPassWord"` +type ChangePasswordStutrc struct { + Username string `json:"username"` + Password string `json:"password"` + NewPassword string `json:"newPassword"` } // @Tags User // @Summary 用户修改密码 // @Security ApiKeyAuth // @Produce application/json -// @Param data body api.ChangePassWordStutrc true "用户修改密码" +// @Param data body api.ChangePasswordStutrc true "用户修改密码" // @Success 200 {string} json "{"success":true,"data":{},"msg":"修改成功"}" -// @Router /user/changePassWord [post] -func ChangePassWord(c *gin.Context) { - var params ChangePassWordStutrc +// @Router /user/changePassword [post] +func ChangePassword(c *gin.Context) { + var params ChangePasswordStutrc _ = c.BindJSON(¶ms) - U := &dbModel.User{UserName: params.UserName, PassWord: params.PassWord} - if err, _ := U.ChangePassWord(params.NewPassWord); err != nil { + U := &dbModel.User{Username: params.Username, Password: params.Password} + if err, _ := U.ChangePassword(params.NewPassword); err != nil { servers.ReportFormat(c, false, "修改失败,请检查用户名密码", gin.H{}) } else { servers.ReportFormat(c, true, "修改成功", gin.H{}) @@ -120,7 +120,7 @@ type UserHeaderImg struct { // @accept multipart/form-data // @Produce application/json // @Param headerImg formData file true "用户上传头像" -// @Param userName formData string true "用户上传头像" +// @Param username formData string true "用户上传头像" // @Success 200 {string} json "{"success":true,"data":{},"msg":"上传成功"}" // @Router /user/uploadHeaderImg [post] func UploadHeaderImg(c *gin.Context) { @@ -131,7 +131,7 @@ func UploadHeaderImg(c *gin.Context) { fmt.Println(waitUse.NickName) _, header, err := c.Request.FormFile("headerImg") //便于找到用户 以后从jwt中取 - userName := c.PostForm("userName") + username := c.PostForm("username") if err != nil { servers.ReportFormat(c, false, fmt.Sprintf("上传文件失败,%v", err), gin.H{}) } else { @@ -141,7 +141,7 @@ func UploadHeaderImg(c *gin.Context) { servers.ReportFormat(c, false, fmt.Sprintf("接收返回值失败,%v", err), gin.H{}) } else { //修改数据库后得到修改后的user并且返回供前端使用 - err, user := new(dbModel.User).UploadHeaderImg(userName, filePath) + err, user := new(dbModel.User).UploadHeaderImg(username, filePath) if err != nil { servers.ReportFormat(c, false, fmt.Sprintf("修改数据库链接失败,%v", err), gin.H{}) diff --git a/QMPlusServer/docs/docs.go b/QMPlusServer/docs/docs.go index 2078f254..cc0fa4c9 100644 --- a/QMPlusServer/docs/docs.go +++ b/QMPlusServer/docs/docs.go @@ -244,7 +244,7 @@ var doc = `{ } } }, - "/user/changePassWord": { + "/user/changePassword": { "post": { "security": [ { @@ -266,7 +266,7 @@ var doc = `{ "required": true, "schema": { "type": "object", - "$ref": "#/definitions/api.ChangePassWordStutrc" + "$ref": "#/definitions/api.ChangePasswordStutrc" } } ], @@ -347,7 +347,7 @@ var doc = `{ { "type": "string", "description": "用户上传头像", - "name": "userName", + "name": "username", "in": "formData", "required": true } @@ -364,16 +364,16 @@ var doc = `{ } }, "definitions": { - "api.ChangePassWordStutrc": { + "api.ChangePasswordStutrc": { "type": "object", "properties": { - "newPassWord": { + "newPassword": { "type": "string" }, - "passWord": { + "password": { "type": "string" }, - "userName": { + "username": { "type": "string" } } @@ -414,10 +414,10 @@ var doc = `{ "api.RegistAndLoginStuct": { "type": "object", "properties": { - "passWord": { + "password": { "type": "string" }, - "userName": { + "username": { "type": "string" } } diff --git a/QMPlusServer/docs/swagger.json b/QMPlusServer/docs/swagger.json index b8d8acff..0b0d627c 100644 --- a/QMPlusServer/docs/swagger.json +++ b/QMPlusServer/docs/swagger.json @@ -227,7 +227,7 @@ } } }, - "/user/changePassWord": { + "/user/changePassword": { "post": { "security": [ { @@ -249,7 +249,7 @@ "required": true, "schema": { "type": "object", - "$ref": "#/definitions/api.ChangePassWordStutrc" + "$ref": "#/definitions/api.ChangePasswordStutrc" } } ], @@ -330,7 +330,7 @@ { "type": "string", "description": "用户上传头像", - "name": "userName", + "name": "username", "in": "formData", "required": true } @@ -347,16 +347,16 @@ } }, "definitions": { - "api.ChangePassWordStutrc": { + "api.ChangePasswordStutrc": { "type": "object", "properties": { - "newPassWord": { + "newPassword": { "type": "string" }, - "passWord": { + "password": { "type": "string" }, - "userName": { + "username": { "type": "string" } } @@ -397,10 +397,10 @@ "api.RegistAndLoginStuct": { "type": "object", "properties": { - "passWord": { + "password": { "type": "string" }, - "userName": { + "username": { "type": "string" } } diff --git a/QMPlusServer/docs/swagger.yaml b/QMPlusServer/docs/swagger.yaml index ff17ba4e..c24a745b 100644 --- a/QMPlusServer/docs/swagger.yaml +++ b/QMPlusServer/docs/swagger.yaml @@ -1,12 +1,12 @@ basePath: / definitions: - api.ChangePassWordStutrc: + api.ChangePasswordStutrc: properties: - newPassWord: + newPassword: type: string - passWord: + password: type: string - userName: + username: type: string type: object api.CreateApiParams: @@ -32,9 +32,9 @@ definitions: type: object api.RegistAndLoginStuct: properties: - passWord: + password: type: string - userName: + username: type: string type: object modelInterface.PageInfo: @@ -187,7 +187,7 @@ paths: summary: 用户注册账号 tags: - Base - /user/changePassWord: + /user/changePassword: post: parameters: - description: 用户修改密码 @@ -195,7 +195,7 @@ paths: name: data required: true schema: - $ref: '#/definitions/api.ChangePassWordStutrc' + $ref: '#/definitions/api.ChangePasswordStutrc' type: object produces: - application/json @@ -245,7 +245,7 @@ paths: type: file - description: 用户上传头像 in: formData - name: userName + name: username required: true type: string produces: diff --git a/QMPlusServer/init/qmsql/initMysql.go b/QMPlusServer/init/qmsql/initMysql.go index 05d85feb..e4addc30 100644 --- a/QMPlusServer/init/qmsql/initMysql.go +++ b/QMPlusServer/init/qmsql/initMysql.go @@ -11,7 +11,7 @@ var DEFAULTDB *gorm.DB //初始化数据库并产生数据库全局变量 func InitMysql(admin config.Admin) *gorm.DB { - if db, err := gorm.Open("mysql", admin.UserName+":"+admin.Password+"@("+admin.Path+")/"+admin.Dbname+"?"+admin.Config); err != nil { + if db, err := gorm.Open("mysql", admin.Username+":"+admin.Password+"@("+admin.Path+")/"+admin.Dbname+"?"+admin.Config); err != nil { log.Printf("DEFAULTDB数据库启动异常%S", err) } else { DEFAULTDB = db diff --git a/QMPlusServer/model/dbModel/user.go b/QMPlusServer/model/dbModel/user.go index 37d80a82..e61f0e2e 100644 --- a/QMPlusServer/model/dbModel/user.go +++ b/QMPlusServer/model/dbModel/user.go @@ -13,8 +13,8 @@ import ( type User struct { gorm.Model `json:"-"` UUID uuid.UUID `json:"uuid"` - UserName string `json:"userName"` - PassWord string `json:"passWord"` + Username string `json:"-"` + Password string `json:"-"` NickName string `json:"nickName" gorm:"default:'QMPlusUser'"` HeaderImg string `json:"headerImg" gorm:"default:'http://www.henrongyi.top/avatar/lufu.jpg'"` Authority Authority `json:"authority" form:"ForeignKey:authority_id;AssociationForeignKey:authority_id"` @@ -31,13 +31,13 @@ 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("user_name = ?", u.Username).First(&user).Error //err为nil表明读取到了 不能注册 if findErr == nil { return errors.New("用户名已注册"), nil } else { // 否则 附加uuid 密码md5简单加密 注册 - u.PassWord = tools.MD5V(u.PassWord) + u.Password = tools.MD5V(u.Password) u.UUID = uuid.NewV4() err = qmsql.DEFAULTDB.Create(u).Error } @@ -45,11 +45,11 @@ func (u *User) Regist() (err error, userInter *User) { } //修改用户密码 -func (u *User) ChangePassWord(newPassWord string) (err error, userInter *User) { +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 + 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 return err, u } @@ -62,16 +62,16 @@ 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 + 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("authority_id = ?", user.AuthorityId).First(&user.Authority).Error return err, &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 - err = qmsql.DEFAULTDB.Where("user_name = ?", userName).First(&user).Update("header_img", filePath).First(&user).Error + err = qmsql.DEFAULTDB.Where("user_name = ?", username).First(&user).Update("header_img", filePath).First(&user).Error return err, &user } diff --git a/QMPlusServer/router/user.go b/QMPlusServer/router/user.go index d1c5c23c..1cce93e6 100644 --- a/QMPlusServer/router/user.go +++ b/QMPlusServer/router/user.go @@ -9,7 +9,7 @@ import ( func InitUserRouter(Router *gin.Engine) { UserRouter := Router.Group("user").Use(middleware.JWTAuth()) { - UserRouter.POST("changePassWord", api.ChangePassWord) + UserRouter.POST("changePassword", api.ChangePassword) UserRouter.POST("uploadHeaderImg", api.UploadHeaderImg) UserRouter.POST("getInfoList", api.GetInfoList) } diff --git a/QMPlusVuePage/src/store/module/user.js b/QMPlusVuePage/src/store/module/user.js index 55586827..a482a40e 100644 --- a/QMPlusVuePage/src/store/module/user.js +++ b/QMPlusVuePage/src/store/module/user.js @@ -1,9 +1,13 @@ +import { login } from '@/api/user' + export const user = { namespaced: true, state: { userInfo: { uuid: "", - nickName: "" + nickName: "", + headerImg: "", + authority: "", }, token: "" }, @@ -18,13 +22,20 @@ export const user = { } }, actions: { - // AsyncSetUserInfo({ commit }, loginInfo) { - - // } + LoginIn({ commit }, loginInfo) { + login(loginInfo).then(res => { + commit('setUserInfo', res.data.user) + commit('setToken', res.data.token) + return res + }).catch(err => { + console.error(err) + return Promise.reject(err) + }) + } }, getters: { - userName(state) { - return state.userName + userInfo(state) { + return state.userInfo } } } \ No newline at end of file