ziwen 1 year ago
parent
commit
ca367ae8b6
2 changed files with 42 additions and 23 deletions
  1. 39 20
      controller/auth.go
  2. 3 3
      models/english_report_email/email.go

+ 39 - 20
controller/auth.go

@@ -33,17 +33,37 @@ func (a *AuthController) Login(c *gin.Context) {
 		resp.Fail("邮箱或手机号错误", c)
 		return
 	}
+
+	emailItem := new(english_report_email.Email)
+	if req.Type == 1 {
+		userEmail, err := emailItem.GetByEmail(req.Account)
+		if err != nil && err != utils.ErrNoRow {
+			resp.Unregistered("账号未注册.", c)
+			return
+		}
+		if userEmail == nil {
+			resp.Unregistered("账号未注册", c)
+			return
+		}
+	} else {
+		userEmail, err := emailItem.GetByMobile(req.Account, req.CountryCode)
+		if err != nil && err != utils.ErrNoRow {
+			resp.FailData("获取客户邮箱信息失败 ", "Err:"+err.Error(), c)
+			return
+		}
+		if userEmail == nil {
+			resp.Unbound("手机号未绑定", c)
+			return
+		}
+	}
+
 	sysUser, err := english_report_email.CheckUserPwd(req.Type, req.CountryCode, req.Account, req.Password)
 	if err != nil {
 		resp.FailData("Login failed. Please check your entries and try again.", "Err:"+err.Error(), c)
 		return
 	}
 	if sysUser == nil {
-		if req.Type == 1 {
-			resp.Unregistered("账号未注册.", c)
-		} else {
-			resp.Unbound("手机号未绑定.", c)
-		}
+		resp.Fail("Login failed. Please check your entries and try again.", c)
 		return
 	}
 	if sysUser.Enable == 0 {
@@ -116,19 +136,18 @@ func (a *AuthController) Register(c *gin.Context) {
 		return
 	}
 	if emailItem != nil {
-		//if emailItem.Status == 1 {
-		//	//已经是正式用户,更新密码即可
-		//	emailItem.Password = req.Password
-		//	emailItem.ModifyTime = time.Now()
-		//
-		//	err = emailItem.Update([]string{"Password", "ModifyTime"})
-		//	if err != nil {
-		//		resp.FailMsg("修改密码失败", "修改密码失败,Err:"+err.Error(), c)
-		//		return
-		//	}
-		//	resp.Ok("注册成功", c)
-		//} else
-		if emailItem.Status == 2 || emailItem.Status == 1 {
+		if emailItem.Status == 1 && emailItem.Password == "" {
+			//已经是正式用户,更新密码即可
+			emailItem.Password = req.Password
+			emailItem.ModifyTime = time.Now()
+
+			err = emailItem.Update([]string{"Password", "ModifyTime"})
+			if err != nil {
+				resp.FailMsg("修改密码失败", "修改密码失败,Err:"+err.Error(), c)
+				return
+			}
+			resp.Ok("注册成功", c)
+		} else if emailItem.Status == 2 {
 			resp.Registered("邮箱已注册.", c)
 			return
 		} else if emailItem.Status == 3 {
@@ -411,7 +430,7 @@ func (a *AuthController) ForgetPwd(c *gin.Context) {
 			resp.FailData("获取客户邮箱信息失败 ", "Err:"+err.Error(), c)
 			return
 		}
-		if userEmail != nil {
+		if userEmail == nil {
 			resp.Unregistered("账号未注册", c)
 			return
 		}
@@ -421,7 +440,7 @@ func (a *AuthController) ForgetPwd(c *gin.Context) {
 			resp.FailData("获取客户邮箱信息失败 ", "Err:"+err.Error(), c)
 			return
 		}
-		if userEmail != nil {
+		if userEmail == nil {
 			resp.Unbound("手机号未绑定", c)
 			return
 		}

+ 3 - 3
models/english_report_email/email.go

@@ -57,17 +57,17 @@ func (e *Email) UpdateViewTotalById(Id uint) (err error) {
 func CheckUserPwd(loginType int, countryCode, account, password string) (item *Email, err error) {
 	sql := ``
 	if loginType == 1 {
-		sql = `SELECT * FROM english_report_email WHERE email=? AND password=?  `
+		sql = `SELECT * FROM english_report_email WHERE email=? AND password=? AND is_deleted = 0 `
 		err = global.MYSQL["rddp"].Raw(sql, account, password).Scan(&item).Error
 	} else {
-		sql = `SELECT * FROM english_report_email WHERE country_code = ? mobile=? AND password=?  `
+		sql = `SELECT * FROM english_report_email WHERE country_code = ? mobile=? AND password=?  AND is_deleted = 0 `
 		err = global.MYSQL["rddp"].Raw(sql, countryCode, account, password).Scan(&item).Error
 	}
 	return
 }
 
 func CheckUser(email string) (item *Email, err error) {
-	sql := `SELECT * FROM english_report_email WHERE email=?  `
+	sql := `SELECT * FROM english_report_email WHERE email=? AND is_deleted = 0 `
 	err = global.MYSQL["rddp"].Raw(sql, email).First(&item).Error
 	return
 }