Esempio n. 1
0
        public JsonResult GetNotebooks()
        {
            long?userid = GetUserIdBySession();

            Notebook[] noteBoooks = notebookService.GetNoteBookTree(userid);
            return(Json(noteBoooks, MyJsonConvert.GetLeanoteOptions()));
        }
Esempio n. 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()));
            }
        }
Esempio n. 3
0
        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()));
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 登陆
        ///  成功返回 {Ok: true, Item: token }
        ///  失败返回 {Ok: false, Msg: ""}
        /// </summary>
        /// <param name="email"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        //[HttpPost]
        public JsonResult Login(string email, string pwd)
        {
            string tokenStr = "";
            User   user;

            if (AuthService.LoginByPWD(email, pwd, out tokenStr, out user))
            {
                SetUserIdToSession(user.UserId);
                AuthOk authOk = new AuthOk()
                {
                    Ok       = true,
                    Token    = tokenStr,
                    UserId   = user.UserId.ToString("x"),
                    Email    = user.Email,
                    Username = user.Username
                };
                return(Json(authOk, MyJsonConvert.GetSimpleOptions()));
            }
            else
            {
                ApiRe apiRe = new ApiRe()
                {
                    Ok  = false,
                    Msg = "用户名或密码有误"
                };
                string json = JsonSerializer.Serialize(apiRe, MyJsonConvert.GetSimpleOptions());
                return(Json(apiRe, MyJsonConvert.GetSimpleOptions()));
            }
        }
Esempio n. 5
0
        public async Task <IActionResult> Register(string email, string pwd)
        {
            //ex:API当前不使用cookie和session判断用户身份,
            //API调用必须显式的提供token字段,以证明身份
            //API调用者必须是管理员身份或者超级管理员身份,否则调用无效
            //如果用户设置二次验证必须显示提供二次验证码
            ApiRe re = new ApiRe();

            if (!this.config.SecurityConfig.OpenRegister)
            {
                re.Msg = "服务器管理员已经禁止用户注册功能";
                return(LeanoteJson(re));
            }

            if (await authService.Register(email, pwd, 0))
            {
                re = new ApiRe()
                {
                    Ok  = true,
                    Msg = "注册成功"
                };
            }
            else
            {
                re = new ApiRe()
                {
                    Ok  = false,
                    Msg = "注册失败"
                };
            }
            return(Json(re, MyJsonConvert.GetSimpleOptions()));
        }
Esempio n. 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="email">注册者的电子邮件</param>
        /// <param name="pwd">注册者的口令</param>
        /// <param name="iu"></param>
        /// <returns></returns>
        public async Task <JsonResult> DoRegister(string email, string pwd, string iu, string captcha)
        {
            if (!configFileService.WebConfig.SecurityConfig.OpenRegister)
            {
                return(Json(new ApiRe()
                {
                    Ok = false,
                    Msg = "管理员已经将注册功能关闭"
                }, MyJsonConvert.GetSimpleOptions()));
            }
            string errorMessage = string.Empty;
            bool   result       = await authService.Register(email, pwd, iu.ToLongByHex());

            if (result)
            {
                return(Json(new ApiRe()
                {
                    Ok = true,
                    Msg = "Success"
                }, MyJsonConvert.GetSimpleOptions()));
            }
            else
            {
                return(Json(new ApiRe()
                {
                    Ok = false,
                    Msg = $"注册失败:{errorMessage}"
                }, MyJsonConvert.GetSimpleOptions()));
            }
        }
Esempio n. 7
0
        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.GetOptions());

            Console.WriteLine(json);
        }
Esempio n. 8
0
        public IActionResult ListNotes(string notebookId)
        {
            Note[] notes = NoteService.ListNotes(1208692382644703232, 1208692382640508928, false, 1, 1, "defaultSortField", false, false);
            string json  = JsonSerializer.Serialize(notes, MyJsonConvert.GetOptions());

            return(Content(json));
        }
Esempio n. 9
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 = "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()));
                }
            }
        }
