ziwen 1 year ago
parent
commit
83c4c715de
2 changed files with 42 additions and 4 deletions
  1. 35 3
      controller/auth.go
  2. 7 1
      models/english_report_email/email.go

+ 35 - 3
controller/auth.go

@@ -33,19 +33,23 @@ func (a *AuthController) Login(c *gin.Context) {
 		resp.Fail("邮箱或手机号错误", c)
 		return
 	}
-	sysUser, err := english_report_email.CheckUser(req.Type, req.Account, req.Password)
+	sysUser, err := english_report_email.CheckUserPwd(req.Type, req.Account, req.Password)
 	if err != nil {
-		resp.FailData("登录失败,账号或密码错误", "Err:"+err.Error(), c)
+		resp.FailData("Login failed. Please check your entries and try again.", "Err:"+err.Error(), c)
 		return
 	}
 	if sysUser == nil {
-		resp.FailData("登录失败,账号或密码错误", "Err:"+err.Error(), c)
+		resp.FailData("Login failed. Please check your entries and try again.", "Err:"+err.Error(), c)
 		return
 	}
 	if sysUser.Enable == 0 {
 		resp.FailData("您的账号已被禁用,如需登录,请联系管理员", "Err:"+err.Error(), c)
 		return
 	}
+	if sysUser.Status == 3 {
+		resp.FailData("Your trial has ended</br>Enjoyed your experience with us?</br>Contact us at stephanie@hzinsights.com to extend your trial.", "Err:"+err.Error(), c)
+		return
+	}
 	account := utils.MD5(req.Account)
 	token, err := utils.GenToken(account)
 	sysSession := new(session.EnglishYbSession)
@@ -94,12 +98,40 @@ func (a *AuthController) Register(c *gin.Context) {
 		return
 	}
 
+	emailItem, err := english_report_email.CheckUser(req.Email)
+	if err != nil && err != utils.ErrNoRow{
+		resp.Fail("验证码错误,请重新输入", c)
+		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{
+			resp.Fail("There is already a user account associated with this email address. Please log in instead.", c)
+			return
+		} else if emailItem.Status == 3 {
+			resp.Fail("Your trial has ended</br>Enjoyed your experience with us?</br>Contact us at stephanie@hzinsights.com to extend your trial.", c)
+			return
+		}
+	}
+
+	//状态为临时
 	user := english_report_email.Email{
 		Name:        req.Name,
 		CompanyName: req.CompanyName,
 		Email:       req.Email,
 		Password:    req.Password,
 		Enable:      1,
+		Status:      2,
 	}
 	user.Set()
 

+ 7 - 1
models/english_report_email/email.go

@@ -53,7 +53,7 @@ func (e *Email) UpdateViewTotalById(Id uint) (err error) {
 	return
 }
 
-func CheckUser(loginType int, account, password string) (item *Email, err error) {
+func CheckUserPwd(loginType int, account, password string) (item *Email, err error) {
 	sql := ``
 	if loginType == 1 {
 		sql = `SELECT * FROM english_report_email WHERE email=? AND password=?  `
@@ -63,3 +63,9 @@ func CheckUser(loginType int, account, password string) (item *Email, err error)
 	err = global.MYSQL["rddp"].Exec(sql, account, password).First(&item).Error
 	return
 }
+
+func CheckUser(email string) (item *Email, err error) {
+	sql := `SELECT * FROM english_report_email WHERE email=?  `
+	err = global.MYSQL["rddp"].Exec(sql, email).First(&item).Error
+	return
+}