public IActionResult Login( [FromServices] SigningConfigurations signingConfigurations, [FromServices] TokenConfigurations tokenConfigurations, [FromBody] LoginEntidade user) { try { var claims = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("Cpf", user.Cpf), new KeyValuePair <string, string>("Admin", true.ToString()), new KeyValuePair <string, string>("Nome", "Rony Moura") }; var token = AuthenticationToken.Generate(signingConfigurations, tokenConfigurations, user.Cpf, claims); return(Ok(new { token.AccessToken, token.Authenticated, token.Created, token.Expiration, Admin = true })); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public ActionResult Post( [FromServices] SigningConfigurations signingConfigurations, [FromServices] TokenConfigurations tokenConfigurations, [FromBody] UsuarioLogin dados) { try { var usuario = new UsuarioProxy().Login(dados.Email, dados.Senha); var claims = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("Oid", usuario.OID_USUARIO.ToString()), new KeyValuePair <string, string>("Email", usuario.TXT_EMAIL) }; var token = AuthenticationToken.Generate(signingConfigurations, tokenConfigurations, usuario.OID_USUARIO.ToString(), claims); return(Json(new { token.AccessToken, token.Authenticated, token.Created, token.Expiration, token.Message })); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IActionResult Login( [FromServices] SigningConfigurations signingConfigurations, [FromServices] TokenConfigurations tokenConfigurations, [FromBody] dynamic user) { try { string cpf = user.Cpf.Value; string senha = user.Senha.Value; var usuario = new UsuarioProxy().BuscarPorLoginSenha(cpf, senha); if (usuario != null) { var dadosPessoais = new DadosPessoaisProxy().BuscarPorCdPessoa(usuario.CD_PESSOA.Value).First(); var claims = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("Cpf", usuario.USR_LOGIN), new KeyValuePair <string, string>("CdPessoa", usuario.CD_PESSOA.ToString()), new KeyValuePair <string, string>("Admin", usuario.USR_ADMINISTRADOR), new KeyValuePair <string, string>("SqContratoTrabalho", dadosPessoais.SQ_CONTRATO_TRABALHO.ToString()) }; return(Json(AuthenticationToken.Generate(signingConfigurations, tokenConfigurations, usuario.USR_LOGIN, claims))); } else { throw new Exception("Matrícula ou senha incorretos!"); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IActionResult LoginV3( [FromServices] SigningConfigurations signingConfigurations, [FromServices] TokenConfigurations tokenConfigurations, [FromBody] dynamic user) { try { string cpf = user.Cpf.Value; string senha = user.Senha.Value; var usuario = new UsuarioProxy().BuscarPorLoginSenha(cpf, senha); if (usuario != null) { var grupo = new UsuarioGrupoProxy().BuscarPorUsuario(usuario.USR_CODIGO); bool pensionista = grupo != null && grupo.GRP_CODIGO == 32 ? true : false; string sqContratoTrabalho; if (pensionista) { var processo = new ProcessoBeneficioProxy().BuscarPorCdPessoa(usuario.CD_PESSOA.Value); sqContratoTrabalho = processo.SQ_CONTRATO_TRABALHO.ToString(); } else { var dadosPessoais = new DadosPessoaisProxy().BuscarPorCdPessoa(usuario.CD_PESSOA.Value).First(); sqContratoTrabalho = dadosPessoais.SQ_CONTRATO_TRABALHO.ToString(); } var claims = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("Cpf", usuario.USR_LOGIN), new KeyValuePair <string, string>("CdPessoa", usuario.CD_PESSOA.ToString()), new KeyValuePair <string, string>("Admin", usuario.USR_ADMINISTRADOR), new KeyValuePair <string, string>("SqContratoTrabalho", sqContratoTrabalho), new KeyValuePair <string, string>("Pensionista", pensionista.ToString()) }; var token = AuthenticationToken.Generate(signingConfigurations, tokenConfigurations, usuario.USR_LOGIN, claims); return(Json(new { token.AccessToken, token.Authenticated, token.Created, token.Expiration, token.Message, pensionista })); } else { throw new Exception("Matrícula ou senha incorretos!"); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public void WhenGenerating_NothingIsEmpty() { var token = AuthenticationToken.Generate("Race184", "Judge001"); Assert.That(token.RaceId, Is.EqualTo("Race184")); Assert.That(token.JudgeId, Is.EqualTo("Judge001")); Assert.That(token.Token, Is.Not.Empty.Or.Null); }
public JudgeDto Authorize(string raceId, AuthorizeRequestDto authorization) { if (string.IsNullOrEmpty(raceId)) { throw new ArgumentNullException("Missing RaceId"); } if (string.IsNullOrEmpty(authorization.ConnectCode)) { throw new ArgumentNullException("Missing ConnectCode"); } if (string.IsNullOrEmpty(authorization.JudgeId)) { throw new ArgumentNullException("Missing JudgeId"); } if (string.IsNullOrEmpty(authorization.JudgeName)) { throw new ArgumentNullException("Missing JudgeName"); } var judgesRepository = repositorySetProvider.GetRepositorySet(raceId).Judges; var judgesDevice = judgesRepository.FindConnectCode(authorization.ConnectCode); if (judgesDevice == null) { throw new ArgumentOutOfRangeException("Unknown ConnectCode"); } ModelJudge judge = judgesRepository.FindJudge(authorization.JudgeId); if (judge == null) { judge = new ModelJudge(); judge.JudgeId = authorization.JudgeId; judge.Name = authorization.JudgeName; judgesRepository.SaveJudge(judge); } judgesDevice.AuthenticationToken = AuthenticationToken.Generate(raceId, judge.JudgeId).ToString(); judgesDevice.JudgeId = judge.JudgeId; judgesRepository.SaveJudgeDevice(judgesDevice); JudgeDto judgeDto = new JudgeDto(); judgeDto.JudgeId = judge.JudgeId; judgeDto.JudgeName = judge.Name; judgeDto.IsAdmin = judge.IsAdmin; judgeDto.DeviceIds = new List <string>(); foreach (var judgeDevice in judgesRepository.FindJudgesDevices(judge.JudgeId)) { judgeDto.DeviceIds.Add(judgeDevice.DeviceId); } return(judgeDto); }
public IActionResult SelecionarMatricula( [FromServices] SigningConfigurations signingConfigurations, [FromServices] TokenConfigurations tokenConfigurations, string matricula) { try { bool pensionista = false; var usuario = new UsuarioProxy().BuscarPorCPF(Cpf); var contratoTrabalho = new ContratoTrabalhoProxy().BuscarPorCpfComPlanoAtivo(Cpf).First(x => x.NR_REGISTRO == matricula); var cdPessoa = contratoTrabalho.CD_PESSOA; var sqContratoTrabalho = contratoTrabalho.SQ_CONTRATO_TRABALHO; var processo = new ProcessoBeneficioProxy().BuscarPorCdPessoa(cdPessoa); if (processo != null) { pensionista = true; sqContratoTrabalho = processo.SQ_CONTRATO_TRABALHO.Value; } var claims = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("Cpf", Cpf), new KeyValuePair <string, string>("CdPessoa", cdPessoa.ToString()), new KeyValuePair <string, string>("Admin", Admin ? "S" : "N"), new KeyValuePair <string, string>("SqContratoTrabalho", sqContratoTrabalho.ToString()), new KeyValuePair <string, string>("Pensionista", pensionista.ToString()) }; var token = AuthenticationToken.Generate(signingConfigurations, tokenConfigurations, Cpf, claims); return(Ok(new { token.AccessToken, Pensionista = pensionista })); } catch (Exception ex) { return(BadRequest(ex.Message)); } }