public void CreateUserReturnsUser()
        {
            var userEntity = new UserEntity();

            ExpectFactoryCalls();

            _mocks.ReplayAll();
            User user = _userFactory.CreateUser(userEntity, null);

            _mocks.VerifyAll();

            Assert.IsNotNull(user);
        }
Exemple #2
0
        public Task <JsonResult> GetUser(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "user")] HttpRequest req,
            [HttpHeader(Name = "Authorization")] HttpParam <string> authorization,
            CancellationToken cancellationToken)
        {
            return(exceptionFilter.FilterExceptions(async() =>
            {
                var(userId, _, _) = await auth.ValidateUser(authorization, cancellationToken);
                var consent = await consentStore.FetchConsent(userId, cancellationToken);
                consent = consent.Verify(userId, ignoreFhir: true);

                return new JsonResult(await userFactory.CreateUser(consent, jobId: null, cancellationToken));
            }));
        }
        public async Task RegisterAdminAsync(string username, string password)
        {
            var findUser = await context.Users
                           .FirstOrDefaultAsync(u => u.UserName == username);

            if (findUser != null)
            {
                throw new ArgumentException("User with this name already exist.");
            }
            var newAdmin = usersFactory.CreateUser(username, password, 2);

            newAdmin.Password = hasher.Hasher(newAdmin.Password);
            this.context.Users.Add(newAdmin);
            await this.context.SaveChangesAsync();
        }
Exemple #4
0
        public async Task AddUserAsync(UserDataStructure userDataStructure)
        {
            var user = (await _usersRepository.GetWithExpressionAsync(x => x.UserName == userDataStructure.UserName)).SingleOrDefault();

            if (user != null)
            {
                throw new BusinessLogicException("User already exists");
            }

            user = _userFactory.CreateUser(userDataStructure);
            ValidatePasswords(userDataStructure.Password, userDataStructure.ConfirmPassword);
            user.SetPassword(userDataStructure.Password);

            await _usersRepository.CreateAsync(user);

            var userCratedEvent = new UserChangedEvent(user.Id, user.UserName, user.Email,
                                                       user.Roles.Select(x => x.ToString()), user.FirstName, user.SecondName, user.BirthDate, user.ModifyDate,
                                                       new AddressEventData()
            {
                City       = user.Address.City,
                PostalCode = user.Address.City,
                Street     = user.Address.Street
            });

            await _busPublisher.PublishAsync(userCratedEvent);
        }
Exemple #5
0
        public void inputValidationCheck()
        {
            if (Regex.IsMatch(emailBox.Text, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"))
            {
                user = new UserFactory();
                User newUser = user.CreateUser("name", 1, UserType.Standard, emailBox.Text);

                if (emailBox.Text != null)
                {
                    if (userSelectBox.SelectedIndex == 1)
                    {
                        this.NavigationService.Navigate(new joinSessionFrame(newUser));
                    }
                    else if (userSelectBox.SelectedIndex == 0)
                    {
                        this.NavigationService.Navigate(new tutorPage(newUser));
                    }
                    else
                    {
                        MessageBox.Show("You must select a user type!");
                    }
                }
            }
            else
            {
                MessageBox.Show("You Must Enter a vaild Email!");
            }
        }
Exemple #6
0
        public Task <JsonResult> WithingsAuth(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "withings/auth")] HttpRequest req,
            [HttpBody(Required = true)] HttpParam <AuthDto> authDto,
            [HttpHeader(Name = "Authorization")] HttpParam <string> authorization,
            CancellationToken cancellationToken)
        {
            return(exceptionFilter.FilterExceptions(async() =>
            {
                var withingsAccessCode = authDto.Value.WithingsAccessCode;
                var withingsRedirectUri = authDto.Value.WithingsRedirectUri;

                var(userId, _, _) = await auth.ValidateUser(authorization, cancellationToken);
                var consent = await consentStore.FetchConsent(userId, cancellationToken);

                var newWithingsUserId = await withingsClient.CreateAccount(userId, withingsAccessCode, withingsRedirectUri, cancellationToken);

                if (consent == null || !consent.ExternalIds.TryGetValue(withingsToFhirConverter.System, out var withingsUserId) || withingsUserId != newWithingsUserId)
                {
                    consent ??= ConsentFactory.WithId(userId);
                    consent.ExternalIds[withingsToFhirConverter.System] = newWithingsUserId;
                    await consentStore.WriteConsent(consent, cancellationToken);
                }

                return new JsonResult(await userFactory.CreateUser(consent, jobId: null, cancellationToken));
            }));
        }
        public async Task <IHttpActionResult> Register(UserIncomingContract userIncomingContract)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest());
                }
                var user = _userFactory.CreateUser(userIncomingContract.UserName,
                                                   userIncomingContract.Password,
                                                   userIncomingContract.Email);
                await user.SaveAsync();

                return(Ok());
            }
            catch (UserRegisterException)
            {
                return(BadRequest());
            }
            catch (UserNotFoundException)
            {
                return(NotFound());
            }
            catch (Exception ex)
            {
                _logger.Error("Register method", ex);
                return(InternalServerError());
            }
        }
        static void RegisterUser(IUserFactory userFactory)
        {
            IUser user = userFactory.CreateUser("Max", "Planck");

            IUserIdentity id = userFactory.CreateIdentity();

            user.SetIdentity(id);
        }
