public async Task <IActionResult> ReLogin(Models.ViewModel.HisLoginViewModel model) { try { if (model.StationId <= 0) { throw new Exception(); } var login = UserMgr.GetMyLoginData(UserSelf.LoginId); if (!model.DepartId.HasValue) { model.DepartId = findDepartId(login.DoctorId.Value, model.StationId); } await SignInProcess(login, model.StationId, model.DepartId, model.LoginExtMobile); await Logger.WriteInfoAsync("Home", "Login", $"用户({login.CustomerId},{login.CustomerName})切换登录到工作站({model.StationId})"); return(RedirectToAction("LoginedDefault")); //登录到默认页面 } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(View("Login", model)); } }
public IActionResult Login() { if (User.Identity.IsAuthenticated) { return(RedirectDefaultIndexPage()); } Models.ViewModel.HisLoginViewModel model = null; return(View(model)); }
public async Task <IActionResult> Login(Models.ViewModel.HisLoginViewModel model) { try { bool rlt = false; //解密传入的登录数据 Func <string, HisLoginViewModel, (bool, HisLoginViewModel)> decriptModel = (type, m) => { if (type == "STEP2" || type == "STEPEXT") { //验证解密数据 string[] dd = Ass.Data.Secret.Decript(m.LoadEncipt, Ass.Data.Secret.GetDynamicEncriptCode(m.BaseTimeTicks)).Split('|'); if (dd[0] == m.LoginName) { m.LoginPassword = dd[1]; rlt = true; } else { throw new Exception("数据加密校验错误 002"); } } return(rlt, m); }; vwCHIS_Sys_Login login = null; //判断传入的数据,是否是初次传入(有密码,没有加密串) //使用传入的数据后,对密码会进行MD5加密处理,对用户名和密码进行3des加密处理 string sendType = ""; if (!string.IsNullOrEmpty(model.LoginPassword) && !string.IsNullOrEmpty(model.LoadEncipt) && !model.IsNeedLoginExt) { sendType = "STEP2"; } if (!string.IsNullOrEmpty(model.LoginPassword) && string.IsNullOrEmpty(model.LoadEncipt)) { sendType = "STEP1"; } if (model.IsNeedLoginExt) { sendType = "STEPEXT"; } if (string.IsNullOrEmpty(sendType)) { throw new Exception("数据加密校验错误 001"); } if (sendType == "STEP1" || sendType == "STEPEXT") { if (!ModelState.IsValid) { return(View(model)); } var mrlt = decriptModel(sendType, model); login = CheckHisLogin_PwdCheck(mrlt.Item2, mrlt.Item1); } var stations = GetUserAllowedStations(model.LoginName); if (stations.Count() == 0) { ModelState.AddModelError("", "该用户没有工作站信息"); return(View()); } if (model.StationId == 0) { if (stations.Count() > 1) { if (sendType == "STEP1") { ViewBag.Stations = stations; ViewBag.StationTree = new Code.Managers.UserFrameManager().GetStationsTree(stations); model.BaseTimeTicks = DateTime.Now.Ticks; model.LoadEncipt = Ass.Data.Secret.Encript(string.Format("{0}|{1}", model.LoginName, Ass.Data.Secret.MD5(model.LoginPassword)) , Ass.Data.Secret.GetDynamicEncriptCode(DateTime.Now.Ticks)); //数据加密 model.LoginPassword = Ass.Data.Secret.Encript(model.LoginPassword, Global.SYS_ENCRIPT_PWD); //密码加密 ViewBag.DoctorId = GetLoginInfoName(model.LoginName).DoctorId; //医生的Id return(View("selectStation", model)); } } if (stations.Count() == 1) { model.StationId = stations.FirstOrDefault().StationID; } } //如果需要重登录系统 if (login != null && login.NeedLoginExt) { ViewBag.loginExtItems = _loginSvr.GetLoginExtsOfThis(login.LoginId).Where(m => m.LoginExtEnabled) .Select(m => new Microsoft.AspNetCore.Mvc.Rendering.SelectListItem { Value = m.LoginExtMobile, Text = $"{m.LoginExtName}({m.LoginExtMobile})" }); ViewBag.loginStationStoreInfo = _loginSvr.GetStationStoreInfo(model.StationId, login.DoctorId.Value); if (sendType == "STEP1") { model.BaseTimeTicks = DateTime.Now.Ticks; model.LoadEncipt = Ass.Data.Secret.Encript(string.Format("{0}|{1}", model.LoginName, Ass.Data.Secret.MD5(model.LoginPassword)) , Ass.Data.Secret.GetDynamicEncriptCode(DateTime.Now.Ticks)); //数据加密 model.LoginPassword = Ass.Data.Secret.Encript(model.LoginPassword, Global.SYS_ENCRIPT_PWD); //密码加密 } model.IsNeedLoginExt = true; if (model.LoginExtPwd.IsEmpty() && model.LoginExtMobile.IsEmpty()) { return(View("loginExtInput", model)); } else { if (!_loginSvr.CheckLoginExtPwd(login.LoginId, model.LoginExtMobile, model.LoginExtPwd, out Exception exx)) { if (exx != null) { ModelState.AddModelError("", exx.Message); } else { ModelState.AddModelError("", "错误的密码!"); } return(View("loginExtInput", model)); } } } if (!stations.Select(m => m.StationID).Contains(model.StationId)) { ModelState.AddModelError("", "该用户没有被授权到指定工作站"); return(View()); } if (sendType == "STEP1") { model.LoginPassword = Ass.Data.Secret.MD5(model.LoginPassword); } model = decriptModel(sendType, model).Item2; var customerId = await CheckHisLogin(model); if (customerId <= 0) { throw new Exception("获取用户数据失败"); } if (customerId > 0) { await Logger.WriteInfoAsync("HomeLogin", "Login", $"用户({model.LoginName})登录成功,工作站({model.StationId})"); return(RedirectToAction("LoginedDefault")); //登录到默认页面 } return(View(model)); } catch (Exception ex) { if (ex.InnerException != null) { ex = ex.InnerException; } var rlt = ex.Message; rlt = rlt.Replace("ChisAdmin", "[数据账户]").Replace("CHIS", "[天使数据库]"); ModelState.AddModelError("", rlt); await Logger.WriteErrorAsync("HomeLogin", "Login", ex); return(View(model)); } }