Example #1
0
        public bool PasswordReset(string emailAddress)
        {
            // get user based upon email address
            var user = _unitOfWork.UserRepository.Get(u => u.Email == emailAddress).FirstOrDefault();

            if (user != null)
            {
                // for use below with unhashed password
                var userDto = Mapper.Map <UserDto>(user);

                // generate new password from Random
                userDto.Password = CommonHelperAppService.RandomString(8);

                // Hash it. Hash it, real good!
                user.Password = CommonHelperAppService.HashPassword(userDto.Password);

                _unitOfWork.UserRepository.Update(user);
                _unitOfWork.Save();

                MailerService.SendPasswordResetEmail(userDto);

                return(true);
            }

            return(false);
        }
        // CRUD
        public long RegisterUserAccount(UserDto userDto, long userId)
        {
            // gen random string and hash
            var unhashedPassword = CommonHelperAppService.RandomString(8);

            userDto.Password = unhashedPassword;

            var user = Mapper.Map <User>(userDto);

            user.Password = HashPassword(unhashedPassword);

            _unitOfWork.UserRepository.Create(user);
            _unitOfWork.Save();


            // Mail
            MailerService.SendUserRegisteredEmail(userDto);

            // Audit
            _auditLogAppService.Audit(
                AppConstants.ActionTypeCreate,
                AppConstants.UserTableName,
                userId,
                user.Id);

            return(user.Id);
        }
        public void Should_Send_New_User_Email_with_Account_Password()
        {
            // Arrange
            var userDto = new UserDto
            {
                Email              = "*****@*****.**",
                Firstname          = "Test",
                Lastname           = "User",
                IsAccountLocked    = false,
                IsActive           = true,
                SystemAccessRoleId = 1,
                Password           = CommonHelperAppService.RandomString(8)
            };

            // Act
            MailerService.SendUserRegisteredEmail(userDto);

            // Assert
            //Assert.AreEqual(expected, result);
        }