Exemple #9
0
        void should_create_user(IUserFactory factory)
        {
            User user = factory.CreateUser("User Name", 1980);

            Assert.True(user.Id != Guid.Empty);
            Assert.Equal("User Name", user.Name);
            Assert.Equal(1980, user.YearOfBirth);
        }
Exemple #10
0
        public static User CreateUser(string firstName, string lastName, string email)
        {
            if (Factory == null)
            {
                return(null);
            }

            return(Factory.CreateUser(firstName, lastName, email));
        }
Exemple #11
0
 void should_throw_if_year_of_birth_is_out_of_range(IUserFactory factory)
 {
     int[] outOfRangeYears = { 1899, DateTime.UtcNow.Year + 1 };
     foreach (int outOfRangeYear in outOfRangeYears)
     {
         Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                     factory.CreateUser("name", outOfRangeYear));
     }
 }
        private async Task <bool> CreateNewUserInformation()
        {
            User?user;
            bool isValid;

            IsBusy = true;
            bool isCreated = false;;

            //AddConfirmPasswordValidation(Password);
            isValid = ValidateEntries();

            if (isValid)
            {
                // Copy to Entry Model
                RegisterModel = CopyValuesToRegisterModel(RegisterModel);

                // Check using email, if not exist create

                user = await _UserDataStore.GetUserByEmail(RegisterModel.Email);

                if (user == null)
                {
                    user = _UserFactory.CreateUser(
                        FullName: RegisterModel.FullName,
                        BirthDate: RegisterModel.BirthDate,
                        Password: RegisterModel.Password,
                        PhoneNumber: RegisterModel.PhoneNumber,
                        Email: RegisterModel.Email
                        );

                    isCreated = _UserDataStore.AddItem(user);
                    if (isCreated)
                    {
                        await App.ApplicationManager.SetCredentialsInStorage(user);

                        await App.ApplicationManager.SetCurrentUserDataFromSecureStorage();
                    }
                    else
                    {
                        // Error, cant add
                        //  await Application.Current.MainPage.Navigation.PushAsync(new LoginPage());
                        // Pop Message of error.
                    }
                }
                else
                {
                    // Exist, should go to login page
                    //  await Application.Current.MainPage.Navigation.PushAsync(new LoginPage());
                    // Pop Message Already have an account.
                }
            }

            IsBusy = false;
            return(isCreated);
        }
 public async Task CreateAsync(string username, string password, string role)
 {
     if (_context.Users.Any(user => user.UserName == username))
     {
         // To implement properly
         throw new ArgumentException(Constants.UserExists);
     }
     else
     {
         await _factory.CreateUser(username, password, role);
     }
 }
Exemple #14
0
 public UserType GetUser(long userId)
 {
     using (var myAdapter = PersistenceLayer.GetDataAccessAdapter())
     {
         var linqMetaData = new LinqMetaData(myAdapter);
         var userEntity   =
             linqMetaData.User.WithPath(prefetchPath => prefetchPath.Prefetch(u => u.UserLogin)).SingleOrDefault(
                 u => u.UserId == userId);
         if (userEntity == null)
         {
             throw new ObjectNotFoundInPersistenceException <User>();
         }
         return(_userFactory.CreateUser(userEntity, _addressRepository.GetAddress(userEntity.HomeAddressId)));
     }
 }
 public void RegisterUser(string username, string firstname, string familyname)
 {
     using (var transaction = new TransactionScope()) {
         var user = userFactory.CreateUser(
             new UserName(username),
             new FullName(firstname, familyname)
             );
         if (userService.IsDuplicated(user))
         {
             throw new Exception("重複しています");
         }
         else
         {
             userRepository.Save(user);
         }
         transaction.Complete();
     }
 }
Exemple #16
0
        public IActionResult Register([FromBody] string request)
        {
            if (!ModelState.IsValid)
            {
                return(new UnprocessableEntityObjectResult(ModelState));
            }

            var obj      = JObject.Parse(request);
            int userType = (int)obj["SystemUserTypeNo"];

            var user = _userFactory.CreateUser(userType, request);

            if (user == null)
            {
                return(BadRequest("User already exists"));
            }

            _repository.UserRepository.CreateUser(user);


            try
            {
                _repository.Save();
            }
            catch (Exception)
            {
                return(Ok(
                           new RegisterResponseDTO
                {
                    Success = false,
                    Message = "User not created."
                }
                           ));
            }

            return(Ok(
                       new RegisterResponseDTO
            {
                Success = true,
                Message = "User created successfully"
            }
                       ));
        }
