Пример #1
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()));
            }
        }
        private void AuthOkHandler(MemoryStream stream)
        {
            var authOk = Schemes.AuthOk.DeserializeWithLengthPrefix(stream);

            AuthOk?.Invoke(this, EventArgs.Empty);
        }