public async Task HandleAsync(RequestPasswordResetCommand command)
        {
            FifthweekUser user = null;

            if (command.Username != null)
            {
                user = await this.userManager.FindByNameAsync(command.Username.Value);
            }

            if (command.Email != null && user == null)
            {
                user = await this.userManager.FindByEmailAsync(command.Email.Value);
            }

            if (user == null) // || !(await this.userManager.IsEmailConfirmedAsync(user.Id))
            {
                // Don't reveal that the user does not exist.
                return;
            }

            var token = await this.userManager.GeneratePasswordResetTokenAsync(user.Id);

            var callbackUrl = string.Format("{0}/#/sign-in/reset?userId={1}&token={2}", Core.Constants.FifthweekWebsiteBaseUrl, user.Id.EncodeGuid(), HttpUtility.UrlEncode(token));

            // Some email clients render whitespace.
            var lintedTemplate = this.htmlLinter.RemoveWhitespaceForHtmlEmail(EmailBodyTemplate);

            var emailBody = string.Format(lintedTemplate, callbackUrl, user.UserName).Replace("\n", "<br />");

            await this.userManager.SendEmailAsync(user.Id, "Reset Password", emailBody);
        }
        private void CreateBlogs(FifthweekUser creator)
        {
            var userBlogs    = new List <Blog>();
            var userChannels = new List <Channel>();
            var userQueues   = new List <Queue>();

            for (var blogIndex = 0; blogIndex < BlogsPerCreator; blogIndex++)
            {
                var blog = BlogTests.UniqueEntity(Random);

                if (blog.HeaderImageFile != null)
                {
                    var file = blog.HeaderImageFile;
                    file.UserId = creator.Id;

                    this.files.Add(file);
                }

                blog.Creator   = creator;
                blog.CreatorId = creator.Id;
                userBlogs.Add(blog);
                this.blogs.Add(blog);

                this.CreateChannels(blog, userChannels);
                this.CreateQueues(blog, userQueues);
                this.CreatePosts(blog, userChannels, userQueues);
            }
        }
Esempio n. 3
0
 public BlogEntitiesResult(FifthweekUser user, Blog blog, Channel channel, Queue queue)
 {
     this.User    = user;
     this.Blog    = blog;
     this.Channel = channel;
     this.Queue   = queue;
 }
Esempio n. 4
0
        public async Task ExecuteAsync(
            UserId userId,
            Username username,
            Email email,
            string exampleWork,
            Password password,
            DateTime timeStamp)
        {
            userId.AssertNotNull("userId");
            username.AssertNotNull("username");
            email.AssertNotNull("email");
            password.AssertNotNull("password");

            var passwordHash = this.userManager.PasswordHasher.HashPassword(password.Value);

            var user = new FifthweekUser
            {
                Id                  = userId.Value,
                UserName            = username.Value,
                Email               = email.Value,
                ExampleWork         = exampleWork,
                RegistrationDate    = timeStamp,
                LastSignInDate      = SqlDateTime.MinValue.Value,
                LastAccessTokenDate = SqlDateTime.MinValue.Value,
                SecurityStamp       = Guid.NewGuid().ToString(),
                PasswordHash        = passwordHash,
            };

            var parameters = new SqlGenerationParameters <FifthweekUser, FifthweekUser.Fields>(user)
            {
                Conditions = new[]
                {
                    WhereUsernameNotTaken,
                    WhereEmailNotTaken
                }
            };

            using (var transaction = TransactionScopeBuilder.CreateAsync())
            {
                using (var connection = this.connectionFactory.CreateConnection())
                {
                    var result = await connection.InsertAsync(parameters);

                    switch (result)
                    {
                    case 0: throw new RecoverableException("The username '" + username.Value + "' is already taken.");

                    case 1: throw new RecoverableException("The email address '" + email.Value + "' is already taken.");
                    }
                }

                await this.requestSnapshot.ExecuteAsync(userId, SnapshotType.Subscriber);

                transaction.Complete();
            }
        }
        private void CreateFreeAccess(FifthweekUser user)
        {
            var freeAccessIndicies = this.GenerageUniqueIndexes(this.blogs.Count, Random.Next(0, FreeAccessPerUser + 1));

            foreach (var blogIndex in freeAccessIndicies)
            {
                var freeAccess = new FreeAccessUser(this.blogs[blogIndex].Id, user.Email);
                this.freeAccessUsers.Add(freeAccess);
            }
        }
        private void CreateSubscriptions(FifthweekUser user)
        {
            var subscriptionIndicies = this.GenerageUniqueIndexes(this.channels.Count, Random.Next(0, SubscriptionsPerUser + 1));

            foreach (var channelIndex in subscriptionIndicies)
            {
                var subscription = new ChannelSubscription(this.channels[channelIndex].Id, null, user.Id, null, Random.Next(1, 500), DateTime.UtcNow.AddDays(-10 - Random.Next(0, 5)), DateTime.UtcNow.AddDays(Random.Next(1, 5)));
                this.subscriptions.Add(subscription);
            }
        }
