示例#1
0
        public Role AddRole(string roleName, string roleDesc, string permissions)
        {
            var tmp = permissions.Split(',').Select(p => Convert.ToInt32(p)).ToList();
            List <Permission> list = new List <Permission>();
            var allPermissions     = PermissionFactory.GetPermissions();

            tmp.ForEach(p =>
            {
                list.Add(allPermissions.Single(q => q.PermissionId == p));
            });
            var role = new Role(roleName, roleDesc, list);

            _roleRepo.AddRole(role);
            return(role);
        }
示例#2
0
        public bool Save(string guid, string roleName, string roleDesc, string permissions)
        {
            var tmp = permissions.Split(',').Select(p => Convert.ToInt32(p)).ToList();
            List <Permission> list = new List <Permission>();
            var allPermissions     = PermissionFactory.GetPermissions();

            tmp.ForEach(p =>
            {
                list.Add(allPermissions.Single(q => q.PermissionId == p));
            });
            var role = GetRole(guid);

            role.RoleName    = roleName;
            role.RoleDesc    = roleDesc;
            role.Permissions = list;
            return(Save(role));
        }
示例#3
0
        public bool Login(out User user, string userName, string password)
        {
            if (userName == "admin" && password == "123456")
            {
                user = new User("admin", "123456", "admin", "",
                                new List <Role> {
                    new Role("超级管理员", "初始化生成", PermissionFactory.GetPermissions())
                });
                return(true);
            }
            string cipherText = GetMD5(password);

            user = _userRepo.GetUserByUserName(userName);
            if (user == null)
            {
                return(false);
            }
            return(user.Password == cipherText);
        }