Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
yswenli committed Apr 23, 2021
1 parent 5e5084b commit 849003b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions SAEA.WebRedisManager/Attr/AuthAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public override bool OnActionExecuting()
{
_stopwatch = Stopwatch.StartNew();

if (!HttpContext.Current.Session.ContainsKey("uid"))
if (!HttpContext.Current.Request.Cookies.ContainsKey("uid"))
{
HttpContext.Current.Response.SetCached(new JsonResult(new JsonResult<string>() { Code = 3, Message = "当前操作需要登录!" }));

Expand All @@ -59,7 +59,7 @@ public override bool OnActionExecuting()
}
if (_isAdmin)
{
var user = UserHelper.Get(HttpContext.Current.Session["uid"].ToString());
var user = UserHelper.Get(HttpContext.Current.Request.Cookies["uid"].Value);

if (user.Role != Role.Admin)
{
Expand Down
8 changes: 4 additions & 4 deletions SAEA.WebRedisManager/Services/ConfigService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public JsonResult<string> Set(Config config)
{
try
{
config.Creator = HttpContext.Current.Session["uid"].ToString();
config.Creator = HttpContext.Current.Request.Cookies["uid"].Value;

ConfigHelper.Set(config);

Expand Down Expand Up @@ -69,7 +69,7 @@ public JsonResult<string> SetConfigs(string configs)

var confs = SerializeHelper.Deserialize<List<Config>>(configs);

var user = UserHelper.Get(HttpContext.Current.Session["uid"].ToString());
var user = UserHelper.Get(HttpContext.Current.Request.Cookies["uid"].Value);

if (user.Role == Role.User)
{
Expand Down Expand Up @@ -113,7 +113,7 @@ public JsonResult<List<Config>> GetList()
{
try
{
var user = UserHelper.Get(HttpContext.Current.Session["uid"].ToString());
var user = UserHelper.Get(HttpContext.Current.Request.Cookies["uid"].Value);

if (user != null)
{
Expand Down Expand Up @@ -170,7 +170,7 @@ public JsonResult<bool> Rem(string name)
{
if (string.IsNullOrEmpty(name)) return new JsonResult<bool>() { Code = 2, Message = "传入的配置项名称不能为空!" };

var user = UserHelper.Get(HttpContext.Current.Session["uid"].ToString());
var user = UserHelper.Get(HttpContext.Current.Request.Cookies["uid"].Value);

if (user.Role == Role.Admin)
{
Expand Down
11 changes: 6 additions & 5 deletions SAEA.WebRedisManager/Services/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using System.Text;

using SAEA.Common;
using SAEA.Http;
using SAEA.MVC;
using SAEA.Redis.WebManager.Models;
using SAEA.WebRedisManager.Libs;
Expand Down Expand Up @@ -66,7 +67,7 @@ public JsonResult<string> Login(string userName, string password, string code)

UserHelper.Set(newUser);

HttpContext.Current.Session["uid"] = newUser.ID;
HttpContext.Current.Response.Cookies.Add("uid", new HttpCookie("uid", newUser.ID));

return new JsonResult<string>() { Code = 1, Message = "登录成功,欢迎" + newUser.NickName + "地访问" };
}
Expand All @@ -77,7 +78,7 @@ public JsonResult<string> Login(string userName, string password, string code)
}
else
{
HttpContext.Current.Session["uid"] = user.ID;
HttpContext.Current.Response.Cookies.Add("uid", new HttpCookie("uid", user.ID));

return new JsonResult<string>() { Code = 1, Message = "登录成功,欢迎" + user.NickName + "地访问" };
}
Expand Down Expand Up @@ -191,9 +192,9 @@ public JsonResult<List<User>> Rem(string uid)
{
try
{
if (HttpContext.Current.Session.ContainsKey("uid"))
if (HttpContext.Current.Request.Cookies.ContainsKey("uid"))
{
var cuid = HttpContext.Current.Session["uid"].ToString();
var cuid = HttpContext.Current.Request.Cookies["uid"].Value;

if (cuid == uid)
{
Expand Down Expand Up @@ -252,7 +253,7 @@ public JsonResult<bool> Authenticated()
{
try
{
if (HttpContext.Current.Session.ContainsKey("uid"))
if (HttpContext.Current.Request.Cookies.ContainsKey("uid"))
{
return new JsonResult<bool>() { Code = 1, Data = true };
}
Expand Down

0 comments on commit 849003b

Please sign in to comment.