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
|
|
|
}
|
}
|