Esempio n. 7
0
 private void EnsureUserHasRole(FifthweekUser user, IEnumerable <string> usersInRole, Guid roleId)
 {
     if (usersInRole.Contains(user.UserName) && user.Roles.All(_ => _.RoleId != roleId))
     {
         user.Roles.Add(new FifthweekUserRole
         {
             RoleId = roleId,
             UserId = user.Id
         });
     }
 }
 private void CreateRefreshTokens(FifthweekUser user)
 {
     for (int i = 0; i < RefreshTokensPerCreator; i++)
     {
         this.refreshTokens.Add(
             new RefreshToken(user.UserName,
                              "client_" + i,
                              "hash_" + user.Id + i,
                              DateTime.UtcNow.AddSeconds(-100),
                              DateTime.UtcNow, "protected_" + i));
     }
 }
        public async Task WhenRegisteringANewUser_ItShouldRequestSnapshotAfterUpdate()
        {
            await this.DatabaseTestAsync(async testDatabase =>
            {
                var trackingDatabase = new TrackingConnectionFactory(testDatabase);
                this.target          = new RegisterUserDbStatement(this.userManager.Object, trackingDatabase, this.requestSnapshot);

                var hashedPassword = RegistrationData.Password + "1";
                this.passwordHasher.Setup(v => v.HashPassword(RegistrationData.Password.Value)).Returns(hashedPassword);

                await testDatabase.TakeSnapshotAsync();

                this.requestSnapshot.VerifyConnectionDisposed(trackingDatabase);

                await this.target.ExecuteAsync(
                    UserId,
                    RegistrationData.Username,
                    RegistrationData.Email,
                    RegistrationData.ExampleWork,
                    RegistrationData.Password,
                    TimeStamp);

                this.requestSnapshot.VerifyCalledWith(UserId, SnapshotType.Subscriber);

                var expectedUser = new FifthweekUser
                {
                    Id                  = UserId.Value,
                    UserName            = RegistrationData.Username.Value,
                    Email               = RegistrationData.Email.Value,
                    ExampleWork         = RegistrationData.ExampleWork,
                    RegistrationDate    = TimeStamp,
                    LastSignInDate      = SqlDateTime.MinValue.Value,
                    LastAccessTokenDate = SqlDateTime.MinValue.Value,
                    PasswordHash        = hashedPassword,
                };

                return(new ExpectedSideEffects
                {
                    Insert = new WildcardEntity <FifthweekUser>(expectedUser)
                    {
                        Expected = actual =>
                        {
                            expectedUser.SecurityStamp = actual.SecurityStamp;
                            return expectedUser;
                        }
                    }
                });
            });
        }
        public async Task WhenRegisteringANewUserWithNoExampleWork_ItShouldAddTheUserToTheDatabase()
        {
            await this.DatabaseTestAsync(async testDatabase =>
            {
                this.target = new RegisterUserDbStatement(this.userManager.Object, testDatabase, this.requestSnapshot);

                var hashedPassword = RegistrationData.Password + "1";
                this.passwordHasher.Setup(v => v.HashPassword(RegistrationData.Password.Value)).Returns(hashedPassword);

                await testDatabase.TakeSnapshotAsync();

                await this.target.ExecuteAsync(
                    UserId,
                    RegistrationData.Username,
                    RegistrationData.Email,
                    null,
                    RegistrationData.Password,
                    TimeStamp);

                var expectedUser = new FifthweekUser
                {
                    Id                  = UserId.Value,
                    UserName            = RegistrationData.Username.Value,
                    Email               = RegistrationData.Email.Value,
                    ExampleWork         = null,
                    RegistrationDate    = TimeStamp,
                    LastSignInDate      = SqlDateTime.MinValue.Value,
                    LastAccessTokenDate = SqlDateTime.MinValue.Value,
                    PasswordHash        = hashedPassword,
                };

                return(new ExpectedSideEffects
                {
                    Insert = new WildcardEntity <FifthweekUser>(expectedUser)
                    {
                        Expected = actual =>
                        {
                            expectedUser.SecurityStamp = actual.SecurityStamp;
                            return expectedUser;
                        }
                    }
                });
            });
        }
 private CommentsResult.Item GetCommentsResultItem(Persistence.Comment comment, FifthweekUser user)
 {
     return(new CommentsResult.Item(
                new CommentId(comment.Id),
                new PostId(comment.PostId),
                new UserId(comment.UserId),
                new Username(user.UserName),
                new Shared.Comment(comment.Content),
                comment.CreationDate));
 }
        private void CreatePaymentInformation(FifthweekUser user, Guid previousUserId, int userIndex)
        {
            this.CreateAppendOnlyLedgerRecord(user.Id, previousUserId);

            // Add credit.
            var transactionReference2 = Guid.NewGuid();

            this.appendOnlyLedgerRecord.Add(
                new AppendOnlyLedgerRecord(
                    Guid.NewGuid(),
                    user.Id,
                    null,
                    DateTime.UtcNow,
                    -1200,
                    LedgerAccountType.Stripe,
                    LedgerTransactionType.CreditAddition,
                    transactionReference2,
                    Guid.NewGuid(),
                    "comment",
                    "stripe",
                    "taxamo"));

            this.appendOnlyLedgerRecord.Add(
                new AppendOnlyLedgerRecord(
                    Guid.NewGuid(),
                    user.Id,
                    null,
                    DateTime.UtcNow,
                    1000,
                    LedgerAccountType.FifthweekCredit,
                    LedgerTransactionType.CreditAddition,
                    transactionReference2,
                    Guid.NewGuid(),
                    "comment",
                    "stripe",
                    "taxamo"));

            this.appendOnlyLedgerRecord.Add(
                new AppendOnlyLedgerRecord(
                    Guid.NewGuid(),
                    user.Id,
                    null,
                    DateTime.UtcNow,
                    200,
                    LedgerAccountType.SalesTax,
                    LedgerTransactionType.CreditAddition,
                    transactionReference2,
                    Guid.NewGuid(),
                    "comment",
                    "stripe",
                    "taxamo"));

            this.calculatedAccountBalance.Add(new CalculatedAccountBalance(user.Id, LedgerAccountType.FifthweekCredit, DateTime.UtcNow.AddDays(-1), 1000));
            this.calculatedAccountBalance.Add(new CalculatedAccountBalance(user.Id, LedgerAccountType.Stripe, DateTime.UtcNow.AddDays(-1), -1100));
            this.calculatedAccountBalance.Add(new CalculatedAccountBalance(user.Id, LedgerAccountType.SalesTax, DateTime.UtcNow.AddDays(-1), 100));
            this.calculatedAccountBalance.Add(new CalculatedAccountBalance(user.Id, LedgerAccountType.FifthweekRevenue, DateTime.UtcNow.AddDays(-1), 10000));

            if (userIndex % 3 == 0)
            {
                this.creatorPercentageOverride.Add(
                    new CreatorPercentageOverride(
                        user.Id,
                        0.8m,
                        userIndex % 2 == 0 ? (DateTime?)null : DateTime.UtcNow.AddDays(userIndex - (Users / 2))));
            }

            this.uncommittedSubscriptionPayment.Add(
                new UncommittedSubscriptionPayment(user.Id, previousUserId, DateTime.Now.AddMinutes(-30), DateTime.Now, 10m, Guid.NewGuid()));
        }