Example #1
0
        public ActionResult <SGI_Pessoa> Get()
        {
            var currentUser = HttpContext.User;

            string cod = usersRepository.Claim(currentUser, ClaimTypes.Sid);

            if (!string.IsNullOrEmpty(cod))
            {
                SGI_Pessoa pessoa = pessoasRepository.GetById(long.Parse(cod));

                //SGI_Pessoa pessoa = pessoasRepository.dbSet.Include(x => x.SGI_Imobiliaria_Corretor)
                //                                           .Include(x => x.SGI_Imovel_Proprietario)
                //                                           .Include(x => x.SGI_Usuarios)
                //                                           .FirstOrDefault(x => x.COD_PESSOA == long.Parse(cod));

                //pessoa.SGI_Imobiliaria_Corretor
                //pessoa.SGI_Imovel_Proprietario
                //pessoa.SGI_Usuarios

                if (pessoa != null)
                {
                    return(Ok(pessoa));
                }
            }

            return(NotFound());
        }
Example #2
0
        private string BuildToken(SGI_Usuarios user)
        {
            if (user == null)
            {
                return("");
            }

            SGI_Pessoa pessoa = pessoasRepository.Get(x => x.COD_PESSOA == user.COD_PESSOA).FirstOrDefault();

            if (pessoa == null)
            {
                return("");
            }

            var secretKey         = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(settings.Token.Key));
            var signinCredentials = new SigningCredentials(secretKey, SecurityAlgorithms.HmacSha256);

            var claims = new[]
            {
                new Claim(ClaimTypes.Name, pessoa.NOME),
                new Claim(ClaimTypes.Email, user.USER_EMAIL),
                new Claim(ClaimTypes.Sid, pessoa.COD_PESSOA.ToString()),
                new Claim(ClaimTypes.WindowsAccountName, user.USER_NAME),
                new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
                new Claim(JwtRegisteredClaimNames.Sub, user.USER_NAME),
                new Claim(ClaimTypes.DateOfBirth, (pessoa.ANIVERSARIO.HasValue ? pessoa.ANIVERSARIO.Value.ToString("u"): DateTime.Now.ToString("u")))
            };

            var tokeOptions = new JwtSecurityToken(
                issuer: settings.Token.Issuer,
                audience: settings.Token.Issuer,
                claims: claims,
                expires: DateTime.Now.AddMinutes(30),
                signingCredentials: signinCredentials
                );

            return(new JwtSecurityTokenHandler().WriteToken(tokeOptions));
        }