From 4b89e7d58973ce4b6fe57e5778bdd8c3dad87569 Mon Sep 17 00:00:00 2001 From: pixel <303176530@qq.com> Date: Sun, 15 Dec 2019 15:42:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E5=BD=95=E5=85=A5=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- QMPlusServer/controller/api/sys_user.go | 13 +++++++++++-- QMPlusServer/model/sysModel/sys_user.go | 3 +++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/QMPlusServer/controller/api/sys_user.go b/QMPlusServer/controller/api/sys_user.go index 29f98a37..56651fb0 100644 --- a/QMPlusServer/controller/api/sys_user.go +++ b/QMPlusServer/controller/api/sys_user.go @@ -23,6 +23,14 @@ type RegistAndLoginStuct struct { Password string `json:"password"` } +type RegestStuct struct { + Username string `json:"userName"` + Password string `json:"passWord"` + NickName string `json:"nickName" gorm:"default:'QMPlusUser'"` + HeaderImg string `json:"headerImg" gorm:"default:'http://www.henrongyi.top/avatar/lufu.jpg'"` + AuthorityId string `json:"authorityId" gorm:"default:888"` +} + // @Tags Base // @Summary 用户注册账号 // @Produce application/json @@ -30,9 +38,10 @@ type RegistAndLoginStuct struct { // @Success 200 {string} string "{"success":true,"data":{},"msg":"注册成功"}" // @Router /base/regist [post] func Regist(c *gin.Context) { - var R sysModel.SysUser + var R RegestStuct _ = c.BindJSON(&R) - err, user := R.Regist() + user := &sysModel.SysUser{Username:R.Username,NickName:R.NickName,Password:R.Password,HeaderImg:R.HeaderImg,AuthorityId:R.AuthorityId} + err, user := user.Regist() if err != nil { servers.ReportFormat(c, false, fmt.Sprintf("%v", err), gin.H{ "user": user, diff --git a/QMPlusServer/model/sysModel/sys_user.go b/QMPlusServer/model/sysModel/sys_user.go index 1278e075..d86b7d20 100644 --- a/QMPlusServer/model/sysModel/sys_user.go +++ b/QMPlusServer/model/sysModel/sys_user.go @@ -62,6 +62,9 @@ func (u *SysUser) Login() (err error, userInter *SysUser) { var user SysUser u.Password = tools.MD5V(u.Password) err = qmsql.DEFAULTDB.Where("username = ? AND password = ?", u.Username, u.Password).First(&user).Error + if(err!=nil){ + return err,&user + } err = qmsql.DEFAULTDB.Where("authority_id = ?", user.AuthorityId).First(&user.Authority).Error return err, &user }