Beispiel #1
0
        public async Task <ActionResult> Index([FromBody] Models.Login_Info info)
        {
            Hub hub = new Hub();

            Domain.Resp resp = await hub.Login(info);

            Results.Login_Result data = resp.GetData <Results.Login_Result>();
            if (data == Domain.Resp.NONE)
            {
                return(Pack(resp));
            }

            //  生成 JWT
            Claim[] claims = new Claim[]
            {
                new Claim(ClaimTypes.Authentication, data.Token.ToString()),
                new Claim(ClaimTypes.PrimarySid, data.Id.ToString())
            };
            string jwt = Auth.JWT.CreateJwtToken(claims);

            Response.Cookies.Append(Defaults.CLIENT_AUTH_COOKIE_KEY, jwt);

            resp.SetData(data.Account);

            return(Pack(resp));
        }
        public async Task <IActionResult> GetQuestionDetailAsync(int id, string title, int index, int size)
        {
            SetTitle(title);
            Domain.Paginator pager = Domain.Paginator.New(index, size, 1);
            pager["currentUserId"] = CurrentUser.Id.ToString();

            Domain.Questions.Question question = Domain.Questions.Hub.GetQuestion(id);
            Domain.Resp resp = await question.GetDetailAsync(Domain.Questions.Question.DetailSource.Client, pager);

            if (!resp.IsSuccess)
            {
                return(Redirect(string.Format($"/questions/?{ALERT_WARNING}", resp.Message)));
            }
            Domain.Questions.Results.QuestionDetailForClient model = resp.GetData <Domain.Questions.Results.QuestionDetailForClient>();

            return(View("QuestionDetail", model));
        }