Пример #1
0
        public void CreateAccount(UserDto user)
        {
            if (user == null)
            {
                throw new ArgumentNullException();
            }
            if (user.Id != 0)
            {
                user.Id = 0;
            }
            if (user.Login == null)
            {
                throw new DtoValidationException("Set Login!");
            }
            if (user.Passwod == null)
            {
                throw new DtoValidationException("Set password!");
            }

            User   userToAdd = user.MapToDbEntity();
            string wallName  = Utils.WallThreadNameResolver.GetWallThreadName(userToAdd);

            //generate 128 bit salt
            userToAdd.PasswordSalt = _securityProvider.GenerateSalt(128 / 8);
            userToAdd.PasswordHash = _securityProvider.ComputeHash(user.Passwod, userToAdd.PasswordSalt);

            ExecuteNonQuery(uow => {
                uow.UserRepository.Create(userToAdd);
                uow.ThreadRepository.Create(new ConvThread {
                    Name = wallName, Moderator = userToAdd
                });                                                                                     //create wall
                uow.SaveChanges();
            });
        }