Ejemplo n.º 1
0
        public static User Create(
            IUserValidator userValidator,
            IUserPasswordService userPasswordService,
            string email,
            string displayName,
            string plainPassword,
            string postalCode,
            int timeZoneId)
        {
            AsyncHelper.RunSync(() => userValidator.ValidateAsync(null, email, displayName, plainPassword, postalCode));

            byte[] passwordHash;
            byte[] passwordSalt;
            userPasswordService.CreateHash(plainPassword, out passwordHash, out passwordSalt);

            var user = new User
            {
                Id             = Guid.NewGuid(),
                Email          = email,
                DisplayName    = displayName,
                PasswordHash   = passwordHash,
                PasswordSalt   = passwordSalt,
                PostalCode     = postalCode,
                UserTimeZoneId = timeZoneId
            };

            return(user);
        }
Ejemplo n.º 2
0
        public ApplicationUser CreateUser(ApplicationUser user)
        {
            byte[] passwordHash;
            byte[] passwordSalt;
            _userPasswordService.CreateHash(user.Password, out passwordHash, out passwordSalt);

            var userEntity = new ApplicationUserEntity
            {
                FirstName    = user.FirstName,
                LastName     = user.LastName,
                Username     = user.Username,
                PasswordHash = passwordHash,
                PasswordSalt = passwordSalt,
                IsActive     = true
            };

            userEntity.Roles = user.Roles.Select(r =>
                                                 new ApplicationUserRoleEntity
            {
                ApplicationUserId = userEntity.Id,
                ApplicationRoleId = r.ApplicationRoleId
            }).ToList();

            var result = _userRepository.Insert(userEntity);

            return(_mapper.Map <ApplicationUser>(result));
        }
Ejemplo n.º 3
0
            public async Task <Unit> Handle(RegisterUserCommand request, CancellationToken cancellationToken)
            {
                byte[] passwordHash;
                byte[] passwordSalt;
                _passwordService.CreateHash(request.Password, out passwordHash, out passwordSalt);
                var entity = new User
                {
                    Email        = request.Email,
                    DisplayName  = request.DisplayName,
                    PasswordHash = passwordHash,
                    PasswordSalt = passwordSalt
                };

                await _repository.Insert(entity, cancellationToken);

                return(Unit.Value);
            }