Przeglądaj źródła

修改验证用户

zhoufan 4 lat temu
rodzic
commit
a2727611d8

+ 26 - 6
CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/App_Start/AuthorizeAttribute.cs

@@ -19,10 +19,30 @@ namespace CallCenterApi.Interface
19 19
         /// <param name="filterContext"></param>
20 20
         public override void OnAuthorization(AuthorizationContext filterContext)
21 21
         {
22
-            bool isAuth = false;
23
-          
22
+            //bool isAuth = false;
24 23
             if (filterContext.RequestContext.HttpContext.Request.IsAuthenticated)
25 24
             {
25
+                try
26
+                {
27
+                    var us = (FormsPrincipal<Dictionary<string, string>>)filterContext.RequestContext.HttpContext.User;
28
+
29
+                    var user= new BLL.T_Sys_UserAccount().GetModel(us.UserData["F_UserCode"]);
30
+                    if (user == null || user.F_RoleId.ToString() != us.UserData["F_RoleID"])
31
+                    {
32
+                        //角色改变时重新登录
33
+                        filterContext.RequestContext.HttpContext.Response.StatusCode = 200;
34
+                        filterContext.Result = new ContentResult { Content = new AjaxResult { state = ResultTypes.notoken.ToString(), message = "token无效或过期,请重新登录。" }.ToJson() };
35
+                        return;
36
+                    }
37
+                }
38
+                catch (Exception ex)
39
+                {
40
+                    WriteLog(filterContext, "验证失败:" + ex.ToString());
41
+                    filterContext.RequestContext.HttpContext.Response.StatusCode = 200;
42
+                    filterContext.Result = new ContentResult { Content = new AjaxResult { state = ResultTypes.notoken.ToString(), message = "token无效或过期,请重新登录。" }.ToJson() };
43
+                    return;
44
+                }
45
+
26 46
                 //var actionDescriptor = filterContext.ActionDescriptor;
27 47
                 //var controllerDescriptor = actionDescriptor.ControllerDescriptor;
28 48
                 //var controller = controllerDescriptor.ControllerName;
@@ -58,9 +78,9 @@ namespace CallCenterApi.Interface
58 78
             }
59 79
             else
60 80
             {
61
-                filterContext.HttpContext.Response.StatusCode = 200;
81
+                filterContext.RequestContext.HttpContext.Response.StatusCode = 200;
62 82
                 filterContext.Result = new ContentResult { Content = new AjaxResult { state = ResultTypes.notoken.ToString(), message = "token无效或过期,请重新登录。"}.ToJson() };
63
-                WriteLog(filterContext);
83
+                WriteLog(filterContext, "token无效或过期,请重新登录。");
64 84
                 return;
65 85
             }
66 86
 
@@ -78,10 +98,10 @@ namespace CallCenterApi.Interface
78 98
             
79 99
             //}
80 100
         }
81
-        private void WriteLog(AuthorizationContext filterContext)
101
+        private void WriteLog(AuthorizationContext filterContext,string error)
82 102
         {
83 103
             var log = LogFactory.GetLogger(filterContext.Controller.ToString()+"/"+ filterContext.ActionDescriptor.ActionName);
84
-            log.Error("token无效或过期,请重新登录。");
104
+            log.Error(error);
85 105
         }
86 106
 
87 107
     }

+ 22 - 22
CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Controllers/Login/LoginController.cs

@@ -102,7 +102,7 @@ namespace CallCenterApi.Interface.Controllers
102 102
                             //Dic.Add("F_DeptId", dt.Rows[0]["F_DeptId"].ToString());
103 103
                             //Dic.Add("F_UserName", dt.Rows[0]["F_UserName"].ToString());
104 104
                             //Dic.Add("F_Telephone", dt.Rows[0]["F_Telephone"].ToString());
105
-                            //Dic.Add("F_RoleID", dt.Rows[0]["F_RoleID"].ToString());
105
+                            Dic.Add("F_RoleID", dt.Rows[0]["F_RoleID"].ToString());
106 106
                             //Dic.Add("F_SeatFlag", dt.Rows[0]["F_SeatFlag"].ToString());
