コード例 #1
0
ファイル: BaseController.cs プロジェクト: hyfree/MoreNote
 protected User GetUserByToken(string token)
 {
     if (string.IsNullOrEmpty(token))
     {
         return(null);
     }
     else
     {
         User user = tokenSerivce.GetUserByToken(token);
         return(user);
     }
 }
コード例 #2
0
        //todo:删除笔记本
        public IActionResult DeleteNotebook(string token, string notebookId, int usn)
        {
            User user = TokenSerivce.GetUserByToken(token);

            if (user == null)
            {
                ApiRe apiRe = new ApiRe()
                {
                    Ok  = false,
                    Msg = "Not logged in",
                };

                return(Json(apiRe, MyJsonConvert.GetOptions()));
            }
            if (NotebookService.DeleteNotebookForce(user.UserId, MyConvert.HexToLong(notebookId), usn))
            {
                ApiRe apiRe = new ApiRe()
                {
                    Ok  = true,
                    Msg = "success",
                };
                return(Json(apiRe, MyJsonConvert.GetOptions()));
            }
            else
            {
                ApiRe apiRe = new ApiRe()
                {
                    Ok  = false,
                    Msg = "conflict",
                };
                return(Json(apiRe, MyJsonConvert.GetOptions()));
            }
        }
コード例 #3
0
        //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()));
            }
        }
コード例 #4
0
        //修改笔记
        public IActionResult UpdateNotebook(string token, string notebookId, string title, string parentNotebookId, int seq, int usn)
        {
            User user = TokenSerivce.GetUserByToken(token);

            if (user == null)
            {
                ApiRe apiRe = new ApiRe()
                {
                    Ok  = false,
                    Msg = "Not logged in",
                };

                return(Json(apiRe, MyJsonConvert.GetOptions()));
            }
            else
            {
                Notebook notebook;
                if (NotebookService.UpdateNotebookApi(user.UserId, MyConvert.HexToLong(notebookId), title, MyConvert.HexToLong(parentNotebookId), seq, usn, out notebook))
                {
                    ApiNotebook apiNotebook = fixNotebook(notebook);

                    return(Json(apiNotebook, MyJsonConvert.GetOptions()));
                }
                else
                {
                    ApiRe apiRe = new ApiRe()
                    {
                        Ok  = false,
                        Msg = "UpdateNotebook is error",
                    };

                    return(Json(apiRe, MyJsonConvert.GetOptions()));
                }
            }
        }
コード例 #5
0
ファイル: VditorController.cs プロジェクト: hyfree/MoreNote
        public IActionResult upload(string token)
        {
            var user = tokenSerivce.GetUserByToken(token);

            if (user == null)
            {
                Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                return(Content("401"));
            }

            string             msg  = null;
            var                data = UploadImagesOrAttach(user.UserId, out msg);
            UploadFileResponse uploadFileResponse = new UploadFileResponse()
            {
                data = data
            };

            return(Json(uploadFileResponse, MyJsonConvert.GetSimpleOptions()));
        }
コード例 #6
0
 public User getUserByToken(string token)
 {
     if (string.IsNullOrEmpty(token))
     {
         return(null);
     }
     else
     {
         User user = TokenSerivce.GetUserByToken(token);
         return(user);
     }
 }
コード例 #7
0
 // todo:得到用户信息
 public long getUserIdByToken(string token)
 {
     if (string.IsNullOrEmpty(token))
     {
         return(0);
     }
     else
     {
         User user   = TokenSerivce.GetUserByToken(token);
         long userid = (user == null ? 0 : user.UserId);
         return(userid);
     }
 }
コード例 #8
0
        public JsonResult GetSyncTags(string token, int afterUsn, int maxEntry)
        {
            User user = tokenSerivce.GetUserByToken(token);

            if (user == null)
            {
                ApiRe apiRe = new ApiRe()
                {
                    Ok  = false,
                    Msg = "NOTLOGIN",
                };
                return(Json(apiRe, MyJsonConvert.GetLeanoteOptions()));
            }
            NoteTag[] noteTags = tagService.GeSyncTags(user.UserId, afterUsn, maxEntry);
            return(Json(noteTags, MyJsonConvert.GetLeanoteOptions()));
        }
コード例 #9
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()));
            }
        }
