| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372 |
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Web;
- using System.Web.Mvc;
- using YTSoft.BaseCallCenter.Model;
- using YTSoft.BaseCallCenter.MVCWeb.Models;
- using YTSoft.Common;
- namespace YTSoft.BaseCallCenter.MVCWeb.Controllers
- {
- public class DefaultController : Controller
- {
- BLL.T_Sys_UserAccount busUserInfo = new BLL.T_Sys_UserAccount();
- public ActionResult Login()
- {
- T_Sys_UserAccount userInfo = new T_Sys_UserAccount();
- HttpCookie cookies = Request.Cookies["platform"];
- //判断是否有cookie值,有的话就读取出来
- if (cookies != null && cookies.HasKeys)
- {
- userInfo.F_UserName = cookies["Name"];
- }
- // userInfo.F_UserName = SystemInfo.GetCpuPerformancevalue();
- return View(userInfo);
- }
- [AcceptVerbs(HttpVerbs.Post)]
- public string LoginIn(string username, string extensionphone, string password)
- {
- string res = "未知错误,请重新登录";
- DataTable dt = new DataTable();
- try
- {
- dt = busUserInfo.GetList(username, password).Tables[0];
- if (dt != null)
- {
- if (dt.Rows.Count > 0)
- {
- if (dt.Rows[0]["F_UserCode"].ToString() == dt.Rows[0]["F_PassWord"].ToString())
- {
- res = "firstlogin" + dt.Rows[0]["F_UserId"].ToString();
- }
- else
- {
- //记住用户名每3个月更换一次
- HttpCookie cookie = new HttpCookie("platform");
- cookie.Values.Add("Name", username);
- cookie.Values.Add("islocal", "1");
- cookie.Expires = System.DateTime.Now.AddMonths(3);
- Response.Cookies.Add(cookie);
- Dictionary<string, string> Dic = new Dictionary<string, string>();
- Dic.Add("F_UserID", dt.Rows[0]["F_UserId"].ToString());
- Dic.Add("F_UserCode", dt.Rows[0]["F_UserCode"].ToString());
- Dic.Add("F_DeptId", dt.Rows[0]["F_DeptId"].ToString());
- Dic.Add("F_UserName", HttpUtility.UrlEncode(dt.Rows[0]["F_UserName"].ToString(), Encoding.UTF8));
- Dic.Add("F_Telephone", dt.Rows[0]["F_Telephone"].ToString());
- Dic.Add("F_RoleID", dt.Rows[0]["F_RoleID"].ToString());
- Dic.Add("F_SeatFlag", dt.Rows[0]["F_SeatFlag"].ToString());
- Dic.Add("F_PId", dt.Rows[0]["F_PId"].ToString());
- if (dt.Rows[0]["F_GroupId"].ToString() != null)
- {
- Dic.Add("F_GroupId", dt.Rows[0]["F_GroupId"].ToString());
- }
- if (dt.Rows[0]["F_SeatRight"].ToString() != null)
- {
- Dic.Add("F_SeatRight", dt.Rows[0]["F_SeatRight"].ToString());
- }
- if (!string.IsNullOrEmpty(extensionphone))
- {
- Dic.Add("F_ExtensionNumber", extensionphone);
- }
- else
- {
- Dic.Add("F_ExtensionNumber", "");
- }
- Dic.Add("F_WorkNumber", dt.Rows[0]["F_WorkNumber"].ToString());
- CookieUtil.SetCookie("BaseCallCenter_T_User", Dic);
- //HttpCookie UserCookie = new HttpCookie("BaseCallCenter_T_User");
- //UserCookie["F_UserId"] = dt.Rows[0]["F_UserId"].ToString();
- //UserCookie["F_UserCode"] = dt.Rows[0]["F_UserCode"].ToString();
- //UserCookie["F_DeptId"] = dt.Rows[0]["F_DeptId"].ToString();
- //UserCookie["F_UserName"] = dt.Rows[0]["F_UserName"].ToString();
- //UserCookie["F_Telephone"] = dt.Rows[0]["F_Telephone"].ToString();
- //UserCookie["F_RoleID"] = dt.Rows[0]["F_RoleID"].ToString();
- //UserCookie["F_SeatFlag"] = dt.Rows[0]["F_SeatFlag"].ToString();
- //if (dt.Rows[0]["F_GroupId"].ToString() != null)
- //{
- // UserCookie["F_GroupId"] = dt.Rows[0]["F_GroupId"].ToString();
- //}
- //if (dt.Rows[0]["F_SeatRight"].ToString() != null)
- //{
- // UserCookie["F_SeatRight"] = dt.Rows[0]["F_SeatRight"].ToString();
- //}
- //if (!string.IsNullOrEmpty(extensionphone))
- //{
- // UserCookie["F_ExtensionNumber"] =extensionphone;
- //}
- //else
- //{
- // UserCookie["F_ExtensionNumber"] = "";
- //}
- //UserCookie["F_WorkNumber"] = dt.Rows[0]["F_WorkNumber"].ToString();
- //Response.Cookies.Add(UserCookie);
- //写入登录日志
- new BLL.T_Sys_LoginLogs().Add(new Model.T_Sys_LoginLogs()
- {
- F_LoginName = dt.Rows[0]["F_UserName"].ToString(),
- F_LoginId = Convert.ToInt32(dt.Rows[0]["F_UserId"].ToString()),
- F_Result = "登录成功",
- F_LoginIP = Common.DTRequest.GetIP(),
- F_Hostname = Common.DTRequest.GetIP(),
- F_LoginDate = DateTime.Now,
- F_Remark = "",
- F_State = 0
- });
- Common.CommonRequest.dtUserId = Convert.ToInt32(dt.Rows[0]["F_UserId"].ToString());
- Common.CommonRequest.dtUserCode = dt.Rows[0]["F_UserCode"].ToString();//Convert.ToInt32(dt.Rows[0]["F_UserId"].ToString());
- res = "success";
- //绑定登录用户分机号
- BLL.T_Sys_UserAccount bll = new BLL.T_Sys_UserAccount();
- bll.UpdateWXId("ExtensionCode",Convert.ToInt32(extensionphone), Convert.ToInt32(dt.Rows[0]["F_UserId"].ToString())); }
- }
- else
- {
- //写入登录日志
- DataTable dt1 = busUserInfo.GetList("F_UserCode='" + username + "'").Tables[0];
- if (dt1.Rows.Count > 0)
- {
- int rr = new BLL.T_Sys_LoginLogs().Add(new Model.T_Sys_LoginLogs()
- {
- F_LoginName = dt1.Rows[0]["F_UserName"].ToString(),
- F_LoginId = Convert.ToInt32(dt1.Rows[0]["F_UserId"].ToString()),
- F_Result = "登录失败:帐号-" + username + ";分机号-" + extensionphone,
- F_LoginIP = Common.DTRequest.GetIP(),
- F_Hostname = Common.DTRequest.GetIP(),
- F_LoginDate = DateTime.Now,
- F_Remark = "",
- F_State = 0
- });
- }
- else
- {
- int rr = new BLL.T_Sys_LoginLogs().Add(new Model.T_Sys_LoginLogs()
- {
- F_LoginName = username,
- F_LoginId = -1,
- F_Result = "登录失败:帐号-" + username + ";分机号-" + extensionphone,
- F_LoginIP = Common.DTRequest.GetIP(),
- F_Hostname = Common.DTRequest.GetIP(),
- F_LoginDate = DateTime.Now,
- F_Remark = "",
- F_State = 0
- });
- }
- res = "账号或密码错误,请重新登录";
- }
- }
- else
- {
- res = "账号或密码错误,请重新登录";
- }
- }
- catch (Exception ex)
- {
- res = "错误:" + ex.ToString();
- SysLog.WriteLog(ex);
- }
- finally
- {
- dt.Clear();
- dt.Dispose();
- }
- return res;
- }
- //退出系统
- [AcceptVerbs(HttpVerbs.Post)]
- public string LoginOut(string username)
- {
- string res = "未知错误,请重新登录";
- DataTable dt = new DataTable();
- try {
- string userid = Request.Cookies["BaseCallCenter_T_User"]["F_UserId"];
- dt = busUserInfo.GetList("F_UserId='" + userid + "'").Tables[0];
- //写入登录日志
- new BLL.T_Sys_LoginLogs().Add(new Model.T_Sys_LoginLogs()
- {
- F_LoginName = dt.Rows[0]["F_UserName"].ToString(),
- F_LoginId = Convert.ToInt32(dt.Rows[0]["F_UserId"].ToString()),
- F_Result = "退出系统成功",
- F_LoginIP = Common.DTRequest.GetIP(),
- F_Hostname = Common.DTRequest.GetIP(),
- F_LoginDate = DateTime.Now,
- F_Remark = "",
- F_State = 0
- });
- res = "success";
- //绑定登录用户分机号
- BLL.T_Sys_UserAccount bll = new BLL.T_Sys_UserAccount();
- bll.UpdateWXId("ExtensionCode", 0, Convert.ToInt32(dt.Rows[0]["F_UserId"].ToString()));
-
- }
- catch(Exception){ }
- return res;
- }
- public ActionResult SSO()
- {
- string[] headerNames = Request.Headers.AllKeys;
- foreach (string strtemp in headerNames)
- {
- string value = Request.Headers.Get(strtemp);
- LogHelper.Default.WriteInfo(strtemp + ":" + value);
- }
- string strReturn = "success";
- bool res = false; //标记是否登录
- bool power = false;
- string LoginName=Request.Headers.Get("OAM_REMOTE_USER");
- //string LoginName1 = "";
- //if (Request.Headers.GetValues("OAM_REMOTE_USER") != null)
- //{
- // LoginName1= Request.Headers.GetValues("OAM_REMOTE_USER").FirstOrDefault();
- //}
- //string LoginName2 = Request.Headers["OAM_REMOTE_USER"].ToMyString();
- LogHelper.Default.WriteInfo("LoginName:" + LoginName.ToMyString());
- //LogHelper.Default.WriteInfo("LoginName1:" + LoginName1.ToMyString());
- //LogHelper.Default.WriteInfo("LoginName2:" + LoginName2.ToMyString());
- if (!string.IsNullOrEmpty(LoginName))
- {
-
- if (!"Anonymous".Equals(LoginName))
- {
- res = true;
- }
- }
- //正常登录
- if (res)
- {
- DataTable dt = new DataTable();
- try
- {
- DataSet ds = busUserInfo.GetList(" F_UserCode=" + LoginName);
- if (ds != null)
- {
- dt = ds.Tables[0];
- if (dt != null && dt.Rows.Count > 0)
- {
- power = true;
- //记住用户名每3个月更换一次
- HttpCookie cookie = new HttpCookie("platform");
- cookie.Values.Add("Name", LoginName);
- cookie.Values.Add("islocal", "0");
- cookie.Expires = System.DateTime.Now.AddMonths(3);
- Response.Cookies.Add(cookie);
- string extensionphone = dt.Rows[0]["F_ExtensionNumber"].ToMyString();
- Dictionary<string, string> Dic = new Dictionary<string, string>();
- Dic.Add("F_UserID", dt.Rows[0]["F_UserId"].ToMyString());
- Dic.Add("F_UserCode", dt.Rows[0]["F_UserCode"].ToMyString());
- Dic.Add("F_DeptId", dt.Rows[0]["F_DeptId"].ToMyString());
- Dic.Add("F_UserName", HttpUtility.UrlEncode(dt.Rows[0]["F_UserName"].ToMyString(), Encoding.UTF8));
- Dic.Add("F_Telephone", dt.Rows[0]["F_Telephone"].ToMyString());
- Dic.Add("F_RoleID", dt.Rows[0]["F_RoleID"].ToMyString());
- Dic.Add("F_SeatFlag", dt.Rows[0]["F_SeatFlag"].ToMyString());
- Dic.Add("F_PId", dt.Rows[0]["F_PId"].ToMyString());
- Dic.Add("F_GroupId", dt.Rows[0]["F_GroupId"].ToMyString());
- Dic.Add("F_SeatRight", dt.Rows[0]["F_SeatRight"].ToMyString());
- Dic.Add("F_ExtensionNumber", extensionphone);
- Dic.Add("F_WorkNumber", dt.Rows[0]["F_WorkNumber"].ToMyString());
- CookieUtil.SetCookie("BaseCallCenter_T_User", Dic);
- //写入登录日志
- new BLL.T_Sys_LoginLogs().Add(new Model.T_Sys_LoginLogs()
- {
- F_LoginName = dt.Rows[0]["F_UserName"].ToString(),
- F_LoginId =dt.Rows[0]["F_UserId"].ToInt32(),
- F_Result = "单点登录成功",
- F_LoginIP = Common.DTRequest.GetIP(),
- F_Hostname = Common.DTRequest.GetIP(),
- F_LoginDate = DateTime.Now,
- F_Remark = "",
- F_State = 0
- });
- Common.CommonRequest.dtUserId = Convert.ToInt32(dt.Rows[0]["F_UserId"].ToString());
- Common.CommonRequest.dtUserCode = dt.Rows[0]["F_UserCode"].ToString();
- //绑定登录用户分机号
- BLL.T_Sys_UserAccount bll = new BLL.T_Sys_UserAccount();
- bll.UpdateWXId("ExtensionCode", extensionphone.ToInt32(), dt.Rows[0]["F_UserId"].ToInt32());
- }
- }
- }
- catch (Exception ex)
- {
- LogHelper.Default.WriteError(ex.Message, ex);
- }
- finally
- {
- dt.Clear();
- dt.Dispose();
- }
- }
- else
- {
- //没有登录 跳转到集团登录页
- }
-
- if (!res)
- {
- strReturn = "没有登录";
- }
- else if (!power)
- {
- strReturn = "没有权限";
- }
- ViewBag.Return = strReturn;
- if (strReturn == "success")
- {
- return View();
- //return RedirectToAction("Index", "Main");
- }
- else
- return View();
- }
- }
- }
|