//todo:得到note和内容
        public IActionResult GetNoteAndContent(string token, string noteId)
        {
            User tokenUser = TokenSerivce.GetUserByToken(token);

            if (tokenUser == null)
            {
                return(Json(new ApiRe()
                {
                    Ok = false, Msg = ""
                }, MyJsonConvert.GetOptions()));
            }
            NoteAndContent noteAndContent = NoteService.GetNoteAndContent(MyConvert.HexToLong(noteId), tokenUser.UserId, false, false, false);

            ApiNote[] apiNotes = NoteService.ToApiNotes(new Note[] { noteAndContent.note });
            ApiNote   apiNote  = apiNotes[0];

            apiNote.Content  = NoteService.FixContent(noteAndContent.noteContent.Content, noteAndContent.note.IsMarkdown);
            apiNote.Desc     = noteAndContent.note.Desc;
            apiNote.Abstract = noteAndContent.noteContent.Abstract;
            if (noteAndContent == null)
            {
                return(Json(new ApiRe()
                {
                    Ok = false, Msg = ""
                }, MyJsonConvert.GetOptions()));
            }
            else
            {
                return(Json(apiNote, MyJsonConvert.GetOptions()));
            }
        }
Exemple #2
0
        public async Task <IActionResult> PostAsync(string blogUserName, string noteIdHex)
        {
            //添加访问日志
            await InsertLogAsync($"Blog/Post/{blogUserName}/{noteIdHex}/").ConfigureAwait(false);

            User blogUser = ActionInitBlogUser(blogUserName);

            if (blogUser == null)
            {
                Response.StatusCode = (int)HttpStatusCode.NotFound;
                return(Content("查无此人"));
            }
            long noteId = MyConvert.HexToLong(noteIdHex);

            if (noteId == 0)
            {
                Response.StatusCode = (int)HttpStatusCode.NotFound;
                return(Content("未找到"));
            }
            Dictionary <string, string> blog = new Dictionary <string, string>();
            NoteAndContent noteAndContent    = NoteService.GetNoteAndContent(noteId);

            NoteService.AddReadNum(noteId);
            if (noteAndContent == null)
            {
                Response.StatusCode = (int)HttpStatusCode.NotFound;
                return(Content("未经授权的访问"));
            }
            if (noteAndContent.note.IsDeleted || noteAndContent.note.IsTrash)
            {
                Response.StatusCode = (int)HttpStatusCode.NotFound;
                return(Content("这篇文章已经被删除"));
            }
            if (!noteAndContent.note.IsBlog)
            {
                Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                return(Content("这篇文章已经被取消分享"));
            }

            ViewBag.noteAndContent = noteAndContent;
            blog.Add("Title", noteAndContent.note.Title);
            blog.Add("NoteTitle", noteAndContent.note.Title);
            blog.Add("keywords", "关键字");
            ViewBag.blog = blog;
            return(View());
        }
Exemple #3
0
        public IActionResult GetNoteAndContent(string token, string noteId)
        {
            User tokenUser = tokenSerivce.GetUserByToken(token);

            if (tokenUser == null)
            {
                return(Json(new ApiRe()
                {
                    Ok = false, Msg = ""
                }, MyJsonConvert.GetLeanoteOptions()));
            }
            try
            {
                NoteAndContent noteAndContent = noteService.GetNoteAndContent(noteId.ToLongByHex(), tokenUser.UserId, false, false, false);

                ApiNote[] apiNotes = noteService.ToApiNotes(new Note[] { noteAndContent.note });
                ApiNote   apiNote  = apiNotes[0];
                apiNote.Content  = noteService.FixContent(noteAndContent.noteContent.Content, noteAndContent.note.IsMarkdown);
                apiNote.Desc     = noteAndContent.note.Desc;
                apiNote.Abstract = noteAndContent.noteContent.Abstract;
                if (noteAndContent == null)
                {
                    return(Json(new ApiRe()
                    {
                        Ok = false, Msg = ""
                    }, MyJsonConvert.GetLeanoteOptions()));
                }
                else
                {
                    return(Json(apiNote, MyJsonConvert.GetLeanoteOptions()));
                }
            }
            catch (Exception ex)
            {
                return(Json(new ApiRe()
                {
                    Ok = false, Msg = ex.Message
                }, MyJsonConvert.GetLeanoteOptions()));
            }
        }
Exemple #4
0
        public async Task <IActionResult> PostAsync(string blogUserName, string noteIdHex)
        {
            //添加访问日志
            await InsertLogAsync($"Blog/Post/{blogUserName}/{noteIdHex}/").ConfigureAwait(false);

            User blogUser = ActionInitBlogUser(blogUserName);

            if (blogUser == null)
            {
                Response.StatusCode = (int)HttpStatusCode.NotFound;
                return(Content("查无此人"));
            }
            long?noteId = noteIdHex.ToLongByHex();

            if (noteId == 0)
            {
                Response.StatusCode = (int)HttpStatusCode.NotFound;
                return(Content("未找到"));
            }

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

            NoteAndContent noteAndContent = noteService.GetNoteAndContent(noteId);

            if (!string.IsNullOrEmpty(noteAndContent.note.AccessPassword))
            {
                if (!Request.Headers.ContainsKey("Authorization"))
                {
                    Response.StatusCode = 401;
                    Response.Headers.Add("WWW-Authenticate", $"Basic realm='{config.APPConfig.SiteUrl}/Blog/Post/{blogUserName}/{noteIdHex}'");
                    return(Content("Missing Authorization Header"));
                }
                else
                {
                    var authorization = Request.Headers["Authorization"].ToString().Replace("Basic", "");
                    var basic         = Base64Util.UnBase64String(authorization);
                    var sp            = basic.Split(":");
                    var user          = sp[0];
                    var password      = sp[1];
                    if (!noteService.VerifyAccessPassword(noteAndContent.note.UserId, noteId, password, noteAndContent.note.AccessPassword))
                    {
                        Response.StatusCode = 401;
                        Response.Headers.Add("WWW-Authenticate", $"Basic realm='{config.APPConfig.SiteUrl}/Blog/Post/{blogUserName}/{noteIdHex}'");
                        return(Content("Missing Authorization Header"));
                    }
                    else
                    {
                    }
                }
            }

            noteService.AddReadNum(noteId);
            if (noteAndContent == null)
            {
                Response.StatusCode = (int)HttpStatusCode.NotFound;
                return(Content("未经授权的访问"));
            }

            if (noteAndContent.note.IsDeleted || noteAndContent.note.IsTrash)
            {
                Response.StatusCode = (int)HttpStatusCode.NotFound;
                return(Content("这篇文章已经被删除"));
            }

            if (!noteAndContent.note.IsBlog)
            {
                Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                return(Content("这篇文章已经被取消分享"));
            }
            if (!blogUser.Verified)
            {
                return(Content("用户未实名认证"));
            }
            UserBlog userBlog = blogService.GetUserBlog(blogUser.UserId);

            BlogCommon(blogUser.UserId, userBlog, blogUser);
            ViewBag.noteAndContent = noteAndContent;
            blog.Add("Title", noteAndContent.note.Title);
            blog.Add("NoteTitle", noteAndContent.note.Title);
            blog.Add("keywords", "关键字");
            ViewBag.blog = blog;
            return(View());
        }