public void SeedClientApplicationData(ModelBuilder modelBuilder)
        {
            foreach (var clientApplication in ClientApplications)
            {
                var salt         = HashString.GetSalt();
                var hashPassword = HashString.Hash(clientApplication.ClientApplicationPassword, salt
                                                   , AuthorizationUtilConstants.IterationCountForHashing);
                var clientApplicationUtil = new ClientApplicationUtil()
                {
                    Id = ClientApplicationUtilId,
                    ClientApplicationId = clientApplication.Id,
                    SpecialValue        = salt,
                };

                clientApplication.ClientApplicationPassword = hashPassword;

                SeedDataUtil.SetCommonFields <ClientApplication, int>(clientApplication, LoggedUserId);
                SeedDataUtil.SetCommonFields <ClientApplicationUtil, int>(clientApplicationUtil, LoggedUserId);

                modelBuilder.Entity <ClientApplication>()
                .HasData(clientApplication);

                modelBuilder.Entity <ClientApplicationUtil>()
                .HasData(clientApplicationUtil);

                ClientApplicationUtilId++;
            }
        }
        public void SeedUserData(ModelBuilder modelBuilder)
        {
            foreach (var user in Users)
            {
                var salt         = HashString.GetSalt();
                var hashPassword = HashString.Hash(user.Password, salt
                                                   , AuthorizationUtilConstants.IterationCountForHashing);

                var userUtil = new UserUtil
                {
                    Id           = UserUtilId,
                    UserId       = user.Id,
                    SpecialValue = salt,
                };

                user.Password = hashPassword;

                SeedDataUtil.SetCommonFields <User, int>(user, LoggedUserId);
                SeedDataUtil.SetCommonFields <UserUtil, int>(userUtil, LoggedUserId);

                modelBuilder.Entity <User>()
                .HasData(user);

                modelBuilder.Entity <UserUtil>()
                .HasData(userUtil);

                UserUtilId++;
            }
        }
示例#3
0
        public Task <ClientApplication> CreateAsync(ClientApplicationRequest request)
        {
            return(CommonOperationAsync(async() =>
            {
                var result = Mapper.Map <ClientApplication>(request);

                var tempResult = await _uow.ClientApplications.GetByNameAsync(result.ClientApplicationName);
                tempResult.CheckUniqueValue(AuthorizationConstants.ClientApplicationName);

                tempResult = await _uow.ClientApplications.GetByCodeAsync(result.ClientApplicationCode);
                tempResult.CheckUniqueValue(AuthorizationConstants.ClientApplicationCode);

                var salt = HashString.GetSalt();
                var hashPassword = HashString.Hash(result.ClientApplicationPassword, salt,
                                                   AuthorizationUtilConstants.IterationCountForHashing);

                result.ClientApplicationPassword = hashPassword;

                _uow.ClientApplications.Add(result, GetLoggedInUserId());

                CreateClientApplicationUtil(result.Id, salt);

                await _uow.SaveChangesAsync();
                return result;
            }, new BusinessBaseRequest {
                MethodBase = MethodBase.GetCurrentMethod()
            }));
        }
        public Task <ClientApplication> UpdateClientApplicationPasswordAsync(int id, string clientApplicationPassword)
        {
            return(CommonOperationAsync(async() =>
            {
                var result = await GetByIdAsync(id);

                var salt = HashString.GetSalt();
                var hashPassword = HashString.Hash(clientApplicationPassword, salt,
                                                   IdentityUtilConstants.IterationCountForHashing);

                result.SecurityStamp = salt;
                result.ClientApplicationPassword = hashPassword;

                _uow.ClientApplications.Update(result, GetUserId());

                await _uow.SaveChangesAsync();
                return result;
            }, new BusinessBaseRequest {
                MethodBase = MethodBase.GetCurrentMethod()
            }));
        }
        public Task <User> UpdatePasswordAsync(int id, string password)
        {
            return(CommonOperationAsync(async() =>
            {
                var result = await GetByIdAsync(id);

                /** Hash password **/
                var salt = HashString.GetSalt();
                var hashPassword = HashString.Hash(password, salt, AuthorizationUtilConstants.IterationCountForHashing);

                result.Password = hashPassword;

                _uow.Users.Update(result, GetLoggedInUserId());

                await UpdateUserUtilAsync(id, salt);

                await _uow.SaveChangesAsync();
                return result;
            }, new BusinessBaseRequest {
                MethodBase = MethodBase.GetCurrentMethod()
            }));
        }