示例#1
0
        private static void addUserAppAndMenus(User user, MvcContext ctx)
        {
            if (strUtil.IsNullOrEmpty(config.Instance.Site.UserInitApp))
            {
                return;
            }

            IMemberAppService appService  = new UserAppService();
            IMenuService      menuService = new UserMenuService();

            List <String> menus = new List <string>();

            String[] arr = config.Instance.Site.UserInitApp.Split(',');
            foreach (String app in arr)
            {
                if (strUtil.IsNullOrEmpty(app))
                {
                    continue;
                }
                menus.Add(app.Trim());
            }

            if (menus.Contains("home"))
            {
                new UserHomeInstaller().Install(ctx, user, wojilu.lang.get("homepage"), wojilu.Common.AppBase.AccessStatus.Public);
            }

            if (menus.Contains("blog"))
            {
                IMemberApp blogApp = appService.Add(user, "博客", 2);
                // 添加菜单:此处需要明确传入MemberType,否则将会使用ctx.Owner,也就是Site的值,导致bug
                String blogUrl = UrlConverter.clearUrl(alink.ToUserAppFull(blogApp), ctx, typeof(User).FullName, user.Url);
                menuService.AddMenuByApp(blogApp, blogApp.Name, "", blogUrl);
            }

            if (menus.Contains("photo"))
            {
                IMemberApp photoApp = appService.Add(user, "相册", 3);
                String     photoUrl = UrlConverter.clearUrl(alink.ToUserAppFull(photoApp), ctx, typeof(User).FullName, user.Url);
                menuService.AddMenuByApp(photoApp, photoApp.Name, "", photoUrl);
            }

            if (menus.Contains("microblog"))
            {
                IMenu menu = getMenu(user, "微博", alink.ToUserMicroblog(user), ctx);
                menuService.Insert(menu, user, user);
            }

            //if (menus.Contains( "share" )) {
            //    IMenu menu = getMenu( user, "转帖", lnkToUser( new Users.ShareController().Index ), ctx );
            //    menuService.Insert( menu, user, user );
            //}

            if (menus.Contains("friend"))
            {
                IMenu menu = getMenu(user, "好友", lnkToUser(user, new Users.FriendController().FriendList), ctx);
                menuService.Insert(menu, user, user);
            }

            if (menus.Contains("visitor"))
            {
                IMenu menu = getMenu(user, "访客", lnkToUser(user, new Users.VisitorController().Index), ctx);
                menuService.Insert(menu, user, user);
            }

            if (menus.Contains("forumpost"))
            {
                IMenu menu = getMenu(user, "论坛帖子", lnkToUser(user, new Users.ForumController().Topic), ctx);
                menuService.Insert(menu, user, user);
            }

            if (menus.Contains("about"))
            {
                IMenu menu = getMenu(user, "关于我", lnkToUser(user, new Users.ProfileController().Main), ctx);
                menuService.Insert(menu, user, user);
            }

            if (menus.Contains("feedback"))
            {
                IMenu menu = getMenu(user, "留言", lnkToUser(user, new Users.FeedbackController().List), ctx);
                menuService.Insert(menu, user, user);
            }
        }