public NotificationCollection SaveWaiter(Waiter waiter)
        {
            var newPassword = string.Empty;

            if (waiter.IsTransient())
            {
                newPassword        = passwordGenerator.NewPassword();
                waiter.UserAccount = UserAccount.Create(waiter.EmailAddress, newPassword);
                waiter.UserAccount.EncrypPassword(passwordEncryptor);
            }
            else
            {
                var existingAccount = repository.FindById <Waiter>(waiter.Id);
                waiter.UserAccount = existingAccount.UserAccount;
                //Saving a waiter must not overwrite their shifts with null
                waiter.Shifts = existingAccount.Shifts;
            }

            var result = repository.Save(waiter);

            //If a new waiter was successfully saved
            if (!result.HasErrors() && newPassword.IsNotNullOrEmpty())
            {
                var msg = string.Format("You have been registered on Shifter. Your password has been set to {0}. You should change it to something you will remember after logging in.", newPassword);
                //result += EmailManager.SendEmail(waiter.EmailAddress, Config.FromEmailAddress, "Shifter registration", msg);
                MessagePublisher.PublishComsMessage(msg, "Shifter registration", waiter.EmailAddress);
            }

            return(result);
        }
        public NotificationCollection SaveStaff(Staff staff, UserAccount userAccount, bool emailAddressIsActive = true)
        {
            var newPassword = passwordGenerator.NewPassword();
            var staffToSave = staff.IsTransient() ? CreateAccount(staff, userAccount, newPassword) : UpdateAccount(staff);

            //Because personal details is on the user account for the domain model and on the aggregate for the dto these need to be updated explicitly
            staffToSave.UserAccount.UpdatePersonalDetails(userAccount);

            var result = repository.Save(staffToSave);

            if (!result.HasErrors())
            {
                result += new Notification("Staff saved successfully.", NotificationSeverity.Information);

                if (!staffToSave.WelcomeEmailSent && emailAddressIsActive)
                {
                    result += SaveWelcomeEmail(staffToSave, newPassword);

                    staffToSave.UserAccount.Password = newPassword;
                    staffToSave.UserAccount.EncrypPassword(passwordEncryptor);
                    staffToSave.WelcomeEmailSent = true;

                    result += repository.Save(staffToSave);
                }
            }

            return(result);
        }
Example #3
0
        public NotificationCollection ResetPassword(int userAccountId)
        {
            var result = NotificationCollection.CreateEmpty();

            var userAccount = repository.FindById <UserAccount>(userAccountId);

            if (userAccount.IsNotNull())
            {
                var newPassword = passwordGenerator.NewPassword();
                userAccount.Password = newPassword;
                userAccount.EncrypPassword(passwordEncryptor);

                result += repository.Save(userAccount);

                if (!result.HasErrors())
                {
                    var message = repository.FindBy <EmailTemplate>(e => e.TemplateName == Constants.EmailTemplates.PasswordReset).FirstOrDefault();

                    message.Body = message.Body.Replace(Constants.EmailTemplatePlaceHolders.Password, newPassword);
                    message.Body = message.Body.Replace(Constants.EmailTemplatePlaceHolders.Name, userAccount.FirstName);
                    message.Body = message.Body.Replace(Constants.EmailTemplatePlaceHolders.Username, userAccount.Username);

                    result += repository.Save(EmailNotification.Create(message.Subject, message.Body, SharedConfig.FromSupportEmailAddress, userAccount.EmailAddress));
                }
                if (!result.HasErrors())
                {
                    result += new Notification("Password reset successful.", NotificationSeverity.Information);
                }
            }

            return(result);
        }
Example #4
0
        public void EnsureResetPasswordInvokesPasswordGeneratorNewPasswordOperation()
        {
            var waiter = new Waiter
            {
                UserAccount = new UserAccount
                {
                    Password = "******",
                    Salt     = "salt"
                }
            };

            A.CallTo(() => repository.FindById <Waiter>(1))
            .Returns(waiter);

            waiterService.ResetPassword(1);

            A.CallTo(() => passwordGenerator.NewPassword())
            .MustHaveHappened(Repeated.Exactly.Once);
        }
        public NotificationCollection ResetPassword(int managerId)
        {
            var manager = repository.FindById <Manager>(managerId);

            var newPassword = passwordGenerator.NewPassword();

            manager.UserAccount.Password = newPassword;
            manager.UserAccount.EncrypPassword(passwordEncryptor);

            var result = repository.Save(manager);

            if (!result.HasErrors())
            {
                var message = repository.FindBy <EmailTemplate>(e => e.TemplateName == Constants.EmailTemplates.PasswordReset).FirstOrDefault();

                message.Body = message.Body.Replace(Constants.EmailTemplatePlaceHolders.Password, newPassword);
                message.Body = message.Body.Replace(Constants.EmailTemplatePlaceHolders.Name, manager.UserAccount.FirstName);
                message.Body = message.Body.Replace(Constants.EmailTemplatePlaceHolders.Username, manager.UserAccount.Username);

                result += repository.Save(EmailNotification.Create(message.Subject, message.Body, SharedConfig.FromSupportEmailAddress, manager.UserAccount.EmailAddress));
            }

            return(result);
        }
Example #6
0
        public void EnsureResetPasswordInvokesPasswordGeneratorNewPasswordOperation()
        {
            var waiter = new Staff
            {
                UserAccount = new UserAccount
                {
                    Password = "******",
                    Salt     = "salt"
                }
            };

            A.CallTo(() => repository.FindById <Staff>(1)).Returns(waiter);
            A.CallTo(() => repository.FindBy <EmailTemplate>(c => c == null)).WithAnyArguments().Returns(new List <EmailTemplate>()
            {
                new EmailTemplate()
                {
                    Body = ""
                }
            });

            staffDomainService.ResetPassword(1);

            A.CallTo(() => passwordGenerator.NewPassword()).MustHaveHappened(Repeated.Exactly.Once);
        }