|
@@ -41,6 +41,7 @@ func (this *UserCommonController) Login() {
|
|
|
br.ErrMsg = "参数解析失败,Err:" + err.Error()
|
|
|
return
|
|
|
}
|
|
|
+ resp := new(models.LoginResp)
|
|
|
mobile := req.Mobile
|
|
|
req.Mobile = strings.Trim(req.Mobile, " ")
|
|
|
if req.Mobile == "" {
|
|
@@ -48,31 +49,81 @@ func (this *UserCommonController) Login() {
|
|
|
br.ErrMsg = "参数错误,手机号为空"
|
|
|
return
|
|
|
}
|
|
|
- code := req.VCode
|
|
|
- if code == "" {
|
|
|
- br.Msg = "参数错误"
|
|
|
- br.ErrMsg = "Code 为空"
|
|
|
- return
|
|
|
- }
|
|
|
+
|
|
|
authorization := req.Token
|
|
|
inviteShareCode := req.InviteShareCode
|
|
|
|
|
|
- item, err := models.GetMsgCode(req.Mobile, req.VCode)
|
|
|
- if err != nil {
|
|
|
- if err.Error() == utils.ErrNoRow() {
|
|
|
- br.Msg = "验证码错误,请重新输入"
|
|
|
- br.ErrMsg = "校验验证码失败,Err:" + err.Error()
|
|
|
+ password := req.Password
|
|
|
+ loginType := req.LoginType
|
|
|
+ if !utils.ValidateMobileFormatat(mobile) {
|
|
|
+ br.Msg = "格式错误,请输入正确的手机号码。"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if loginType == "2" { // 单独处理密码登录
|
|
|
+ if password == "" {
|
|
|
+ br.Msg = "参数错误"
|
|
|
+ br.ErrMsg = "Password 为空"
|
|
|
return
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ userByps, err := models.GetWxUserItemByMobile(mobile)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "该账号不是专栏作者,请使用验证码登录。"
|
|
|
+ br.ErrMsg = "获取信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ specialAuthorCheck := services.GetYanxuanSpecialAuthorInfo(userByps) //用户是否没开通研选专栏以及,专栏信息是否完善
|
|
|
+ if !specialAuthorCheck.IsAuthor {
|
|
|
+ br.Msg = "该账号不是专栏作者,请使用验证码登录。"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //专栏作者,但是还没设置登录密码,弹窗提示如下:
|
|
|
+ isSetPassword := services.GetIsSetPassword(mobile)
|
|
|
+ if !isSetPassword {
|
|
|
+ resp.LoginErrCode = 1
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "获取成功"
|
|
|
+ br.Data = resp
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ total, err := models.GetCygxUserPasswordCountByMobileAdnPss(mobile, password)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取信息失败"
|
|
|
+ br.ErrMsg = "获取信息失败 GetCygxUserPasswordCountByMobileAdnPss err" + err.Error()
|
|
|
+ }
|
|
|
+ if total == 0 {
|
|
|
+ br.Msg = "密码错误,请重新输入"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ code := req.VCode
|
|
|
+ if code == "" {
|
|
|
+ br.Msg = "参数错误"
|
|
|
+ br.ErrMsg = "Code 为空"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ item, err := models.GetMsgCode(req.Mobile, req.VCode)
|
|
|
+ if err != nil {
|
|
|
+ if err.Error() == utils.ErrNoRow() {
|
|
|
+ br.Msg = "验证码错误,请重新输入"
|
|
|
+ br.ErrMsg = "校验验证码失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ br.Msg = "验证码错误,请重新输入"
|
|
|
+ br.ErrMsg = "校验验证码失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if item == nil {
|
|
|
br.Msg = "验证码错误,请重新输入"
|
|
|
- br.ErrMsg = "校验验证码失败,Err:" + err.Error()
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
- if item == nil {
|
|
|
- br.Msg = "验证码错误,请重新输入"
|
|
|
- return
|
|
|
- }
|
|
|
|
|
|
user, err := services.BindWxUser(mobile, "86", inviteShareCode)
|
|
|
//user, err := models.GetWxUserItemByMobile(mobile)
|
|
@@ -117,8 +168,8 @@ func (this *UserCommonController) Login() {
|
|
|
itemsSession.AccessToken = token
|
|
|
itemsSession.CreatedTime = time.Now()
|
|
|
itemsSession.LastUpdatedTime = time.Now()
|
|
|
- itemsSession.ExpireTime = time.Now().AddDate(0, 3, 0)
|
|
|
- err = models.AddCygxMfyxWebSession(itemsSession)
|
|
|
+ itemsSession.ExpireTime = time.Now().AddDate(0, 0, 30)
|
|
|
+ err = services.HandleCygxMfyxWebSession(itemsSession)
|
|
|
if err != nil {
|
|
|
br.Msg = "获取用户信息失败"
|
|
|
br.ErrMsg = "添加Token失败,Err:" + err.Error()
|
|
@@ -130,7 +181,6 @@ func (this *UserCommonController) Login() {
|
|
|
services.AddInviteCompany(user) //记录通过三方合作机构过来的公司
|
|
|
}
|
|
|
|
|
|
- resp := new(models.LoginResp)
|
|
|
resp.UserId = user.UserId
|
|
|
resp.Headimgurl = user.Headimgurl
|
|
|
resp.Mobile = user.Mobile
|
|
@@ -327,6 +377,7 @@ func (this *UserController) Detail() {
|
|
|
resp.SpecialColumnId = specialAuthorCheck.SpecialColumnId
|
|
|
resp.IsImproveInformation = specialAuthorCheck.IsImproveInformation
|
|
|
resp.HasPermission = hasPermission
|
|
|
+ resp.IsSetPassword = services.GetIsSetPassword(user.Mobile)
|
|
|
br.Ret = 200
|
|
|
br.Success = true
|
|
|
br.Msg = "获取成功"
|
|
@@ -1893,3 +1944,270 @@ func (this *UserController) EmailBinding() {
|
|
|
br.Success = true
|
|
|
br.Msg = "操作成功"
|
|
|
}
|
|
|
+
|
|
|
+// @Title 设置密码接口
|
|
|
+// @Description 设置密码接口
|
|
|
+// @Param request body models.SetUserPasswordReq true "type json string"
|
|
|
+// @Success 200 {object}
|
|
|
+// @router /set_pass [post]
|
|
|
+func (this *UserController) SetPass() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ this.Data["json"] = br
|
|
|
+ this.ServeJSON()
|
|
|
+ }()
|
|
|
+ user := this.User
|
|
|
+ if user == nil {
|
|
|
+ br.Msg = "请登录"
|
|
|
+ br.ErrMsg = "请登录,用户信息为空"
|
|
|
+ br.Ret = 408
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var req models.SetUserPasswordReq
|
|
|
+ err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "参数解析异常!"
|
|
|
+ br.ErrMsg = "参数解析失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ mobile := req.Mobile
|
|
|
+ mobile = strings.Trim(mobile, " ")
|
|
|
+ if mobile == "" {
|
|
|
+ br.Msg = "参数错误"
|
|
|
+ br.ErrMsg = "参数错误,手机号为空"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ code := req.VCode
|
|
|
+ if code == "" {
|
|
|
+ br.Msg = "参数错误"
|
|
|
+ br.ErrMsg = "Code 为空"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ password := req.Password
|
|
|
+ if password == "" {
|
|
|
+ br.Msg = "参数错误"
|
|
|
+ br.ErrMsg = "Password 为空"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if !utils.ValidateMobileFormatat(mobile) {
|
|
|
+ br.Msg = "格式错误,请输入正确的手机号码。"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ item, err := models.GetMsgCode(req.Mobile, req.VCode)
|
|
|
+ if err != nil {
|
|
|
+ if err.Error() == utils.ErrNoRow() {
|
|
|
+ br.Msg = "验证码错误,请重新输入"
|
|
|
+ br.ErrMsg = "校验验证码失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ br.Msg = "验证码错误,请重新输入"
|
|
|
+ br.ErrMsg = "校验验证码失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if item == nil {
|
|
|
+ br.Msg = "验证码错误,请重新输入"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ specialAuthorCheck := services.GetYanxuanSpecialAuthorInfo(user) //用户是否没开通研选专栏以及,专栏信息是否完善
|
|
|
+ if !specialAuthorCheck.IsAuthor {
|
|
|
+ br.Msg = "该账号不是专栏作者,请使用验证码登录。"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ isSetPassword := services.GetIsSetPassword(mobile)
|
|
|
+ if isSetPassword {
|
|
|
+ err = models.UpdateCygxUserPassword(mobile, password)
|
|
|
+ } else {
|
|
|
+ itemps := new(models.CygxUserPassword)
|
|
|
+ itemps.UserId = user.UserId
|
|
|
+ itemps.Mobile = mobile
|
|
|
+ itemps.RealName = user.RealName
|
|
|
+ itemps.Password = password
|
|
|
+ itemps.CreateTime = time.Now()
|
|
|
+ itemps.ModifyTime = time.Now()
|
|
|
+ err = models.AddCygxUserPassword(itemps)
|
|
|
+ }
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "设置失败"
|
|
|
+ br.ErrMsg = "设置失败 err" + err.Error()
|
|
|
+ }
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "操作成功"
|
|
|
+}
|
|
|
+
|
|
|
+// @Title 修改密码接口
|
|
|
+// @Description 修改密码接口
|
|
|
+// @Param request body models.UpdateUserPasswordReq true "type json string"
|
|
|
+// @Success 200 {object}
|
|
|
+// @router /update_pass [post]
|
|
|
+func (this *UserController) UpdatePass() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ this.Data["json"] = br
|
|
|
+ this.ServeJSON()
|
|
|
+ }()
|
|
|
+ user := this.User
|
|
|
+ if user == nil {
|
|
|
+ br.Msg = "请登录"
|
|
|
+ br.ErrMsg = "请登录,用户信息为空"
|
|
|
+ br.Ret = 408
|
|
|
+ return
|
|
|
+ }
|
|
|
+ mobile := user.Mobile
|
|
|
+ var req models.UpdateUserPasswordReq
|
|
|
+ err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "参数解析异常!"
|
|
|
+ br.ErrMsg = "参数解析失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ oldPassword := req.OldPassword
|
|
|
+ newPassword := req.NewPassword
|
|
|
+ if !utils.ValidateMobileFormatat(mobile) {
|
|
|
+ br.Msg = "格式错误,请输入正确的手机号码。"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ total, err := models.GetCygxUserPasswordCountByMobileAdnPss(mobile, oldPassword)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "设置失败"
|
|
|
+ br.ErrMsg = "设置失败 err" + err.Error()
|
|
|
+ }
|
|
|
+ if total == 0 {
|
|
|
+ br.Msg = "原密码错误"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ specialAuthorCheck := services.GetYanxuanSpecialAuthorInfo(user) //用户是否没开通研选专栏以及,专栏信息是否完善
|
|
|
+ if !specialAuthorCheck.IsAuthor {
|
|
|
+ br.Msg = "非专栏作者无法设置登录密码"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = models.UpdateCygxUserPassword(mobile, newPassword)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "设置失败"
|
|
|
+ br.ErrMsg = "设置失败 err" + err.Error()
|
|
|
+ }
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "操作成功"
|
|
|
+}
|
|
|
+
|
|
|
+// @Title 重置密码接口(忘记密码)
|
|
|
+// @Description 设置密码接口
|
|
|
+// @Param request body models.SetUserPasswordReq true "type json string"
|
|
|
+// @Success 200 {object} models.LoginResp
|
|
|
+// @router /reset_pass [post]
|
|
|
+func (this *UserCommonController) ReSetPass() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ this.Data["json"] = br
|
|
|
+ this.ServeJSON()
|
|
|
+ }()
|
|
|
+ var req models.SetUserPasswordReq
|
|
|
+ err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "参数解析异常!"
|
|
|
+ br.ErrMsg = "参数解析失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ mobile := req.Mobile
|
|
|
+ mobile = strings.Trim(mobile, " ")
|
|
|
+ if mobile == "" {
|
|
|
+ br.Msg = "参数错误"
|
|
|
+ br.ErrMsg = "参数错误,手机号为空"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ code := req.VCode
|
|
|
+ if code == "" {
|
|
|
+ br.Msg = "参数错误"
|
|
|
+ br.ErrMsg = "Code 为空"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ password := req.Password
|
|
|
+ if password == "" {
|
|
|
+ br.Msg = "参数错误"
|
|
|
+ br.ErrMsg = "Password 为空"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if !utils.ValidateMobileFormatat(mobile) {
|
|
|
+ br.Msg = "格式错误,请输入正确的手机号码。"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ item, err := models.GetMsgCode(req.Mobile, req.VCode)
|
|
|
+ if err != nil {
|
|
|
+ if err.Error() == utils.ErrNoRow() {
|
|
|
+ br.Msg = "验证码错误,请重新输入"
|
|
|
+ br.ErrMsg = "校验验证码失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ br.Msg = "验证码错误,请重新输入"
|
|
|
+ br.ErrMsg = "校验验证码失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if item == nil {
|
|
|
+ br.Msg = "验证码错误,请重新输入"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ user, err := models.GetWxUserItemByMobile(mobile)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "该账号不是专栏作者,请使用验证码登录。"
|
|
|
+ br.ErrMsg = "获取信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ specialAuthorCheck := services.GetYanxuanSpecialAuthorInfo(user) //用户是否没开通研选专栏以及,专栏信息是否完善
|
|
|
+ if !specialAuthorCheck.IsAuthor {
|
|
|
+ br.Msg = "该账号不是专栏作者,请使用验证码登录。"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ isSetPassword := services.GetIsSetPassword(mobile)
|
|
|
+ if isSetPassword {
|
|
|
+ err = models.UpdateCygxUserPassword(mobile, password)
|
|
|
+ } else {
|
|
|
+ itemps := new(models.CygxUserPassword)
|
|
|
+ itemps.UserId = user.UserId
|
|
|
+ itemps.Mobile = mobile
|
|
|
+ itemps.RealName = user.RealName
|
|
|
+ itemps.Password = password
|
|
|
+ itemps.CreateTime = time.Now()
|
|
|
+ itemps.ModifyTime = time.Now()
|
|
|
+ err = models.AddCygxUserPassword(itemps)
|
|
|
+ }
|
|
|
+ var token string
|
|
|
+ timeUnix := time.Now().Unix()
|
|
|
+ timeUnixStr := strconv.FormatInt(timeUnix, 10)
|
|
|
+ token = utils.MD5(mobile) + utils.MD5(timeUnixStr)
|
|
|
+ itemsSession := new(models.CygxMfyxWebSession)
|
|
|
+ itemsSession.UserId = user.UserId
|
|
|
+ itemsSession.Mobile = mobile
|
|
|
+ itemsSession.AccessToken = token
|
|
|
+ itemsSession.CreatedTime = time.Now()
|
|
|
+ itemsSession.LastUpdatedTime = time.Now()
|
|
|
+ itemsSession.ExpireTime = time.Now().AddDate(0, 0, 30)
|
|
|
+ err = services.HandleCygxMfyxWebSession(itemsSession)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取用户信息失败"
|
|
|
+ br.ErrMsg = "添加Token失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ resp := new(models.LoginResp)
|
|
|
+ resp.UserId = user.UserId
|
|
|
+ resp.Headimgurl = user.Headimgurl
|
|
|
+ resp.Mobile = user.Mobile
|
|
|
+ resp.Email = user.Email
|
|
|
+ resp.CompanyName = user.CompanyName
|
|
|
+ resp.Authorization = token
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "获取成功"
|
|
|
+ br.Data = resp
|
|
|
+}
|