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