From 69ff51968fe04dac0dd702b7b5eed928ad71945b Mon Sep 17 00:00:00 2001
From: yl <ykxkd@outlook.com>
Date: 星期一, 21 十一月 2022 15:10:08 +0800
Subject: [PATCH] MES产品的登陆接口存redis加企业区分
---
VueWebApi/Controllers/LoginController.cs | 34 ++++++++++++++++++++++------------
1 files changed, 22 insertions(+), 12 deletions(-)
diff --git a/VueWebApi/Controllers/LoginController.cs b/VueWebApi/Controllers/LoginController.cs
index 01057f4..9a055cb 100644
--- a/VueWebApi/Controllers/LoginController.cs
+++ b/VueWebApi/Controllers/LoginController.cs
@@ -1,6 +1,7 @@
锘縰sing Newtonsoft.Json;
using System;
using System.Collections.Generic;
+using System.Configuration;
using System.Data;
using System.Linq;
using System.Net;
@@ -20,6 +21,10 @@
//瀹氫箟鍏ㄥ眬淇℃伅杩斿洖鍙橀噺
ToMessage mes = new ToMessage();
RedisHelper redis = new RedisHelper();
+ //鑾峰彇浼佷笟閰嶇疆Enterprise
+ private static readonly string Enterprise = ConfigurationManager.AppSettings["Enterprise"];
+
+
#region[PC鐢ㄦ埛鐧诲綍]
/// <summary>
@@ -46,18 +51,18 @@
ms.username = dt.Rows[0]["USERNAME"].ToString();
ms.password = dt.Rows[0]["PASSWORD"].ToString();
ms.usertype = usertype;
- ms.rediskey = "LoginUserID" + ms.usertype + ms.userid;
+ ms.rediskey = Enterprise+"LoginUserID" + ms.usertype + ms.userid;
mss.Add(ms);
HttpContext.Current.Session.Clear(); //浠庝細璇濈姸鎬侀泦鍚堜腑鍒犻櫎鎵�鏈夌殑閿��
//HttpContext.Current.Session["User"] = JsonConvert.SerializeObject(ms);
//User loginUser = JsonConvert.DeserializeObject<User>(HttpContext.Current.Session["User"].ToString());
User loginUser = JsonConvert.DeserializeObject<User>(JsonConvert.SerializeObject(ms));
//濡傛灉redis鐧诲綍鐢ㄦ埛涓笉瀛樺湪褰撳墠鐢ㄦ埛
- if (redis.Get<User>("LoginUserID" + ms.usertype + ms.userid, 0) == null)
+ if (redis.Get<User>(Enterprise+"LoginUserID" + ms.usertype + ms.userid, 0) == null)
{
//redis.Remove("LoginUserID" + ms.userid, 0);
//鍐欏叆redis(娉ㄦ剰锛歳edis绫婚噷闈㈢殑澶辨晥鏃堕棿蹇呴』鍦╧ey鍒涘缓瀹屾垚涔嬪悗鎵嶇敓鏁�)
- redis.Set<User>("LoginUserID" + ms.usertype + ms.userid, ms, redis.secondsTimeOut, 0);
+ redis.Set<User>(Enterprise+"LoginUserID" + ms.usertype + ms.userid, ms, redis.secondsTimeOut, 0);
//鐧诲綍淇℃伅鍐欏叆session
HttpContext.Current.Session["User"] = JsonConvert.SerializeObject(ms);
//鍐欏叆鐧诲綍鎿嶄綔璁板綍
@@ -69,7 +74,7 @@
else //濡傛灉瀛樺湪
{
//鑾峰彇redis涓綋鍓嶇敤鎴蜂俊鎭�
- User r_loginUser = redis.Get<User>("LoginUserID" + ms.usertype + ms.userid, 0);
+ User r_loginUser = redis.Get<User>(Enterprise+"LoginUserID" + ms.usertype + ms.userid, 0);
//濡傛灉session涓殑鐢ㄦ埛usercode鍜宺edis涓殑鐢ㄦ埛usercode鍖归厤
if ((r_loginUser.usercode + r_loginUser.usertype).Equals(loginUser.usercode + loginUser.usertype))
{
@@ -80,7 +85,7 @@
else
{
//閲嶇疆杩囨湡鏃堕棿(娉ㄦ剰锛歳edis绫婚噷闈㈢殑澶辨晥鏃堕棿蹇呴』鍦╧ey鍒涘缓瀹屾垚涔嬪悗鎵嶇敓鏁�)
- redis.Set<User>("LoginUserID" + ms.usertype + loginUser.userid, loginUser, redis.secondsTimeOut, 0);
+ redis.Set<User>(Enterprise+"LoginUserID" + ms.usertype + loginUser.userid, loginUser, redis.secondsTimeOut, 0);
//鐧诲綍淇℃伅鍐欏叆session
HttpContext.Current.Session["User"] = JsonConvert.SerializeObject(ms);
//鍐欏叆鐧诲綍鎿嶄綔璁板綍
@@ -138,8 +143,12 @@
sql = @"update [dbo].[TUser] set rid=@rid where usercode=@usercode";
list.Add(new { str = sql, parm = new { rid = rid, usercode = username } });
bool aa = DapperHelper.DoTransaction(list);
+ redis.Remove(Enterprise+"LoginUserID" + usertype + userid, 1); //鍒犻櫎redis
}
- redis.Remove("LoginUserID" + usertype + userid, 0); //鍒犻櫎redis
+ else
+ {
+ redis.Remove(Enterprise+"LoginUserID" + usertype + userid, 0); //鍒犻櫎redis
+ }
mes.code = "200";
mes.count = 0;
mes.Message = "寮哄埗涓嬬嚎鎴愬姛!";
@@ -249,15 +258,15 @@
ms.username = dt.Rows[0]["USERNAME"].ToString();
ms.password = dt.Rows[0]["PASSWORD"].ToString();
ms.usertype = usertype;
- ms.rediskey = "LoginUserID" + ms.usertype + ms.userid;
+ ms.rediskey = Enterprise+"LoginUserID" + ms.usertype + ms.userid;
mss.Add(ms);
HttpContext.Current.Session.Clear(); //浠庝細璇濈姸鎬侀泦鍚堜腑鍒犻櫎鎵�鏈夌殑閿��
User loginUser = JsonConvert.DeserializeObject<User>(JsonConvert.SerializeObject(ms));
//濡傛灉redis鐧诲綍鐢ㄦ埛涓笉瀛樺湪褰撳墠鐢ㄦ埛
- if (redis.Get<User>("LoginUserID" + ms.usertype + ms.userid, 0) == null)
+ if (redis.Get<User>(Enterprise+"LoginUserID" + ms.usertype + ms.userid, 1) == null)
{
//鍐欏叆redis(娉ㄦ剰锛歳edis绫婚噷闈㈢殑澶辨晥鏃堕棿蹇呴』鍦╧ey鍒涘缓瀹屾垚涔嬪悗鎵嶇敓鏁�)
- redis.Set<User>("LoginUserID" + ms.usertype + ms.userid, ms, redis.secondsTimeOut, 0);
+ redis.Set<User>(Enterprise+"LoginUserID" + ms.usertype + ms.userid, ms, redis.secondsTimeOut, 1);
//鐧诲綍淇℃伅鍐欏叆session
HttpContext.Current.Session["User"] = JsonConvert.SerializeObject(ms);
//鏇存柊rid
@@ -273,7 +282,7 @@
else //濡傛灉瀛樺湪
{
//鑾峰彇redis涓綋鍓嶇敤鎴蜂俊鎭�
- User r_loginUser = redis.Get<User>("LoginUserID" + ms.usertype + ms.userid, 0);
+ User r_loginUser = redis.Get<User>(Enterprise+"LoginUserID" + ms.usertype + ms.userid, 1);
//濡傛灉session涓殑鐢ㄦ埛usercode鍜宺edis涓殑鐢ㄦ埛usercode鍖归厤
if ((r_loginUser.usercode + r_loginUser.usertype).Equals(loginUser.usercode + loginUser.usertype))
{
@@ -284,7 +293,7 @@
else
{
//閲嶇疆杩囨湡鏃堕棿(娉ㄦ剰锛歳edis绫婚噷闈㈢殑澶辨晥鏃堕棿蹇呴』鍦╧ey鍒涘缓瀹屾垚涔嬪悗鎵嶇敓鏁�)
- redis.Set<User>("LoginUserID" + ms.usertype + loginUser.userid, loginUser, redis.secondsTimeOut, 0);
+ redis.Set<User>(Enterprise+"LoginUserID" + ms.usertype + loginUser.userid, loginUser, redis.secondsTimeOut, 1);
//鐧诲綍淇℃伅鍐欏叆session
HttpContext.Current.Session["User"] = JsonConvert.SerializeObject(ms);
//鏇存柊rid
@@ -370,7 +379,8 @@
public HttpResponseMessage LoginAppAnDonMessage(string rid, string usercode, string username, string usertype)
{
mes = LoginBLL.LoginAppAnDonMessage(rid, usercode, username, usertype);
- return mes.ResponseMess(mes);
+ return TJson.toJson(mes);
+ //return mes.ResponseMess(mes);
}
#endregion
--
Gitblit v1.9.3