Example #1
0
        public async Task <IActionResult> Login(UserSignDTO userSignDTO)
        {
            if (ModelState.IsValid)
            {
                JObject datasJson = await _userServices.Login(userSignDTO);

                if (datasJson["error"] is null)
                {
                    AuthorizationDTO authorization = JsonHelper.Deserialize <AuthorizationDTO>(datasJson.ToString());
                    UserClaimDTO     userClaim     = await _authenticationService.AcquireUserClaim(_serverAddresses.Addresses.FirstOrDefault(), authorization.access_token);

                    if (authorization is null || userClaim is null)
                    {
                        return(StatusCode(500));
                    }
                    var loginStatus = _mapper.Map <LoginStatusDTO>(userSignDTO);
                    _mapper.Map(userClaim, loginStatus);
                    _mapper.Map <AuthorizationDTO, LoginStatusDTO>(authorization, loginStatus);
                    return(Ok(new ResponseCtrMsg <LoginStatusDTO>(CtrResult.Success)
                    {
                        ResultObj = loginStatus
                    }));
                }
                else
                {
                    this._logger.LogInformation("User:"******",Login Control failed");
                    return(BadRequest("账号密码错误"));
                }
            }
            else
            {
                this._logger.LogInformation("The passed in model is empty");
                return(BadRequest(new ResponseCtrMsg <object>(CtrResult.Failure)
                {
                    message = "传入的模型为空"
                }));
            }
        }