1
duan
2024-08-21 f71a02229c1ba00fbecaead19256593ffb052753
提交 | 用户 | age
90c6eb 1 using DIXWeb.Business.GlobalM;
J 2 using DIXWeb.Business.Common;
3 using DIXWeb.Util;
4 using System.Web.Mvc;
5 using System.Linq;
6 using DIXWeb.Web.Model;
7 using DIXWeb.Web.Model.EasyUIModel;
8 using System;
9 using DIXWeb.Web.Controllers;
10 using System.Diagnostics;
11 using System.Management;
12 using System.Web;
13 using DIXWeb.Entity.Power;
14 using System.Web.UI;
15 using System.Security.Principal;
16 using System.Net;
17 using System.Web.Security;
18 using System.DirectoryServices; 
19 using DIXWeb.DataRepository;
70f264 20 using DIXWeb.Entity.EasyUI;
9057d4 21 using DIXWeb.Business.Workflow;
8eea5c 22 using DMC;
90c6eb 23
J 24 namespace DIXWeb.Web
25 {
26     public class HomeController : BaseMvcController
27     {
28         HomeBusiness _homeBus { get; } = new HomeBusiness();
37756f 29         UserBusiness _userBusiness = new UserBusiness();
90c6eb 30
J 31         #region 视图功能
32
33         public ActionResult Index()
34         {
35             return View();
36         }
37
38         [IgnoreLogin]
39         public ActionResult Login()
40         {
41             ViewData["UserNo"] = "";
42             ViewData["Password"] = "";
43
44             if (Request.Cookies["UserNo"] != null)
45             {
46                 ViewData["UserNo"] = Request.Cookies["UserNo"].Value;
47             }
48             if (Request.Cookies["Password"] != null)
49             {
50                 ViewData["Password"] = Request.Cookies["Password"].Value;
51             }
52             Operator.Logged();
53             //if (Operator.Logged())
54             //{
55
56             //    string loginUrl = Url.Content("~/");
57             //    string script = $@"    
58             //                        <html>
59             //                            <script>
60             //                                top.location.href = '{loginUrl}';
61             //                            </script>
62             //                        </html>
63             //                        ";
64             //    return Content(script);
65             //}
66
67             return View();
68         }
69
70         public ActionResult Desktop()
71         {
72             return View();
73         }
74
75         public ActionResult Test()
76         {
77             return View();
78         }
79
80         #endregion
81
82         #region 获取数据
83
84
85
86         #endregion
87
88         #region 提交数据
7ca951 89         //5105986020
A 90         //spdh1234!@#$
90c6eb 91         [IgnoreLogin]
J 92         public ActionResult SubmitLogin(string UserNo, string password, bool IsCheck)
93         { 
94             ResultMessage res = new ResultMessage();
95             try
96             {
97                 //验证登录
98                 ResultMessage record = new LoginController().CheckUserLogin(UserNo, password);
99                 UserInfo ui = record.Data as UserInfo;
100
101                 if (record.Code == 200)
102                 {
103                     this.RememberUser(UserNo, password, IsCheck, ui);
104                     res.Count = 0;
105                     res.Code = 0;
106                     res.Success = true;
107                     res.Msg = "请求成功!";
108                 }
109                 else
110                 {
70f264 111                     RSP checkSonyUser = this.VerifyDomainUser(UserNo, password);
A 112                     if (checkSonyUser.Code == 200)
113                     {
114                         checkSonyUser = _homeBus.SonyUserUpload(UserNo, password);
115                         ui = new LoginController().LoginUnCode(UserNo, password).Data as UserInfo;
116                         this.RememberUser(UserNo, password, IsCheck, ui);
117                         res.Count = 0;
118                         res.Code = 0;
119                         res.Success = true;
120                         res.Msg = "请求成功!";
121                     }
122                     else
123                     {
90c6eb 124                         res.Count = 0;
J 125                         res.Code = 0;
126                         res.Success = false;
70f264 127                         res.Msg = "账号或密码不正确!";
A 128                     }
90c6eb 129                 }
J 130             }
131             catch (Exception er)
132             {
133                 res.Count = 0;
134                 res.Code = 0;
135                 res.Success = false;
136                 res.Msg = er.Message;
137             }
138             return Content(res.ToJson());
70f264 139         }
A 140         /*
141         5105244510
142         qwer1234!@#$(输入三遍)
143         */
144         public RSP VerifyDomainUser(string user, string pwd, string domain = "AP.")
145         {
146             RSP record = new RSP();
147             string path = "LDAP://AP.Sony.com/CN=Users,DC=AP,DC=Sony,DC=com";
148             int n = domain.IndexOf('.');
149             try
150             {
151                 using (DirectoryEntry de = new DirectoryEntry())
152                 {
153                     de.Path = path;
154                     de.Username = domain.Substring(0, n) + @"\" + user;
155                     de.Password = pwd;
156                     de.AuthenticationType = AuthenticationTypes.ReadonlyServer;
157                     object obj = de.NativeObject;
158                 }
159                 record.Code = 200;
160                 record.Message = "SUCCESS";
161             }
162             catch (System.DirectoryServices.DirectoryServicesCOMException ex)
163             {
164                 record.Code = 500;
165                 record.Message = ex.Message;
166             }
167             return record;
168         }
8eea5c 169         public RSP VerifyDomainUser(string user, string pwd)
A 170         {
171             RSP record = new RSP();
172             try
173             {
174                 DMC.DomainServiceProxy proxy = new DMC.DomainServiceProxy();
175                 Tuple<bool, string> r = proxy.VerifyDomainUser(user, pwd);
176
177                 if (r.Item1)
178                 {
179                     record.Code = 200;
180                     record.Message = "SUCCESS";
181                 }
182                 else
183                 {
184                     record.Code = 500;
185                     record.Message = r.Item2;
186                 }
187             }
188             catch (System.DirectoryServices.DirectoryServicesCOMException ex)
189             {
190                 record.Code = 500;
191                 record.Message = ex.Message;
192             }
193             return record;
194         }
90c6eb 195         private void RememberUser(string UserNo, string password, bool IsCheck, UserInfo ui)
J 196         {
197             if (IsCheck)
198             {
199                 Response.Cookies["UserNo"].Value = UserNo;
200                 Response.Cookies["UserNo"].Expires = DateTime.Now.AddDays(30);
201                 Response.Cookies["Password"].Value = password;
202                 Response.Cookies["Password"].Expires = DateTime.Now.AddDays(30);
675b00 203             }
90c6eb 204             else
J 205             {
206                 Response.Cookies["UserNo"].Expires = DateTime.Now.AddSeconds(-1);
207                 Response.Cookies["Password"].Expires = DateTime.Now.AddSeconds(-1);
675b00 208             }
37756f 209
955cd4 210             Util.SessionHelper.Session["UserId"] = ui.Id;
90c6eb 211             Util.SessionHelper.Session["UserInfo"] = ui;
J 212             Util.SessionHelper.Session["OrgList"] = "";// new OrgInfoController().GetOrganizationByUserNo(ui.UserNo);//保存组织
37756f 213             Util.SessionHelper.Session["RoleNameString"] = _userBusiness.GetUserRoleNameStr(UserNo);
90c6eb 214             Util.SessionHelper.Session["UserNo"] = ui.UserNo;
J 215         }
216
217         /// <summary>
218         /// 注销
219         /// </summary>
220         public ActionResult Logout()
221         {
222             Operator.Logout();
223
224             return Success("注销成功!");
225         }
226
227         #endregion
228          
229
230     }
231 }