Esempio n. 1
0
        public ActionResult SsoLogin(int schoolId, string loginCode)
        {
            using (var db = new XkSystem.Models.DbContext())
            {
                loginCode = Code.Common.DESDeCode(loginCode);
                var user = (from p in db.TableRoot <Sys.Entity.tbSysUser>()
                            where p.tbTenant.IsDeleted == false &&
                            p.tbTenant.Id == schoolId &&
                            p.UserCode == loginCode
                            select new
                {
                    p.Id,
                    p.IsDisable,
                    p.IsLock,
                    p.UserName,
                    p.UserType,
                    TenantId = p.tbTenant.Id
                }).FirstOrDefault();
                if (user == null)
                {
                    return(Content("<script>alert('账号或密码不正确,请重新输入!');</script>"));
                }
                else
                {
                    if (user.IsDisable)
                    {
                        return(Content("<script>alert('帐号被禁用!');</script>"));
                    }

                    if (user.IsLock)
                    {
                        return(Content("<script>alert('帐号因多次密码错误被锁定,请通过【找回账号密码】功能重新激活账号!');</script>"));
                    }

                    Code.Common.UserId   = user.Id;
                    Code.Common.UserName = user.UserName;
                    Code.Common.UserType = user.UserType;
                    Code.Common.TenantId = user.TenantId;

                    SysUserLogController.Insert("登录系统!");
                }

                var program = (from p in db.TableRoot <Admin.Entity.tbProgram>()
                               where (p.Id == Code.Common.ProgramId || Code.Common.ProgramId == 0)
                               orderby p.No
                               select new
                {
                    p.Id,
                    p.IsWide,
                    p.Startup
                }).FirstOrDefault();
                if (program != null)
                {
                    Code.Common.ProgramId = program.Id;
                    Code.Common.IsWide    = program.IsWide;

                    if (string.IsNullOrEmpty(program.Startup) == false)
                    {
                        return(Code.MvcHelper.Post(null, Url.Content("~/" + program.Startup)));
                    }
                }

                return(Code.MvcHelper.Post(null, Url.Action("Index", "SysIndex", new { area = "Sys" })));
            }
        }
Esempio n. 2
0
        public ActionResult Edit(Models.SysMessage.Edit vm)
        {
            using (var db = new XkSystem.Models.DbContext())
            {
                var error = new List <string>();
                if (error.Count == decimal.Zero)
                {
                    if (vm.MessageEdit.Id == 0)
                    {
                        var tb = new Sys.Entity.tbSysMessage();
                        tb.MessageTitle = vm.MessageEdit.MessageTitle;
                        tb.tbProgram    = db.Set <Admin.Entity.tbProgram>().Find(Code.Common.ProgramId);
                        //tb.IsSms = vm.MessageEdit.IsSms;
                        //tb.IsEmail = vm.MessageEdit.IsEmail;
                        //tb.Url = vm.MessageEdit.Url;
                        tb.MessageContent = vm.MessageEdit.MessageContent;
                        tb.tbSysUser      = db.Set <Sys.Entity.tbSysUser>().Find(Code.Common.UserId);
                        tb.InputDate      = DateTime.Now;
                        tb.IsPublic       = vm.MessageEdit.IsPublic;
                        db.Set <Sys.Entity.tbSysMessage>().Add(tb);

                        if (!vm.MessageEdit.IsPublic)
                        {
                            var roleIds = vm.RoleIds.Split(',').ToList();
                            roleIds.RemoveAll(p => string.IsNullOrWhiteSpace(p));
                            if (roleIds != null || roleIds.Count > 0)
                            {
                                var tbSysRoleList    = (from p in db.Table <Entity.tbSysRole>() where roleIds.Contains(p.Id.ToString()) select p);
                                var tbSysMessageRole = vm.RoleIds.Split(',').Select(p => new Entity.tbSysMessageRole()
                                {
                                    tbSysMessage = tb,
                                    tbSysRole    = tbSysRoleList.First(r => r.Id.ToString() == p)
                                }).ToList();
                                db.Set <Entity.tbSysMessageRole>().AddRange(tbSysMessageRole);
                            }
                        }

                        if (db.SaveChanges() > 0)
                        {
                            SysUserLogController.Insert("添加消息");
                        }
                    }
                    else
                    {
                        var tb = (from p in db.Table <Sys.Entity.tbSysMessage>()
                                  where p.Id == vm.MessageEdit.Id
                                  select p).FirstOrDefault();
                        var oldIsPublic = tb.IsPublic;
                        if (tb != null)
                        {
                            tb.MessageTitle = vm.MessageEdit.MessageTitle;
                            //tb.IsSms = vm.MessageEdit.IsSms;
                            //tb.IsEmail = vm.MessageEdit.IsEmail;
                            //tb.Url = vm.MessageEdit.Url;
                            tb.MessageContent = vm.MessageEdit.MessageContent;
                            tb.tbSysUser      = db.Set <Sys.Entity.tbSysUser>().Find(Code.Common.UserId);
                            tb.InputDate      = DateTime.Now;
                            tb.IsPublic       = vm.MessageEdit.IsPublic;
                            if (vm.MessageEdit.IsPublic)
                            {
                                if (!oldIsPublic)   //非公开变成公开
                                {
                                    var tbSysMessageRole = (from p in db.Table <Entity.tbSysMessageRole>() where p.tbSysMessage.Id == tb.Id select p);
                                    foreach (var item in tbSysMessageRole)
                                    {
                                        item.IsDeleted  = true;
                                        item.UpdateTime = DateTime.Now;
                                    }
                                }
                            }
                            else
                            {
                                var roleIds = vm.RoleIds.Split(',').ToList();
                                roleIds.RemoveAll(p => string.IsNullOrWhiteSpace(p));
                                if (roleIds != null || roleIds.Count > 0)
                                {
                                    var existsRoleId = (from p in db.Table <Entity.tbSysMessageRole>() where p.tbSysMessage.Id == tb.Id select p.tbSysRole.Id).ToList();
                                    roleIds.RemoveAll(p => existsRoleId.Contains(p.ConvertToInt()));

                                    if (roleIds != null || roleIds.Count > 0)
                                    {
                                        var tbSysRoleList    = (from p in db.Table <Entity.tbSysRole>() where roleIds.Contains(p.Id.ToString()) select p);
                                        var tbSysMessageRole = vm.RoleIds.Split(',').Select(p => new Entity.tbSysMessageRole()
                                        {
                                            tbSysMessage = tb,
                                            tbSysRole    = tbSysRoleList.First(r => r.Id.ToString() == p)
                                        }).ToList();
                                        db.Set <Entity.tbSysMessageRole>().AddRange(tbSysMessageRole);
                                    }
                                }
                            }
                            if (db.SaveChanges() > 0)
                            {
                                XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("修改消息");
                            }
                        }
                        else
                        {
                            error.AddError(Resources.LocalizedText.MsgNotFound);
                        }
                    }
                }

                return(Code.MvcHelper.Post(error, Url.Action("List"), "提交成功!"));
            }
        }
Esempio n. 3
0
        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);
            }
        }