Esempio n. 10
0
        public IActionResult SetRTEditorPreferences(string rtOption)
        {
            var re        = new ResponseMessage();
            var mdHashSet = new HashSet <string>();

            mdHashSet.Add("ace");
            mdHashSet.Add("vditor");

            var rthashSet = new HashSet <string>();

            rthashSet.Add("tinymce");
            rthashSet.Add("textbus");
            //参数判断
            if (string.IsNullOrEmpty(rtOption) || !rthashSet.Contains(rtOption))
            {
                re.Msg = "Parameter error ";
                re.Ok  = false;
                return(Json(re, MyJsonConvert.GetSimpleOptions()));
            }
            var user = GetUserBySession();

            //设置编辑器偏好
            userService.SetRTEditorPreferences(user.UserId, rtOption);
            re.Ok = true;
            return(Json(re, MyJsonConvert.GetSimpleOptions()));
        }
Esempio n. 11
0
        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));
        }
Esempio n. 12
0
        public JsonResult MakeCredentialOptions(string token, string authType)
        {
            var tokenVerify = tokenSerivce.VerifyToken(token);

            if (!tokenVerify)
            {
                var apiRe = new ApiRe()
                {
                    Ok  = false,
                    Msg = "注册失败,token无效"
                };
                return(Json(apiRe, MyJsonConvert.GetSimpleOptions()));
            }
            var user = userService.GetUserByToken(token);

            var attachment = AuthenticatorAttachment.Platform;
            var ok         = Enum.TryParse <AuthenticatorAttachment>(authType, true, out attachment);

            //注册选项
            var opts = new MakeCredentialParams(user.Username, user.UserId);

            if (ok)
            {
                opts.AuthenticatorSelection.AuthenticatorAttachment = attachment;
            }
            var credentialCreateOptions = fido2Service.MakeCredentialOptions(user, opts);

            return(Json(credentialCreateOptions));
        }
Esempio n. 13
0
        //todo:格式化URL

        //todo:得到内容
        public IActionResult GetNoteContent(string token, string noteId)
        {
            ApiRe falseRe = new ApiRe()
            {
                Ok  = false,
                Msg = "GetNoteContent_is_error"
            };
            Note        note        = NoteService.GetNote(MyConvert.HexToLong(noteId), getUserIdByToken(token));
            NoteContent noteContent = NoteContentService.GetNoteContent(MyConvert.HexToLong(noteId), getUserIdByToken(token), false);

            if (noteContent == null || note == null)
            {
                return(Json(falseRe, MyJsonConvert.GetOptions()));
            }
            if (noteContent != null && !string.IsNullOrEmpty(noteContent.Content))
            {
                noteContent.Content = NoteService.FixContent(noteContent.Content, note.IsMarkdown);
            }
            ApiNoteContent apiNote = new ApiNoteContent()
            {
                NoteId  = note.NoteId,
                UserId  = note.UserId,
                Content = noteContent.Content
            };

            return(Json(apiNote, MyJsonConvert.GetOptions()));
        }
Esempio n. 14
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()));
            }
        }
Esempio n. 15
0
        public JsonResult DoRegister(string email, string pwd, string iu)
        {
            if (!ConfigService.IsOpenRegister())
            {
                return(Json(new ApiRe()
                {
                    Ok = false,
                    Msg = "管理员已经将注册功能关闭"
                }, MyJsonConvert.GetSimpleOptions()));
            }
            bool result = AuthService.Register(email, pwd, MyConvert.HexToLong(iu));

            if (result)
            {
                return(Json(new ApiRe()
                {
                    Ok = true,
                    Msg = "Success"
                }, MyJsonConvert.GetSimpleOptions()));
            }
            else
            {
                return(Json(new ApiRe()
                {
                    Ok = false,
                    Msg = "注册失败"
                }, MyJsonConvert.GetSimpleOptions()));
            }
        }
Esempio n. 16
0
        public void GetNoteBookTreeTest()
        {
            Notebook[] notebooks = NotebookService.GetNoteBookTree(1208692382644703232);
            string     json      = JsonSerializer.Serialize(notebooks, MyJsonConvert.GetOptions());

            Console.WriteLine(json);
            // Assert.Fail();
        }
Esempio n. 17
0
        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()));
        }
Esempio n. 18
0
        public void JsonConvertWithBetterAnnotation()
        {
            var player = MyJsonConvert.DeserializeObject <Player>("null");

            Assert.Throws <NullReferenceException>(() => {
                var foo = player.Username;
            });
        }
