コード例 #1
0
        public virtual async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                Guid?gamingGroupInvitation = null;
                if (!string.IsNullOrWhiteSpace(model.GamingGroupInvitationId))
                {
                    gamingGroupInvitation = new Guid(model.GamingGroupInvitationId);
                }

                var newUser = new NewUser
                {
                    EmailAddress            = model.EmailAddress.Trim(),
                    UserName                = model.UserName.Trim(),
                    Password                = model.Password,
                    GamingGroupInvitationId = gamingGroupInvitation
                };

                var registerNewUserResult = await _userRegisterer.RegisterUser(newUser);

                if (registerNewUserResult.Result.Succeeded)
                {
                    return(RedirectToAction(MVC.GamingGroup.ActionNames.Index, MVC.GamingGroup.Name));
                }
                AddErrors(registerNewUserResult.Result);
            }

            // If we got this far, something failed, redisplay form
            return(View(MVC.Account.Views.Register, model));
        }
コード例 #2
0
        public async Task ItCreatesANewUser()
        {
            await userRegisterer.RegisterUser(newUser);

            applicationUserManagerMock.AssertWasCalled(mock => mock.CreateAsync(
                                                           Arg <ApplicationUser> .Matches(appUser => appUser.UserName == newUser.UserName &&
                                                                                          appUser.Email == newUser.EmailAddress &&
                                                                                          appUser.EmailConfirmed),
                                                           Arg <string> .Is.Equal(newUser.Password)));
        }
コード例 #3
0
        public virtual async Task <HttpResponseMessage> RegisterNewUser(NewUserMessage newUserMessage)
        {
            var newUser = Mapper.Map <NewUserMessage, NewUser>(newUserMessage);

            var registerNewUserResult = await _userRegisterer.RegisterUser(newUser);

            if (registerNewUserResult.Result.Succeeded)
            {
                var authToken = _authTokenGenerator.GenerateAuthToken(registerNewUserResult.NewlyRegisteredUser.UserId, newUserMessage.UniqueDeviceId);
                var newlyRegisteredUserMessage = Mapper.Map <NewlyRegisteredUser, NewlyRegisteredUserMessage>(registerNewUserResult.NewlyRegisteredUser);
                newlyRegisteredUserMessage.AuthenticationToken = authToken.AuthenticationTokenString;
                newlyRegisteredUserMessage.AuthenticationTokenExpirationDateTime =
                    authToken.AuthenticationTokenExpirationDateTime;
                return(Request.CreateResponse(HttpStatusCode.OK, newlyRegisteredUserMessage));
            }

            return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, registerNewUserResult.Result.Errors.First()));
        }
コード例 #4
0
        public async Task ItDoesntSignInIfTheUserIsntCreatedSuccessfully()
        {
            newUser = new NewUser();
            IdentityResult result = new IdentityResult("an error");

            applicationUserManagerMock = MockRepository.GenerateMock <ApplicationUserManager>(userStoreMock, dataProtectionProviderMock);
            applicationUserManagerMock.Expect(mock => mock.CreateAsync(Arg <ApplicationUser> .Is.Anything, Arg <string> .Is.Anything))
            .Return(Task.FromResult <IdentityResult>(result));
            userRegisterer = new UserRegisterer(
                applicationUserManagerMock,
                firstTimeUserAuthenticatorMock,
                dataContextMock,
                signInManagerMock,
                eventTrackerMock,
                gamingGroupInviteConsumerMock);

            await userRegisterer.RegisterUser(newUser);

            firstTimeUserAuthenticatorMock.AssertWasNotCalled(mock => mock.CreateGamingGroupAndSendEmailConfirmation(
                                                                  Arg <ApplicationUser> .Is.Anything,
                                                                  Arg <TransactionSource> .Is.Anything));
        }
コード例 #5
0
        public async Task ItDoesntSignInIfTheUserIsntCreatedSuccessfully()
        {
            newUser = new NewUser();
            IdentityResult result = new IdentityResult("an error");

            applicationUserManagerMock = MockRepository.GenerateMock<ApplicationUserManager>(userStoreMock, dataProtectionProviderMock);
            applicationUserManagerMock.Expect(mock => mock.CreateAsync(Arg<ApplicationUser>.Is.Anything, Arg<string>.Is.Anything))
                .Return(Task.FromResult<IdentityResult>(result));
            userRegisterer = new UserRegisterer(
                applicationUserManagerMock, 
                firstTimeUserAuthenticatorMock, 
                dataContextMock, 
                signInManagerMock,
                eventTrackerMock,
                gamingGroupInviteConsumerMock);

            await userRegisterer.RegisterUser(newUser);

            firstTimeUserAuthenticatorMock.AssertWasNotCalled(mock => mock.CreateGamingGroupAndSendEmailConfirmation(
                Arg<ApplicationUser>.Is.Anything,
                Arg<TransactionSource>.Is.Anything));
        }