Пример #1
0
        //  [ValidateAntiForgeryToken]
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.Message = String.Join(" ", ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage));
                return(View(model));
            }

            APIRequest ar = new APIRequest(loginController);

            model.ClientCode = AppHelper.ClientCode();
            var response = ar.Post(model);

            string message = string.Empty;

            if (ar.responseModel.IsSuccess)
            {
                TokenData token = JsonConvert.DeserializeObject <TokenData>(ar.responseModel.Data);
                if (token.IsValidUser)
                {
                    OwinContextSignIn(token, model.UserName);
                }


                return(RedirectToLocal(returnUrl));
            }
            else if (!ar.responseModel.IsSuccess)
            {
                //var errorResponseData = JsonConvert.DeserializeObject<OperationResult>(ar.responseModel.Data);
                //if (string.IsNullOrEmpty(errorResponseData.Message))
                //    message = "Login failed.";
                //else
                //    message = errorResponseData.Message;
                message = "Login failed";
                ModelState.AddModelError("", message);
            }


            ViewBag.Message = message;



            return(View(model));
        }