public void RegisterUser(RegisterUserInput registerUser)
        {
            var existingUser = _userRepository.FirstOrDefault(u => u.EmailAddress == registerUser.EmailAddress);
            if (existingUser != null)
            {
                if (!existingUser.IsEmailConfirmed)
                {
                    SendConfirmationEmail(existingUser);
                    throw new UserFriendlyException("You registered with this email address before (" + registerUser.EmailAddress + ")! We re-sent an activation code to your email!");
                }

                throw new UserFriendlyException("There is already a user with this email address (" + registerUser.EmailAddress + ")! Select another email address!");
            }

            var userEntity = registerUser.MapTo<TaskeverUser>();
            userEntity.Password = new PasswordHasher().HashPassword(userEntity.Password);
            userEntity.GenerateEmailConfirmationCode();
            _userRepository.Insert(userEntity);
            SendConfirmationEmail(userEntity);
        }
        public JsonResult Register(RegisterUserInput input)
        {
            //TODO: Return better exception messages!
            //TODO: Show captcha after filling register form, not on startup!

            if (!ModelState.IsValid)
            {
                throw new UserFriendlyException("Your form is invalid!");
            }

            //TODO: Remove Recapthcha for testing??
            var recaptchaHelper = this.GetRecaptchaVerificationHelper();
            if (String.IsNullOrEmpty(recaptchaHelper.Response))
            {
                throw new UserFriendlyException("Captcha answer cannot be empty.");
            }

            var recaptchaResult = recaptchaHelper.VerifyRecaptchaResponse();
            if (recaptchaResult != RecaptchaVerificationResult.Success)
            {
                throw new UserFriendlyException("Incorrect captcha answer.");
            }

            input.ProfileImage = ProfileImageHelper.GenerateRandomProfileImage();

            _userAppService.RegisterUser(input);

            return Json(new MvcAjaxResponse { TargetUrl = Url.Action("ActivationInfo") });
        }