From e7438c176acf8d18c07e1a0946770e0f6cb6fadf Mon Sep 17 00:00:00 2001
From: yl <ykxkd@outlook.com>
Date: 星期一, 21 十一月 2022 15:09:29 +0800
Subject: [PATCH] 灵翔的登陆接口存redis加企业区分
---
VueWebApi/Controllers/LoginController.cs | 19 ++++++++++++-------
1 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/VueWebApi/Controllers/LoginController.cs b/VueWebApi/Controllers/LoginController.cs
index 0a6e4af..35f5cd8 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,9 @@
//瀹氫箟鍏ㄥ眬淇℃伅杩斿洖鍙橀噺
ToMessage mes = new ToMessage();
RedisHelper redis = new RedisHelper();
+ //鑾峰彇浼佷笟閰嶇疆Enterprise
+ private static readonly string Enterprise = ConfigurationManager.AppSettings["Enterprise"];
+
#region[PC鐢ㄦ埛鐧诲綍]
/// <summary>
@@ -46,18 +50,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 +73,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 +84,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);
//鍐欏叆鐧诲綍鎿嶄綔璁板綍
@@ -129,7 +133,7 @@
{
try
{
- redis.Remove("LoginUserID" + usertype + userid, 0); //鍒犻櫎redis
+ redis.Remove(Enterprise+"LoginUserID" + usertype + userid, 0); //鍒犻櫎redis
mes.code = "200";
mes.count = 0;
mes.Message = "寮哄埗涓嬬嚎鎴愬姛!";
@@ -288,7 +292,8 @@
public HttpResponseMessage LoginAppAnDonMessage(int userid, string usercode, string username, string usertype)
{
mes = LoginBLL.LoginAppAnDonMessage(userid, usercode, username, usertype);
- return mes.ResponseMess(mes);
+ return TJson.toJson(mes);
+ //return mes.ResponseMess(mes);
}
#endregion
}
--
Gitblit v1.9.3