Esempio n. 19
0
        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()));
        }
Esempio n. 20
0
        public IActionResult DoLogin(string email, string pwd, string captcha)
        {
            string verifyCode = HttpContext.Session.GetString("VerifyCode");
            int    time       = HttpContext.Session.GetInt32("VerifyCodeTime").GetValueOrDefault(0);
            int    valid      = HttpContext.Session.GetInt32("VerifyCodeValid").GetValueOrDefault(0);

            if (valid != 1 || !UnixTimeHelper.IsValid(time, 15))
            {
                Re re = new Re()
                {
                    Ok = false, Msg = "验证码过期或失效"
                };
                return(Json(re, MyJsonConvert.GetSimpleOptions()));
            }
            //销毁验证码的标志
            HttpContext.Session.SetInt32("VerifyCodeValid", 0);
            if (string.IsNullOrEmpty(verifyCode) || string.IsNullOrEmpty(captcha))
            {
                Re re = new Re()
                {
                    Ok = false, Msg = "错误参数"
                };
                return(Json(re, MyJsonConvert.GetSimpleOptions()));
            }
            else
            {
                if (!captcha.ToLower().Equals(verifyCode))
                {
                    Re re = new Re()
                    {
                        Ok = false, Msg = "验证码错误"
                    };
                    return(Json(re, MyJsonConvert.GetSimpleOptions()));
                }
                string token;
                User   user;
                if (!AuthService.LoginByPWD(email, pwd, out token, out user))
                {
                    //登录失败
                    Re re = new Re()
                    {
                        Ok = false, Msg = "wrongUsernameOrPassword"
                    };
                    return(Json(re, MyJsonConvert.GetSimpleOptions()));
                }
                else
                {
                    //登录成功
                    HttpContext.Session.SetString("_token", token);
                    HttpContext.Session.SetString("_userId", user.UserId.ToString("x"));
                    Re re = new Re()
                    {
                        Ok = true
                    };
                    return(Json(re, MyJsonConvert.GetSimpleOptions()));
                }
            }
        }
Esempio n. 21
0
        public IActionResult GetNotebooks()
        {
            long userid = 1208692382644703232;

            Notebook[] noteBoooks = NotebookService.GetNoteBookTree(userid);
            string     json       = JsonSerializer.Serialize(noteBoooks, MyJsonConvert.GetOptions());

            return(Content(json));
        }
Esempio n. 22
0
        public static string GetPolicy(UPYunOSSOptions options)
        {
            string json = JsonSerializer.Serialize(options, MyJsonConvert.GetOptions());

            json = json.Replace("save_key", "save-key");
            var policy = Base64Helper.Encode(json);

            return(policy);
        }
Esempio n. 23
0
        public IActionResult IncReadNum(string noteId)
        {
            ResponseMessage re      = new ResponseMessage();
            long?           noteNum = noteId.ToLongByHex();

            re.Ok = blogService.IncReadNum(noteNum);

            return(Json(re, MyJsonConvert.GetLeanoteOptions()));
        }
Esempio n. 24
0
 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()));
 }
Esempio n. 25
0
        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()));
        }
Esempio n. 26
0
        public IActionResult UpdateLeftIsMin(bool leftIsMin)
        {
            var re = new ResponseMessage();

            var userId = GetUserIdBySession();

            re.Ok = userService.UpdateLeftIsMin(userId, leftIsMin);

            return(Json(re, MyJsonConvert.GetLeanoteOptions()));
        }
Esempio n. 27
0
        //获取某个笔记的附件列表
        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()));
        }
Esempio n. 28
0
        public void AddNoteTest()
        {
            string noteJson = System.IO.File.ReadAllText(@"E:\Project\JSON\note\getNoteContent.json");
            Note   note     = JsonSerializer.Deserialize <Note>(noteJson, MyJsonConvert.GetOptions());

            note.NoteId    = 2019;
            note.ContentId = 201901;
            NoteService.AddNote(note);

            // Assert.Fail();
        }
Esempio n. 29
0
        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()));
        }
Esempio n. 30
0
        //删除附件
        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()));
        }