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 = "NOTLOGIN", }; return(Json(apiRe, MyJsonConvert.GetLeanoteOptions())); } else { Notebook notebook; if (notebookService.UpdateNotebookApi(user.UserId, notebookId.ToLongByHex(), title, parentNotebookId.ToLongByHex(), seq, usn, out notebook)) { ApiNotebook apiNotebook = fixNotebook(notebook); return(Json(apiNotebook, MyJsonConvert.GetLeanoteOptions())); } else { ApiRe apiRe = new ApiRe() { Ok = false, Msg = "UpdateNotebook is error", }; return(Json(apiRe, MyJsonConvert.GetLeanoteOptions())); } } }
public async Task <IActionResult> sessions([FromBody] SessionRequestDto sessionRequest) { string token = string.Empty; User user = null; var tokenStr = await AuthService.LoginByPWD(sessionRequest.email, sessionRequest.password); if (!string.IsNullOrEmpty(tokenStr)) { var response = new SessionResponseDto { id = token, user_id = user.UserId.ToHex24() }; return(Json(response, MyJsonConvert.GetLeanoteOptions())); } else { var response = new SessionResponseDto { error = "Invalid username or password" }; //(禁止) 服务器拒绝请求。 Response.StatusCode = (int)HttpStatusCode.Forbidden; return(Json(response, MyJsonConvert.GetLeanoteOptions())); } }
public void TestTest() { APPStoreInfo diHaoV1_API = new APPStoreInfo() { resp_data = new Resp_Data() { app_list = new AppInfo[] { new AppInfo() { appid = 111, appautor = "appid", appdetail = "appid", appname = "appid", apppackage = "appid", appdownurl = "appid", applogourl = "appid", appversion = "appid", imglist = new string[] { "", "" }, appsize = "appid" } } } }; string json = JsonSerializer.Serialize(diHaoV1_API, MyJsonConvert.GetLeanoteOptions()); Console.WriteLine(json); }
public JsonResult GetNotebooks() { long?userid = GetUserIdBySession(); Notebook[] noteBoooks = notebookService.GetNoteBookTree(userid); return(Json(noteBoooks, MyJsonConvert.GetLeanoteOptions())); }
public async Task <IActionResult> UpdatePwd(string token, string oldPwd, string pwd) { ApiRe re = new ApiRe(); User user = tokenSerivce.GetUserByToken(token); if (user == null) { re.Msg = "NOTLOGIN"; return(Json(re, MyJsonConvert.GetLeanoteOptions())); } try { var result = await userService.UpdatePwd(user.UserId, oldPwd, pwd); re.Ok = result; if (!result) { re.Msg = "更新密码失败"; } } catch (Exception ex) { re.Msg = ex.Message; re.Ok = false; } return(LeanoteJson(re)); }
public IActionResult SearchNoteByTags(string tags) { var query = Request.Query["tags[]"]; var userId = this.GetUserIdBySession(); var notes = noteService.SearchNoteByTag(query, userId, GetPage(), pageSize); return(Json(notes, MyJsonConvert.GetLeanoteOptions())); }
public IActionResult GetNote(string token, string noteId) { var userId = GetUserIdByToken(token); var note = noteService.GetNote(userId, noteId.ToLongByHex()); var apiNotes = noteService.ToApiNotes(new Note[] { note }); return(Json(apiNotes[0], MyJsonConvert.GetLeanoteOptions())); }
public JsonResult GetSyncNotes(int afterUsn, int maxEntry, string token) { if (maxEntry == 0) { maxEntry = 100; } ApiNote[] apiNotes = noteService.GetSyncNotes(GetUserIdByToken(token), afterUsn, maxEntry); return(Json(apiNotes, MyJsonConvert.GetLeanoteOptions())); }
public IActionResult IncReadNum(string noteId) { ResponseMessage re = new ResponseMessage(); long? noteNum = noteId.ToLongByHex(); re.Ok = blogService.IncReadNum(noteNum); return(Json(re, MyJsonConvert.GetLeanoteOptions())); }
//获取某个笔记的附件列表 public async Task <IActionResult> GetAttachs(string noteId) { var response = new ResponseMessage() { Ok = true, List = await attachService.ListAttachsAsync(noteId.ToLongByHex(), GetUserIdBySession()) }; return(Json(response, MyJsonConvert.GetLeanoteOptions())); }
public IActionResult UpdateLeftIsMin(bool leftIsMin) { var re = new ResponseMessage(); var userId = GetUserIdBySession(); re.Ok = userService.UpdateLeftIsMin(userId, leftIsMin); return(Json(re, MyJsonConvert.GetLeanoteOptions())); }
public IActionResult UpdateColumnWidth(int notebookWidth, int noteListWidth, int mdEditorWidth) { var re = new ResponseMessage(); var userId = GetUserIdBySession(); re.Ok = userService.UpdateColumnWidth(userId, notebookWidth, noteListWidth, mdEditorWidth); return(Json(re, MyJsonConvert.GetLeanoteOptions())); }
public JsonResult GetUserLoginSecurityStrategy(string UserName) { var ss = userService.GetGetUserLoginSecurityStrategy(UserName); ApiRe apiRe = new ApiRe() { Ok = (ss != null), Msg = "", Data = ss }; return(Json(apiRe, MyJsonConvert.GetLeanoteOptions())); }
//删除附件 public async Task <IActionResult> DeleteAttach(string attachId) { var attachIdLong = attachId.ToLongByHex(); var result = await attachService.DeleteAttachAsync(attachIdLong, GetUserIdBySession()); var response = new ResponseMessage() { Ok = result, Msg = string.Empty }; return(Json(response, MyJsonConvert.GetLeanoteOptions())); }
public async Task <IActionResult> GetRealNameInformation(string token, string digitalEnvelopeJson, string dataSignJson) { var re = new ApiRe(); DigitalEnvelope digitalEnvelope = null; var verify = false; //数字信封 if (this.config.SecurityConfig.ForceDigitalEnvelope) { digitalEnvelope = DigitalEnvelope.FromJSON(digitalEnvelopeJson); } if (this.config.SecurityConfig.ForceDigitalSignature) { //验证签名 var dataSign = DataSignDTO.FromJSON(dataSignJson); verify = await this.ePassService.VerifyDataSign(dataSign); if (!verify) { return(LeanoteJson(re)); } verify = dataSign.SignData.Operate.Equals("/api/User/GetRealNameInformation"); if (!verify) { re.Msg = "Operate is not Equals "; return(LeanoteJson(re)); } //签字签名和数字信封数据 //签名存证 this.dataSignService.AddDataSign(dataSign, "GetRealNameInformation"); } User user = tokenSerivce.GetUserByToken(token); if (user == null) { ApiRe apiRe = new ApiRe() { Ok = false, Msg = "NOTLOGIN", }; return(Json(apiRe, MyJsonConvert.GetLeanoteOptions())); } var realName = this.realNameService.GetRealNameInformationByUserId(user.UserId); re.Ok = true; re.Data = realName; return(LeanoteJson(re)); }
public async Task <IActionResult> Register(string email, string pwd) { var re = new ResponseMessage(); var message = string.Empty; if (userService.VDUserName(email, out message) && userService.VDPassWord(pwd, null, out message)) { var result = await authService.Register(email, pwd, null); re.Ok = result; } re.Msg = message; return(Json(re, MyJsonConvert.GetLeanoteOptions())); }
public JsonResult AddNotebook(string notebookId, string title, string parentNotebookId) { Notebook notebook; var result = notebookService.AddNotebook(notebookId.ToLongByHex(), GetUserIdBySession(), parentNotebookId.ToLongByHex(), title, out notebook); if (result) { return(Json(notebook, MyJsonConvert.GetLeanoteOptions())); } else { return(Json(false)); } }
public IActionResult PutTestingContent(string what) { //http://joplin.morenote.top/api/items/root:/testing.txt:/content //what=testing.txt:/content var response = new PutContextResponseDto() { name = "testing.txt", id = "{AC66705E-090C-4AE6-8933-77A7BAC256E8}", created_time = UnixTimeUtil.GetUnixTimeMillisecondsInLong(), updated_time = UnixTimeUtil.GetUnixTimeMillisecondsInLong() }; return(Json(response, MyJsonConvert.GetLeanoteOptions())); }
public JsonResult AddTag(string token, string tag) { NoteTag noteTag = tagService.AddOrUpdateTag(GetUserIdByToken(token), tag); if (noteTag == null) { return(Json(new ApiRe() { Ok = false, Msg = "添加标签失败" }, MyJsonConvert.GetLeanoteOptions())); } else { return(Json(noteTag, MyJsonConvert.GetLeanoteOptions())); } }
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())); }
public async Task <IActionResult> GetNoteContent(string token, string noteId) { ApiRe re = new ApiRe() { Ok = false, Msg = "GetNoteContent_is_error" }; try { var user = GetUserByToken(token); if (user == null) { return(LeanoteJson(re)); } Note note = noteService.GetNote(noteId.ToLongByHex(), GetUserIdByToken(token)); NoteContent noteContent = noteContentService.GetNoteContent(noteId.ToLongByHex(), GetUserIdByToken(token), false); if (noteContent == null || note == null) { return(Json(re, MyJsonConvert.GetLeanoteOptions())); } if (noteContent != null && !string.IsNullOrEmpty(noteContent.Content)) { noteContent.Content = noteService.FixContent(noteContent.Content, note.IsMarkdown); } else { noteContent.Content = "<p>Content is IsNullOrEmpty<>"; } if (noteContent.IsEncryption) { var dec = this.cryptographyProvider.SM4Decrypt(noteContent.Content.Base64ToByteArray()); noteContent.Content = Encoding.UTF8.GetString(dec); } re.Ok = true; re.Data = noteContent; return(LeanoteJson(re)); } catch (Exception ex) { re.Ok = false; re.Msg = ex.Message; throw; } }
public IActionResult GetNoteContent(string noteId) { long? noteNumber = noteId.ToLongByHex(); long? userNumber = GetUserIdBySession(); NoteContent noteContent = noteContentService.GetValidNoteContent(noteId.ToLongByHex(), GetUserIdBySession()); ApiRe falseRe = new ApiRe() { Ok = false, Msg = "GetNoteContent_is_error" }; if (noteContent == null) { return(Json(falseRe, MyJsonConvert.GetLeanoteOptions())); } return(Json(noteContent, MyJsonConvert.GetLeanoteOptions())); }
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 = "NOTLOGIN", }; return(Json(apiRe, MyJsonConvert.GetLeanoteOptions())); } else { Notebook notebook = new Notebook() { NotebookId = idGenerator.NextId(), Title = title, Seq = seq, UserId = user.UserId, ParentNotebookId = parentNotebookId.ToLongByHex() }; if (notebookService.AddNotebook(ref notebook)) { ApiNotebook apiNotebook = fixNotebook(notebook); return(Json(apiNotebook, MyJsonConvert.GetLeanoteOptions())); } else { ApiRe apiRe = new ApiRe() { Ok = false, Msg = "AddNotebook is error", }; return(Json(apiRe, MyJsonConvert.GetLeanoteOptions())); } } }
public async Task <IActionResult> PasteImage(string noteId) { var id = noteId.ToLongByHex(); var re = await uploadImage("pasteImage", null); if (id != null) { var userid = GetUserIdBySession(); var note = noteService.GetNoteById(id); if (note.UserId != null) { var noteUserId = note.UserId; if (noteUserId != userid) { //todo:支持共享编辑 re.Ok = false; } } } return(Json(re, MyJsonConvert.GetLeanoteOptions())); }
public IActionResult UpdateUsername(string token, string username) { var re = new ApiRe(); var message = string.Empty; if (string.IsNullOrEmpty(username) || username.Length < 4) { re.Msg = "用户名长度必须大于4"; return(Json(re, MyJsonConvert.GetLeanoteOptions())); } if (username.Length > 16) { re.Msg = "Name string length>16"; return(Json(re, MyJsonConvert.GetLeanoteOptions())); } User user = tokenSerivce.GetUserByToken(token); if (user == null) { re.Msg = "Unable to obtain user information through Session "; return(Json(re, MyJsonConvert.GetLeanoteOptions())); } if (user.Username.Equals(config.SecurityConfig.DemoUsername)) { re.Msg = "cannotUpdateDemo"; return(Json(re, MyJsonConvert.GetLeanoteOptions())); } if (userService.VDUserName(username, out message)) { re.Ok = userService.UpdateUsername(user.UserId, username); re.Msg = message; return(Json(re, MyJsonConvert.GetLeanoteOptions())); } else { re.Msg = "Incorrect username format or conflict"; return(Json(re, MyJsonConvert.GetLeanoteOptions())); } }
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())); } }
public async Task <IActionResult> UpdatePwd(string oldPwd, string pwd) { var re = new ResponseMessage(); if (string.IsNullOrEmpty(oldPwd) || string.IsNullOrEmpty(pwd) || pwd.Length < 6) { re.Msg = "Password length is too short"; return(Json(re, MyJsonConvert.GetLeanoteOptions())); } User user = GetUserBySession(); if (user == null) { re.Msg = "Unable to obtain user information through Session "; return(Json(re, MyJsonConvert.GetLeanoteOptions())); } if (user.Username.Equals(config.SecurityConfig.DemoUsername)) { re.Msg = "cannotUpdateDemo"; return(Json(re, MyJsonConvert.GetLeanoteOptions())); } string error; if (userService.VDPassWord(pwd, user.UserId, out error)) { re.Ok = await userService.UpdatePwd(user.UserId, oldPwd, pwd); re.Msg = "The update password is wrong, please check the password you provided "; return(Json(re, MyJsonConvert.GetLeanoteOptions())); } else { re.Msg = error; re.Ok = false; return(Json(re, MyJsonConvert.GetLeanoteOptions())); } }
public JsonResult DeleteTrash(string noteId, int usn, string token) { bool result = trashService.DeleteTrashApi(noteId.ToLongByHex(), GetUserIdByToken(token), usn, out string msg, out int afterUsn); if (result) { return(Json(new ReUpdate() { Ok = true, Msg = "", Usn = afterUsn }, MyJsonConvert.GetLeanoteOptions())); } else { return(Json(new ReUpdate() { Ok = false, Msg = msg, Usn = afterUsn }, MyJsonConvert.GetLeanoteOptions())); } }
public JsonResult GetSyncState(string token) { User user = tokenSerivce.GetUserByToken(token); if (user == null) { ApiRe apiRe = new ApiRe() { Ok = false, Msg = "NOTLOGIN", }; return(Json(apiRe, MyJsonConvert.GetLeanoteOptions())); } ApiGetSyncState apiGetSyncState = new ApiGetSyncState() { LastSyncUsn = user.Usn, LastSyncTime = UnixTimeUtil.GetTimeStampInLong(DateTime.Now) }; return(Json(apiGetSyncState, MyJsonConvert.GetSimpleOptions())); }
public IActionResult GetNotebooks(string token) { User user = tokenSerivce.GetUserByToken(token); if (user == null) { ApiRe apiRe = new ApiRe() { Ok = false, Msg = "NOTLOGIN", }; return(Json(apiRe, MyJsonConvert.GetLeanoteOptions())); } else { Notebook[] notebooks = notebookService.GetAll(user.UserId); ApiNotebook[] apiNotebooks = fixNotebooks(notebooks); return(Json(apiNotebooks, MyJsonConvert.GetLeanoteOptions())); } return(null); }