Browse Source

修复登录不跳转最后一次登录的平台的 bug

庄逸洲 5 years ago
parent
commit
67343ed9a7
3 changed files with 17 additions and 8 deletions
  1. 3 3
      conf/app.conf
  2. 7 4
      controllers/login_controller.go
  3. 7 1
      service/login_service.go

+ 3 - 3
conf/app.conf View File

1
 appname = 酷医
1
 appname = 酷医
2
 httpport = 8091
2
 httpport = 8091
3
-runmode = prod
3
+runmode = dev
4
 copyrequestbody = true
4
 copyrequestbody = true
5
 
5
 
6
 is_sso_use_session_id_key = true
6
 is_sso_use_session_id_key = true
101
 readmysqlport = 3306
101
 readmysqlport = 3306
102
 readmysqluser = root
102
 readmysqluser = root
103
 readmysqlpass = 1Q2W3e4r!@#$
103
 readmysqlpass = 1Q2W3e4r!@#$
104
-readmysqlname = sgj_xt
104
+readmysqlname = sgj_patient
105
 
105
 
106
 writemysqlhost = rm-wz9rg531npf61q03tro.mysql.rds.aliyuncs.com
106
 writemysqlhost = rm-wz9rg531npf61q03tro.mysql.rds.aliyuncs.com
107
 writemysqlport = 3306
107
 writemysqlport = 3306
108
 writemysqluser = root
108
 writemysqluser = root
109
 writemysqlpass = 1Q2W3e4r!@#$
109
 writemysqlpass = 1Q2W3e4r!@#$
110
-writemysqlname = sgj_xt
110
+writemysqlname = sgj_patient
111
 
111
 
112
 readuserhost = rm-wz9rg531npf61q03tro.mysql.rds.aliyuncs.com
112
 readuserhost = rm-wz9rg531npf61q03tro.mysql.rds.aliyuncs.com
113
 readuserport = 3306
113
 readuserport = 3306

+ 7 - 4
controllers/login_controller.go View File

31
 	}
31
 	}
32
 
32
 
33
 	if url := service.GetAppURLWithAppType(appType); len(url) == 0 {
33
 	if url := service.GetAppURLWithAppType(appType); len(url) == 0 {
34
-		appType = 1
34
+		appType = 0
35
 		returnURL = ""
35
 		returnURL = ""
36
 	}
36
 	}
37
 	utils.TraceLog("login token: %v", token)
37
 	utils.TraceLog("login token: %v", token)
62
 	appType, _ := this.GetInt("app_type")
62
 	appType, _ := this.GetInt("app_type")
63
 
63
 
64
 	if url := service.GetAppURLWithAppType(appType); len(url) == 0 {
64
 	if url := service.GetAppURLWithAppType(appType); len(url) == 0 {
65
-		appType = 1
65
+		appType = 0
66
 		returnURL = ""
66
 		returnURL = ""
67
 	}
67
 	}
68
 	utils.TraceLog("login token: %v", token)
68
 	utils.TraceLog("login token: %v", token)
102
 func (this *LoginController) PwdLoginSubmit() {
102
 func (this *LoginController) PwdLoginSubmit() {
103
 	appType, _ := this.GetInt("app_type")
103
 	appType, _ := this.GetInt("app_type")
104
 
104
 
105
+	utils.TraceLog("login app_type=%v", appType)
105
 	if url := service.GetAppURLWithAppType(appType); len(url) == 0 {
106
 	if url := service.GetAppURLWithAppType(appType); len(url) == 0 {
106
-		appType = 1
107
+		utils.TraceLog("login app_type not exist")
108
+		appType = 0
107
 	}
109
 	}
108
 	mobile := this.GetString("mobile")
110
 	mobile := this.GetString("mobile")
109
 	password := this.GetString("password")
111
 	password := this.GetString("password")
158
 func (this *LoginController) CodeLoginSubmit() {
160
 func (this *LoginController) CodeLoginSubmit() {
159
 	appType, _ := this.GetInt("app_type")
161
 	appType, _ := this.GetInt("app_type")
160
 	if url := service.GetAppURLWithAppType(appType); len(url) == 0 {
162
 	if url := service.GetAppURLWithAppType(appType); len(url) == 0 {
161
-		appType = 1
163
+		appType = 0
162
 	}
164
 	}
163
 	mobile := this.GetString("mobile")
165
 	mobile := this.GetString("mobile")
164
 	code := this.GetString("code")
166
 	code := this.GetString("code")
261
 			url := this.appendTokenParamToReturnURL(returnURL, token)
263
 			url := this.appendTokenParamToReturnURL(returnURL, token)
262
 			return url, nil, admin
264
 			return url, nil, admin
263
 		}
265
 		}
266
+		utils.TraceLog("login redirect url: app_type=%v", app_type)
264
 		// 普通管理员用户
267
 		// 普通管理员用户
265
 		// 如果有登录记录,则前往最近登录记录中的应用
268
 		// 如果有登录记录,则前往最近登录记录中的应用
266
 		lastLoginLog, getLastLoginLogErr := service.GetAdminUserLastLoginLog(admin.Id, app_type)
269
 		lastLoginLog, getLastLoginLogErr := service.GetAdminUserLastLoginLog(admin.Id, app_type)

+ 7 - 1
service/login_service.go View File

59
 
59
 
60
 func GetAdminUserLastLoginLog(adminUserID int, appType int) (*models.AdminUserLoginLog, error) {
60
 func GetAdminUserLastLoginLog(adminUserID int, appType int) (*models.AdminUserLoginLog, error) {
61
 	var record models.AdminUserLoginLog
61
 	var record models.AdminUserLoginLog
62
-	err := readUserDb.Last(&record, "admin_user_id = ? AND operate_type <> 2 AND app_type = ?", adminUserID, appType).Error
62
+	var err error
63
+	if appType > 0 {
64
+		err = readUserDb.Last(&record, "admin_user_id = ? AND operate_type <> 2 AND app_type = ?", adminUserID, appType).Error
65
+	} else {
66
+		err = readUserDb.Last(&record, "admin_user_id = ? AND operate_type <> 2", adminUserID).Error
67
+	}
68
+
63
 	if err == gorm.ErrRecordNotFound {
69
 	if err == gorm.ErrRecordNotFound {
64
 		return nil, nil
70
 		return nil, nil
65
 	}
71
 	}