Пример #1
0
        public async Task <IActionResult> SetUserJwtAsync([FromBody] LoginUiModel loginVm)
        {
            DateTime startDate;
            DateTime endDate;

            Log.Debug("---------------------");
            Log.Debug($"{startDate = DateTime.Now}");
            Log.Debug("---------------------");

            var registeredUser = await _inquiryUserProcessor.GetUserAuthJwtTokenByLoginAndPasswordAsync(loginVm.Login,
                                                                                                        HashHelper.Sha512(loginVm.Password + loginVm.Login));


            Log.Debug("---------------------");
            Log.Debug($"{endDate = DateTime.Now}");
            Log.Debug("---------------------");
            Log.Debug($"{(endDate - startDate).Milliseconds}.msec");
            Log.Debug("---------------------");

            if (registeredUser == null)
            {
                return(BadRequest("WRONG_USER_PASS"));
            }

            if (!registeredUser.IsActivated)
            {
                return(BadRequest("NOT_ACTIVATED"));
            }

            Guid newRefreshedToken = Guid.NewGuid();

            Log.Debug("---------------------");
            Log.Debug($"{startDate = DateTime.Now}");
            Log.Debug("---------------------");

            registeredUser =
                await _updateUserProcessor.UpdateUserWithNewRefreshTokenAsync(registeredUser, newRefreshedToken);

            Log.Debug("---------------------");
            Log.Debug($"{endDate = DateTime.Now}");
            Log.Debug("---------------------");
            Log.Debug($"{(endDate - startDate).Milliseconds}.msec");
            Log.Debug("---------------------");


            var tokenValue = GenerateJwtToken(registeredUser);

            return(Ok(new AuthUiModel {
                Token = tokenValue, RefreshToken = newRefreshedToken.ToString()
            }));
        }
        public async Task <IActionResult> SetUserJwtAsync([FromBody] LoginUiModel loginVm)
        {
            var registeredUser = await _inquiryUserProcessor.GetUserAuthJwtTokenByLoginAndPasswordAsync(loginVm.Login,
                                                                                                        HashHelper.Sha512(loginVm.Password + loginVm.Login));

            if (registeredUser == null)
            {
                return(BadRequest("WRONG_USER_PASS"));
            }

            var tokenValue = GenerateJwtToken(registeredUser);

            return(Ok(new AuthUiModel {
                Token = tokenValue, Message = "CORRECT_USER_PASS"
            }));
        }