public ActionResult IsLogin(string code) { if (!string.IsNullOrEmpty(Request.QueryString["ticket"]) && string.IsNullOrEmpty(code)) { return(Content(Code.Common.RedirectCas(Url.Action(nameof(this.Login)), "请求参数错误!"))); } using (var db = new XkSystem.Models.DbContext()) { var tb = db.TableRoot <Sys.Entity.tbSysUser>().FirstOrDefault(d => d.UserCode == code); if (tb == null) { return(Content(Code.Common.RedirectCas(Url.Action(nameof(this.Login)), "用户不存在!"))); } Sys.Models.SysIndex.Login vm = new Sys.Models.SysIndex.Login(); vm.CheckCode = "1234"; vm.CheckCodeRefer = "1234"; vm.UserCode = tb.UserCode; vm.Password = Code.Common.DESDeCode(tb.Password); vm.SchoolName = "深圳龙创软件"; string ret = SysUserLogin(vm); if (!string.IsNullOrEmpty(ret)) { return(Content(Code.Common.RedirectCas(Url.Action(nameof(this.Login)), ret))); } var program = (from p in db.TableRoot <Admin.Entity.tbProgram>() //where (p.Id == Code.Common.ProgramId || Code.Common.ProgramId == 0) where (p.Id == Code.Common.ProgramId || p.IsDefault) orderby p.No select new { p.Id, p.ProgramName, p.IsWide, p.Startup }).FirstOrDefault(); if (program != null) { Code.Common.ProgramId = program.Id; Code.Common.ProgramName = program.ProgramName; Code.Common.IsWide = program.IsWide; if (string.IsNullOrEmpty(program.Startup) == false) { return(Code.MvcHelper.Post(null, Url.Content("~/" + program.Startup))); } } if (Code.Common.IsMobile) { return(Content(Code.Common.Redirect(HttpContext.Request.UrlReferrer.ToString()))); } return(Content(Code.Common.Redirect(Url.Action("Index", "SysIndex")))); } }
public static string SysUserLogin(Sys.Models.SysIndex.Login vm) { using (var db = new XkSystem.Models.DbContext()) { if (string.Compare(vm.CheckCode, vm.CheckCodeRefer, true) != decimal.Zero) { return("验证码不正确!"); } var IsStartCas = ConfigurationManager.AppSettings.Get("IsStartCas"); var password = Code.Common.DESEnCode(vm.Password); var passwordMd5 = Code.Common.CreateMD5Hash(vm.Password); var user = (from p in db.TableRoot <Sys.Entity.tbSysUser>() where p.tbTenant.IsDeleted == false && (p.tbTenant.TenantName == vm.SchoolName || IsStartCas == "true") && (p.UserCode == vm.UserCode || p.Mobile == vm.UserCode || p.Email == vm.UserCode || p.IdentityNumber == vm.UserCode) && (p.Password == password || p.PasswordMd5 == passwordMd5 || p.Password == "" || IsStartCas == "true") select new { p.Id, p.IsDisable, p.IsLock, p.UserName, p.UserType, TenantId = p.tbTenant.Id, p.tbTenant.Title }).FirstOrDefault(); if (user == null) { return("账号或密码不正确,请重新输入!"); } else { if (user.IsDisable) { return("帐号被禁用!"); } if (user.IsLock) { return("帐号因多次密码错误被锁定,请通过【找回账号密码】功能重新激活账号!"); } Code.Common.UserId = user.Id; Code.Common.UserName = user.UserName; Code.Common.UserType = user.UserType; Code.Common.TenantId = user.TenantId; Code.Common.AppTitle = user.Title; var userRole = (from p in db.TableRoot <Sys.Entity.tbSysUserRole>().Include(p => p.tbSysRole) where p.tbSysUser.Id == user.Id select p.tbSysRole.RoleCode).ToList(); //是否是资产报修管理人员 //var assetAdminRole = (from p in db.TableRoot<Sys.Entity.tbSysUserRole>() where p.tbSysUser.Id == user.Id && p.tbSysRole.RoleCode == Code.EnumHelper.SysRoleCode.RepairManagner select p).FirstOrDefault(); //Code.Common.IsRepairMananger = assetAdminRole != null; //是否是资产受理人员 //var assetApplyRole = (from p in db.TableRoot<Sys.Entity.tbSysUserRole>() where p.tbSysUser.Id == user.Id && p.tbSysRole.RoleCode == Code.EnumHelper.SysRoleCode.Repair select p).FirstOrDefault(); //Code.Common.IsProcessUser = assetApplyRole != null; Code.Common.IsMoralMananger = userRole.Count(p => p == Code.EnumHelper.SysRoleCode.Administrator) > 0; if (vm.Remember) { var cookie = new System.Web.HttpCookie(Code.Common.AppName + "XkSystem"); cookie.Values.Add(Code.Common.AppName + "UserCode", Code.Common.DESEnCode(vm.UserCode)); cookie.Values.Add(Code.Common.AppName + "Password", Code.Common.DESEnCode(vm.Password)); cookie.Values.Add(Code.Common.AppName + "SchoolName", Code.Common.DESEnCode(vm.SchoolName)); cookie.Expires = DateTime.Now.AddYears(1); System.Web.HttpContext.Current.Response.Cookies.Add(cookie); } else { System.Web.HttpContext.Current.Response.Cookies[Code.Common.AppName + "XkSystem"].Expires = DateTime.Now; } System.Web.HttpContext.Current.Response.Cookies[Code.Common.AppName + "Account_Code_Ticket"].Expires = DateTime.Now; SysUserLogController.Insert("登录系统!", user.Id); } return(string.Empty); } }