Exemple #17
0
 public void RegisterUser(string username, string firstname, string familyname)
 {
     try {
         var user = userFactory.CreateUser(
             new UserName(username),
             new FullName(firstname, familyname)
             );
         if (userService.IsDuplicated(user))
         {
             throw new Exception("重複しています");
         }
         else
         {
             uow.UserRepository.Save(user);
         }
         uow.Commit();
     } catch {
         uow.Rollback();
         throw;
     }
 }
        public IHttpActionResult Post(UserWriteModel model)
        {
            if (string.IsNullOrWhiteSpace(model.UserName))
            {
                return(BadRequest("No username provided."));
            }

            if (string.IsNullOrWhiteSpace(model.Email))
            {
                return(BadRequest("No email provided."));
            }

            var user = _userFactory.CreateUser(model.UserName, model.FirstName, model.LastName, model.Email, model.Password);

            _userMapper.Map(model, user);

            _userRepository.Save(user);

            var result = Mapper.Map <UserReadModel>(user);

            return(CreatedAtRoute("GetUser", new { userId = user.Id }, result));
        }
Exemple #19
0
        public Task <UserModel> Handle(CreateUserCommand request, CancellationToken cancellationToken)
        {
            User user;

            using (var transaction = new TransactionScope())
            {
                user = _factory.CreateUser(
                    new UserName(request.UserName),
                    new FullName(request.FirstName, request.FamilyName)
                    );

                if (_service.IsDuplicated(user))
                {
                    throw new DomainException("重複しています");
                }

                _repository.Save(user);
                transaction.Complete();
            }

            return(Task.FromResult(new UserModel(user)));
        }
Exemple #20
0
 static void RegisterUser(IUserFactory userFactory)
 {
     ITicketHolder holder = userFactory.CreateUser();
 }
Exemple #21
0
        public void AddUser(SignUpViewModel signUpViewModel)
        {
            User zz = _userFactory.CreateUser(signUpViewModel);

            _dbContext.Users.Add(_userFactory.CreateUser(signUpViewModel));
        }
 public ActionResult Register(RegisterModel model)
 {
     IUser user = _userFactory.CreateUser(model.Username, model.Password);
        private IRegistrantUser CreateUser(string name, string password)
        {
            IUser user = userFactory.CreateUser(name);

            return(userFactory.CreateRegistrantUser(user, password));
        }
        public async Task <IActionResult> OnPostConfirmationAsync()
        {
            if (MustAcceptsPrivacyPolicy && !Input.AcceptPrivacyPolicy)
            {
                var field = nameof(Input.AcceptPrivacyPolicy);

                ModelState.AddModelError($"{nameof(Input)}.{field}", T[$"{field}Error"] !);
            }

            if (MustAcceptsTermsOfService && !Input.AcceptTermsOfService)
            {
                var field = nameof(Input.AcceptTermsOfService);

                ModelState.AddModelError($"{nameof(Input)}.{field}", T[$"{field}Error"] !);
            }

            if (ModelState.IsValid)
            {
                var loginInfo = await SignInManager.GetExternalLoginInfoAsync();

                if (loginInfo == null)
                {
                    return(await RedirectToErrorPage("NoEmaiL", T["GithubEmailPrivateError"] !));
                }

                var email = loginInfo.Principal.FindFirst(ClaimTypes.Email)?.Value;

                if (string.IsNullOrWhiteSpace(email))
                {
                    throw new InvalidOperationException(T["GithubEmailPrivateError"]);
                }

                var user = await UserManager.FindByEmailAsync(email);

                if (user == null)
                {
                    user = userFactory.CreateUser(email);

                    var createResult = await UserManager.CreateAsync(user);

                    if (!createResult.Succeeded)
                    {
                        ModelState.AddModelErrors(createResult);
                        return(Page());
                    }
                }

                var addResult = await UserManager.AddLoginAsync(user, loginInfo);

                if (!addResult.Succeeded)
                {
                    ModelState.AddModelErrors(addResult);
                    return(Page());
                }

                await SignInManager.SignInAsync(user, false);

                return(RedirectTo(ReturnUrl));
            }

            return(Page());
        }
Exemple #25
0
 private void RegisterUser(IUserFactory userFactory)
 {
     ITicketHolder user = userFactory.CreateUser();
 }
        static void RegisterUser(IUserFactory userFactory)
        {
            IUser user = userFactory.CreateUser("Max", "Planck");

            Console.WriteLine("Hello {0}, welcome back!", user);
        }
Exemple #27
0
 void should_throw_if_name_is_empty(IUserFactory factory)
 {
     Assert.Throws <ArgumentException>(() => factory.CreateUser(string.Empty, 1980));
 }
Exemple #28
0
 void should_throw_if_name_is_not_provided(IUserFactory factory)
 {
     Assert.Throws <ArgumentNullException>(() => factory.CreateUser(null, 1980));
 }
Exemple #29
0
 public User Create(UserRegisterDto dto)
 {
     return(_userFactory.CreateUser(dto));
 }