Example #1
0
        public IActionResult Editor(string noteIdHex)
        {
            this.SetLocale();                        //设置区域化信息
            //todo:存在一个问题,可能导出用户敏感信息
            var userInfo = this.GetUserAndBlogUrl(); //得到用户信息+博客主页
            //判断用户ID是否已经登录
            var user   = this.GetUserBySession();
            var userId = user.UserId;

            Notebook[] noteBoooks = notebookService.GetNoteBookTree(user.UserId);

            //是否已经开放注册功能
            ViewBag.openRegister = configFileService.WebConfig.SecurityConfig.OpenRegister;
            // 已登录了, 那么得到所有信息
            var notebooks = notebookService.GetNotebooks(userId);

            //获得共享的笔记

            // 还需要按时间排序(DESC)得到notes
            List <Note> notes       = new List <Note>();
            NoteContent noteContent = new NoteContent();

            if (!notebooks.IsNullOrNothing())
            {
                // noteId是否存在
                // 是否传入了正确的noteId
                var hasRightNoteId = false;

                long?noteId = noteIdHex.ToLongByHex();
                if (noteId != null)
                {
                    //说明ID本身是有效的
                    var note = noteService.GetNoteById(noteId);
                    if (note != null)
                    {
                        var noteOwner = note.UserId;
                        noteContent = noteContentService.GetNoteContent(noteId, noteOwner, false);

                        hasRightNoteId        = true;
                        ViewBag.curNoteId     = noteId.ToHex24();
                        ViewBag.curNotebookId = note.NotebookId.ToHex24();

                        // 打开的是共享的笔记, 那么判断是否是共享给我的默认笔记

                        if (noteOwner != GetUserIdBySession())
                        {
                            if (shareService.HasReadPerm(noteOwner, GetUserIdBySession(), noteId))
                            {
                                ViewBag.curSharedNoteNotebookId = note.NotebookId.ToHex24();
                                ViewBag.curSharedUserId         = noteOwner;
                            }
                            else
                            {
                                hasRightNoteId = false;
                            }
                        }
                        else
                        {
                            notes = noteService.ListNotes(this.GetUserIdBySession(), note.NotebookId, false, GetPage(), 50, defaultSortField, false, null);
                            // 如果指定了某笔记, 则该笔记放在首位
                        }
                    }
                    //获得最近的笔记
                    int count2      = 0;
                    var latestNotes = noteService.ListNotes(userId, false, GetPage(), 50, defaultSortField, false, null);
                    ViewBag.latestNotes = latestNotes;
                }
                // 没有传入笔记
                // 那么得到最新笔记
                if (!hasRightNoteId)
                {
                    notes = noteService.ListNotes(userId, false, GetPage(), 50, defaultSortField, false, null);
                    if (notes.Any())
                    {
                        noteContent       = noteContentService.GetValidNoteContent(notes[0].NoteId, userId);
                        ViewBag.curNoteId = notes[0].NoteId;
                    }
                }
            }

            ViewBag.isAdmin       = user.Username.Equals(config.SecurityConfig.AdminUsername);
            ViewBag.IsDevelopment = config.APPConfig.Dev;

            ViewBag.userInfo  = userInfo;
            ViewBag.notebooks = notebooks;
            //ViewBag.shareNotebooks= shareNotebooks;

            ViewBag.notes           = notes;
            ViewBag.noteContentJson = noteContent;
            ViewBag.noteContent     = noteContent == null ? null : noteContent.Content;

            ViewBag.tags   = tagService.GetTags(userId);
            ViewBag.config = config;

            Dictionary <string, string> js = new Dictionary <string, string>();

            SetLocale();
            ViewBag.js = js;

            //页面的值
            ViewBag.isAdmin = configFileService.WebConfig.SecurityConfig.AdminUsername.Equals(user.Username);

            ViewBag.userInfo = userInfo;

            ViewBag.OpenRegister = config.SecurityConfig.OpenRegister;
            //编辑器偏好
            ViewBag.MarkdownEditorOption = userInfo.MarkdownEditorOption;
            ViewBag.RichTextEditorOption = userInfo.RichTextEditorOption;
            return(View());
        }