コード例 #10
0
        public long getUserIdByToken()
        {
            string token = GetToken();

            if (string.IsNullOrEmpty(token))
            {
                string userid_hex    = _accessor.HttpContext.Session.GetString("userId");
                long   userid_number = MyConvert.HexToLong(userid_hex);
                return(userid_number);
            }
            else
            {
                User user   = TokenSerivce.GetUserByToken(token);
                long userid = (user == null ? 0 : user.UserId);
                return(userid);
            }
        }
コード例 #11
0
        //获取同步的笔记本
        //[HttpPost]
        public JsonResult GetSyncNotebooks(string token, int afterUsn, int maxEntry)
        {
            User user = TokenSerivce.GetUserByToken(token);

            if (user == null)
            {
                ApiRe apiRe = new ApiRe()
                {
                    Ok  = false,
                    Msg = "Not logged in",
                };

                return(Json(apiRe, MyJsonConvert.GetOptions()));
            }
            Notebook[] notebook = NotebookService.GeSyncNotebooks(user.UserId, afterUsn, maxEntry);
            return(Json(notebook, MyJsonConvert.GetOptions()));
        }
コード例 #12
0
ファイル: UserAPIController.cs プロジェクト: hyfree/MoreNote
        public IActionResult GetUserInfoByToken(string token)
        {
            var user = tokenSerivce.GetUserByToken(token);
            var re   = new ApiRe();

            if (user == null)
            {
                re.Msg = "NOTLOGIN";
            }
            re.Ok   = true;
            re.Data = user;
            return(LeanoteJson(re));
        }
コード例 #13
0
        //添加notebook
        public IActionResult AddNotebook(string token, string title, string parentNotebookId, int seq)
        {
            User user = TokenSerivce.GetUserByToken(token);

            if (user == null)
            {
                ApiRe apiRe = new ApiRe()
                {
                    Ok  = false,
                    Msg = "Not logged in",
                };

                return(Json(apiRe, MyJsonConvert.GetOptions()));
            }
            else
            {
                Notebook notebook = new Notebook()
                {
                    NotebookId       = SnowFlake_Net.GenerateSnowFlakeID(),
                    Title            = title,
                    Seq              = seq,
                    UserId           = user.UserId,
                    ParentNotebookId = MyConvert.HexToLong(parentNotebookId)
                };
                if (NotebookService.AddNotebook(ref notebook))
                {
                    ApiNotebook apiNotebook = fixNotebook(notebook);

                    return(Json(apiNotebook, MyJsonConvert.GetOptions()));
                }
                else
                {
                    ApiRe apiRe = new ApiRe()
                    {
                        Ok  = false,
                        Msg = "AddNotebook is error",
                    };

                    return(Json(apiRe, MyJsonConvert.GetOptions()));
                }
            }
        }
コード例 #14
0
        //获得同步状态
        //  [HttpPost]
        public JsonResult GetSyncState(string token)
        {
            User user = TokenSerivce.GetUserByToken(token);

            if (user == null)
            {
                ApiRe apiRe = new ApiRe()
                {
                    Ok  = false,
                    Msg = "Not logged in",
                };
                string json = JsonSerializer.Serialize(apiRe, MyJsonConvert.GetSimpleOptions());

                return(Json(apiRe, MyJsonConvert.GetOptions()));
            }
            ApiGetSyncState apiGetSyncState = new ApiGetSyncState()
            {
                LastSyncUsn  = user.Usn,
                LastSyncTime = UnixTimeHelper.GetTimeStampInLong(DateTime.Now)
            };

            return(Json(apiGetSyncState, MyJsonConvert.GetSimpleOptions()));
        }
コード例 #15
0
        //得到用户的所有笔记本
        public IActionResult GetNotebooks(string token)
        {
            User user = TokenSerivce.GetUserByToken(token);

            if (user == null)
            {
                ApiRe apiRe = new ApiRe()
                {
                    Ok  = false,
                    Msg = "Not logged in",
                };

                return(Json(apiRe, MyJsonConvert.GetOptions()));
            }
            else
            {
                Notebook[]    notebooks    = NotebookService.GetAll(user.UserId);
                ApiNotebook[] apiNotebooks = fixNotebooks(notebooks);
                return(Json(apiNotebooks, MyJsonConvert.GetOptions()));
            }

            return(null);
        }