예제 #1
0
        public IActionResult Register([FromForm] RegistrationRequest?request)
        {
            if (IsLoggedIn)
            {
                return(ErrorRedirect("/", ALREADY_LOGGED_IN_ERROR));
            }

            try {
                ValidateNotNull(request?.Name, request?.Email, request?.Password, request?.PasswordConfirm);

                // This is no domain logic, but let's-help-the-user logic. It's fine in here.
                if (request !.Password != request.PasswordConfirm)
                {
                    throw new ManualValidationException("PasswordConfirm", "The passwords do not match.");
                }

                _userRegistrationService.CreateAuthUser(request.Name, request.Email, request.Password);
                return(SuccessRedirect("/", $"User '{request.Name}' is registered."));
            }
            catch (ManualValidationException e) {
                return(ErrorRedirect("/auth/register", e.Message));
            }
        }