Beispiel #1
0
        public async Task <User> Register(string username, string password)
        {
            var userServiceModel = await _usersService.RegisterUser(username.ToLower()) ?? await _usersService.GetUser(username.ToLower());

            if (userServiceModel == null)
            {
                return(null);
            }

            if (!await _portfolioService.CreatePortfolio(userServiceModel.UserId))
            {
                return(null);
            }
            if (!await _bankService.CreateBankAndAccount(userServiceModel.UserId))
            {
                return(null);
            }

            var cipher = CryptoProvider.Encrypt(new CryptoProvider.Plain {
                Password = password
            });
            var user = new User
            {
                UserId   = userServiceModel.UserId,
                Username = userServiceModel.Email,
                Hash     = cipher.Hash,
                Salt     = cipher.Salt
            };

            _unitOfWork.AuthenticationRepository.Register(user);
            await _unitOfWork.CommitAsync();

            return(user);
        }