107 107
 
108 108
                             //if (dt.Rows[0]["F_GroupId"].ToString() != null)
@@ -274,29 +274,29 @@ namespace CallCenterApi.Interface.Controllers
274 274
                             Dictionary<string, string> Dic = new Dictionary<string, string>();
275 275
                             Dic.Add("F_UserID", dt.Rows[0]["F_UserId"].ToString());
276 276
                             Dic.Add("F_UserCode", dt.Rows[0]["F_UserCode"].ToString());
277
-                            Dic.Add("F_DeptId", dt.Rows[0]["F_DeptId"].ToString());
278
-                            Dic.Add("F_UserName", dt.Rows[0]["F_UserName"].ToString());
279
-                            Dic.Add("F_Telephone", dt.Rows[0]["F_Telephone"].ToString());
277
+                            //Dic.Add("F_DeptId", dt.Rows[0]["F_DeptId"].ToString());
278
+                            //Dic.Add("F_UserName", dt.Rows[0]["F_UserName"].ToString());
279
+                            //Dic.Add("F_Telephone", dt.Rows[0]["F_Telephone"].ToString());
280 280
                             Dic.Add("F_RoleID", dt.Rows[0]["F_RoleID"].ToString());
281
-                            Dic.Add("F_SeatFlag", dt.Rows[0]["F_SeatFlag"].ToString());
281
+                            //Dic.Add("F_SeatFlag", dt.Rows[0]["F_SeatFlag"].ToString());
282 282
 
283
-                            if (dt.Rows[0]["F_GroupId"].ToString() != null)
284
-                            {
285
-                                Dic.Add("F_GroupId", dt.Rows[0]["F_GroupId"].ToString());
286
-                            }
287
-                            if (dt.Rows[0]["F_SeatRight"].ToString() != null)
288
-                            {
289
-                                Dic.Add("F_SeatRight", dt.Rows[0]["F_SeatRight"].ToString());
290
-                            }
291
-                            if (!string.IsNullOrEmpty(login.ExtensionPhone))
292
-                            {
293
-                                Dic.Add("F_ExtensionNumber", login.ExtensionPhone);
294
-                            }
295
-                            else
296
-                            {
297
-                                Dic.Add("F_ExtensionNumber", "");
298
-                            }
299
-                            Dic.Add("F_WorkNumber", dt.Rows[0]["F_WorkNumber"].ToString());
283
+                            //if (dt.Rows[0]["F_GroupId"].ToString() != null)
284
+                            //{
285
+                            //    Dic.Add("F_GroupId", dt.Rows[0]["F_GroupId"].ToString());
286
+                            //}
287
+                            //if (dt.Rows[0]["F_SeatRight"].ToString() != null)
288
+                            //{
289
+                            //    Dic.Add("F_SeatRight", dt.Rows[0]["F_SeatRight"].ToString());
290
+                            //}
291
+                            //if (!string.IsNullOrEmpty(login.ExtensionPhone))
292
+                            //{
293
+                            //    Dic.Add("F_ExtensionNumber", login.ExtensionPhone);
294
+                            //}
295
+                            //else
296
+                            //{
297
+                            //    Dic.Add("F_ExtensionNumber", "");
298
+                            //}
299
+                            //Dic.Add("F_WorkNumber", dt.Rows[0]["F_WorkNumber"].ToString());
300 300
 
301 301
                             //CookieUtil.SetCookie("BaseCallCenter_T_User", Dic);
302 302
                             //写入登录日志

+ 1 - 0
CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Controllers/callout/CallOutPlanController.cs

@@ -15,6 +15,7 @@ using CallCenterApi.Common;
15 15
 
16 16
 namespace CallCenterApi.Interface.Controllers.callout
17 17
 {
18
+    [Authority]
18 19
     public class CallOutPlanController : BaseController
19 20
     {
20 21
         private readonly BLL.T_Call_OutTask otBLL = new BLL.T_Call_OutTask();