| 
					
				 | 
			
			
				@@ -7,6 +7,7 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 package middleware 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import ( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	"errors" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	"net/url" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	"strconv" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -20,66 +21,135 @@ func SessionsAuth(ctx iris.Context) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	// 获得cookie 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	cookie, err := ctx.Request().Cookie("cm") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		comm.Redirect(ctx.ResponseWriter(), "/login") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		ctx.JSON(iris.Map{"code": 1, "msg": ""}) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	// 格式化 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	params, err := url.ParseQuery(cookie.Value) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		comm.Redirect(ctx.ResponseWriter(), "/login") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		ctx.JSON(iris.Map{"code": 1, "msg": ""}) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	// 获得用户信息--TODO 存放redis 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	// 解密用户标识 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	identity, err := comm.AesDecrypt(params.Get("identity"), conf.CookieSecret) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	identityId, err := getDecryptId(params.Get("identity")) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		comm.Redirect(ctx.ResponseWriter(), "/login") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		ctx.JSON(iris.Map{"code": 1, "msg": "账号发生异常1"}) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	digitalToken := comm.CreateSign(conf.CookieSecret + identity) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	// 数字证书 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	digitalToken := comm.CreateSign(conf.CookieSecret + strconv.Itoa(identityId)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	// 获得用户信息--TODO 存放redis 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	npaSer := services.NewProjectAccountService() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	identityId, err := strconv.Atoi(identity) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	// 解密副标识 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	attachedIdentityId, err := getDecryptId(params.Get("attachedIdentity")) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		comm.Redirect(ctx.ResponseWriter(), "/login") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		ctx.JSON(iris.Map{"code": 1, "msg": "账号发生异常2"}) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	accountInfo := npaSer.Get(identityId) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	npaSer := services.NewProjectAccountService() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	accountInfo := npaSer.Get(identityId, attachedIdentityId) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	if accountInfo.Id == "0" { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		comm.Redirect(ctx.ResponseWriter(), "/login") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	ctx.Values().Set("accountId", identity) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	projectId, err := comm.AesDecrypt(accountInfo.ProjectId, conf.SignSecret) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		comm.Redirect(ctx.ResponseWriter(), "/login") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		ctx.JSON(iris.Map{"code": 1, "msg": "账号不存在"}) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	ctx.Values().Set("projectId", projectId) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	// 设置viewData 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	ctx.ViewData("Account", accountInfo) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	// npaDao := dao.NewProjectAccountDao(datasource.InstanceDbMaster()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	// identityId, err := strconv.Atoi(identity) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	// if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	// 	comm.Redirect(ctx.ResponseWriter(), "/login") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	// } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	// accountInfo := npaDao.Get(identityId) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	// if accountInfo.Id == 0 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	// 	comm.Redirect(ctx.ResponseWriter(), "/login") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	// } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	// ctx.Values().Set("accountId", identity) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	ctx.Values().Set("accountId", identityId) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	ctx.Values().Set("projectId", attachedIdentityId) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	ctx.Values().Set("account", accountInfo) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	// 设置viewData 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	// accountView := viewmodels.ProjectAccount{} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	// accountView.Account = accountInfo.Account 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	// accountView.Name = accountInfo.Name 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	// accountView.Company = accountInfo.Company 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	// accountView.Role = accountInfo.Role 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	// accountView.Mobile = accountInfo.Mobile 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	// accountView.Telephone = accountInfo.Telephone 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	// ctx.ViewData("Account", accountView) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	//ctx.ViewData("Account", accountInfo) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	// 比对数字证书 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	if digitalToken != params.Get("digitalToken") { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		comm.Redirect(ctx.ResponseWriter(), "/login") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		ctx.JSON(iris.Map{"code": 1, "msg": "账号异常3"}) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	// TODO 分布式session 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	//通过后执行下一步 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	ctx.Next() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 获得解密后的ID 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+func getDecryptId(id string) (int, error) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	id, err := comm.AesDecrypt(id, conf.CookieSecret) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return 0, errors.New("ID 解析错误") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	idInt, err := strconv.Atoi(id) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return 0, errors.New("ID 转换错误") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	return idInt, nil 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 登陆态-认证 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// func SessionsAuth(ctx iris.Context) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	// 获得cookie 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	cookie, err := ctx.Request().Cookie("cm") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 		comm.Redirect(ctx.ResponseWriter(), "/login") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	// 格式化 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	params, err := url.ParseQuery(cookie.Value) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 		comm.Redirect(ctx.ResponseWriter(), "/login") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	// 解密用户标识 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	identity, err := comm.AesDecrypt(params.Get("identity"), conf.CookieSecret) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 		comm.Redirect(ctx.ResponseWriter(), "/login") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	digitalToken := comm.CreateSign(conf.CookieSecret + identity) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	// 获得用户信息--TODO 存放redis 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	npaSer := services.NewProjectAccountService() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	identityId, err := strconv.Atoi(identity) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 		comm.Redirect(ctx.ResponseWriter(), "/login") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	// TODO 项目ID的获得 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	accountInfo := npaSer.Get(identityId, 2) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	if accountInfo.Id == "0" { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 		comm.Redirect(ctx.ResponseWriter(), "/login") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	ctx.Values().Set("accountId", identity) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	projectId, err := comm.AesDecrypt(accountInfo.ProjectId, conf.SignSecret) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 		comm.Redirect(ctx.ResponseWriter(), "/login") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	ctx.Values().Set("projectId", projectId) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	// 设置viewData 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	ctx.ViewData("Account", accountInfo) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	// npaDao := dao.NewProjectAccountDao(datasource.InstanceDbMaster()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	// identityId, err := strconv.Atoi(identity) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	// if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	// 	comm.Redirect(ctx.ResponseWriter(), "/login") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	// } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	// accountInfo := npaDao.Get(identityId) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	// if accountInfo.Id == 0 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	// 	comm.Redirect(ctx.ResponseWriter(), "/login") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	// } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	// ctx.Values().Set("accountId", identity) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	// 设置viewData 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	// accountView := viewmodels.ProjectAccount{} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	// accountView.Account = accountInfo.Account 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	// accountView.Name = accountInfo.Name 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	// accountView.Company = accountInfo.Company 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	// accountView.Role = accountInfo.Role 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	// accountView.Mobile = accountInfo.Mobile 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	// accountView.Telephone = accountInfo.Telephone 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	// ctx.ViewData("Account", accountView) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	// 比对数字证书 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	if digitalToken != params.Get("digitalToken") { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 		comm.Redirect(ctx.ResponseWriter(), "/login") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	// TODO 分布式session 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	//通过后执行下一步 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 	ctx.Next() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// } 
			 |