public LoggerController( ICacheManager cacheManager, ILoggerAppService loggerappservice, IJobGroupAppService jobgroupappservice ) { _LoggerAppService = loggerappservice; _JobGroupAppService = jobgroupappservice; }
public async Task <IActionResult> Login( [FromBody] UserViewModel usuario, [FromServices] TokenConfigurations tokenConfiguration, [FromServices] SignConfigurationToken signinConfiguration, [FromServices] IUserAppService usuarioAppService, [FromServices] ILoggerAppService loggerService) { if (usuario is null || !ModelState.IsValid) { return(BadRequest(ModelState)); } var objRetorno = new BaseViewModel <TokenViewModel>(); var viewModel = _mapper.Map <UserDomain>(usuario); var userBase = await usuarioAppService.ValidarUsuarioAsync(viewModel); if (userBase != null) { var identity = new ClaimsIdentity( new GenericIdentity(userBase.Login, "Login"), new[] { new Claim(JwtRegisteredClaimNames.Jti, userBase.UserId.ToString()), new Claim(JwtRegisteredClaimNames.UniqueName, userBase.Email), new Claim("CompanyId", userBase.CompanyId.ToString()) } ); var dateCreate = DateTime.Now; var dateExpired = dateCreate + TimeSpan.FromDays(tokenConfiguration.ExpireIn); var handler = new JwtSecurityTokenHandler(); var securityToken = handler.CreateToken(new SecurityTokenDescriptor { Issuer = tokenConfiguration.Issuer, Audience = tokenConfiguration.Audience, Subject = identity, NotBefore = dateCreate, Expires = dateExpired, SigningCredentials = new SigningCredentials( new SymmetricSecurityKey( Encoding.UTF8.GetBytes(tokenConfiguration.SigningKey)), SecurityAlgorithms.HmacSha256 ) }); var token = handler.WriteToken(securityToken); objRetorno.ObjetoDeRetorno = new TokenViewModel() { UsuarioId = userBase.UserId, Nome = userBase.Name, Email = userBase.Email, Autenticado = true, Criacao = dateCreate, Expira = dateExpired, Token = token, }; #region Logger loggerService.SaveLoggerSuccess(new domain.core.Entity.Log.LoggerDomain { objects = JsonConvert.SerializeObject(objRetorno.ObjetoDeRetorno), token = objRetorno.ObjetoDeRetorno.Token, userId = objRetorno.ObjetoDeRetorno.UsuarioId }); #endregion return(Ok(objRetorno)); } return(Unauthorized()); }
public ProductController(IMapper mapper, ILoggerAppService loggerService, IMessaging messages) { _mapper = mapper; this.loggerService = loggerService; this.messages = messages; }