예제 #1
0
        public async Task SignUpAsync(string email, string password)
        {
            var userDomain = (User)null;

            if (Shared.UseSql)
            {
                userDomain = await _userEFRepository.GetAsync(email);
            }
            else
            {
                userDomain = await _userMongoRepository.GetAsync(email);
            }

            if (userDomain != null)
            {
                throw new NextDoorException(IdentityExceptionCode.EmailInUse,
                                            $"Email: '{email}' is already in use.");
            }

            var userDto = new UserDto(email, password);

            userDto.SetHashPassword(_passwordHasher);
            userDomain = _mapper.Map <UserDto, User>(userDto);

            if (Shared.UseSql)
            {
                await _userEFRepository.AddAsync(userDomain);
            }
            else
            {
                await _userMongoRepository.AddAsync(userDomain);
            }
        }
        public async Task HandleAsync(SignUpCmd command, ICorrelationContext context)
        {
            var userDomain = (User)null;

            if (Shared.UseSql)
            {
                userDomain = await _userEFRepository.GetAsync(command.Email);
            }
            else
            {
                userDomain = await _userMongoRepository.GetAsync(command.Email);
            }
            if (userDomain != null)
            {
                throw new NextDoorException(IdentityExceptionCode.EmailInUse,
                                            $"Email: '{command.Email}' is already in use.");
            }
            else
            {
                userDomain = new User(command.Email);
                userDomain.SetPassword(command.Password, _passwordHasher);
                if (Shared.UseSql)
                {
                    await _userEFRepository.AddAsync(userDomain);
                }
                else
                {
                    await _userMongoRepository.AddAsync(userDomain);
                }

                // Notify some other service that sign up successed
                await _busPublisher.PublishAsync(new SignUpSuccessEvent(userDomain.Email), context);
            }
        }