Exemplo n.º 1
0
        //public MongoContext(string connectionString, string dbName)
        //{
        //    _client = new MongoClient(connectionString);
        //    _database = _client.GetDatabase(dbName);
        //}

        public MongoContextBase()
        {
            string connectionString = ConfigGetter.GetSectionFromJson("MongoSettings:ConnectionString");
            string dbName           = ConfigGetter.GetSectionFromJson("MongoSettings:DbName");

            _client   = new MongoClient(connectionString);
            _database = _client.GetDatabase(dbName);
        }
Exemplo n.º 2
0
        public async Task <UserAccountBO> CheckUserAccount(string email, string password)
        {
            var         encryptedPassword = Crypto.Encrypt(password, ConfigGetter.GetSectionFromJson("CryptoKey"));
            Task <User> userTask          = _userRepository.GetAsync(u => u.Email == email && u.Password == encryptedPassword);
            User        user = await userTask;

            if (user != null)
            {
                return(_mapper.Map <UserAccountBO>(user));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 3
0
        public string Authenticate(UserAccountBO userAccount)
        {
            var tokenHandler    = new JwtSecurityTokenHandler();
            var key             = Encoding.ASCII.GetBytes(ConfigGetter.GetSectionFromJson("SecretKey"));
            var tokenDescriptor = new SecurityTokenDescriptor
            {
                Subject = new ClaimsIdentity(new Claim[]
                {
                    new Claim(ClaimTypes.Email, userAccount.Email),
                    new Claim(ClaimTypes.Role, UserRoleNames.GetRoleName(userAccount.RoleId))
                }),
                Expires            = DateTime.UtcNow.AddDays(Convert.ToInt32(ConfigGetter.GetSectionFromJson("TokenExpiresDay"))),
                SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
            };
            var token    = tokenHandler.CreateToken(tokenDescriptor);
            var tokenStr = tokenHandler.WriteToken(token);

            return(tokenStr);
        }
Exemplo n.º 4
0
 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 {
     optionsBuilder.UseSqlServer(ConfigGetter.GetSectionFromJson(_connectionStringName));
 }
Exemplo n.º 5
0
 public string Decrypt(CryptoModel model)
 {
     return(Crypto.Decrypt(model.Encrypted, ConfigGetter.GetSectionFromJson("CryptoKey")));
 }