public RegisterStatus CreateAdminLogin([FromBody] RegisterDTO objRegister) { // RegisterStatus to return RegisterStatus objRegisterStatus = new RegisterStatus(); objRegisterStatus.status = "Registration Failure"; objRegisterStatus.isSuccessful = false; // Test for a strong password if (!UtilitySecurity.IsPasswordStrong(objRegister.password)) { objRegisterStatus.status = "The password is not strong enough."; objRegisterStatus.isSuccessful = false; return(objRegisterStatus); } // Do not run if we can connect to the current database if (CurrentVersion().isNewDatabase == false) { objRegisterStatus.isSuccessful = false; objRegisterStatus.status = "Cannot create the Admin account because the database is already set-up. Reload your web browser to upgrade using the updated database connection."; } else { // Run the scripts to set-up the database DTOStatus objDTOStatus = RunUpdateScripts(NewDatabaseVersion, _hostEnvironment, GetConnectionString()); if (!objDTOStatus.Success) { // If scripts have an error return it objRegisterStatus.isSuccessful = false; objRegisterStatus.status = objDTOStatus.StatusMessage; } else { // Create the Administrator string strCurrentHostLocation = $"{this.Request.Scheme}://{this.Request.Host}{this.Request.PathBase}"; objRegisterStatus = RegisterController.RegisterUser( objRegister, GetConnectionString(), _hostEnvironment, _userManager, _signInManager, strCurrentHostLocation, true, true); // There was an error creating the Administrator if (!objRegisterStatus.isSuccessful) { // Delete the record in the version table // So the install can be run again objDTOStatus = ResetVersionTable(); if (!objDTOStatus.Success) { // If there is an error return it objRegisterStatus.isSuccessful = false; objRegisterStatus.status = objDTOStatus.StatusMessage; } else { // Delete the user in case they were partially created objDTOStatus = DeleteAllUsers(); if (!objDTOStatus.Success) { // If there is an error return it objRegisterStatus.isSuccessful = false; objRegisterStatus.status = objDTOStatus.StatusMessage; } } } else { // Update the created user to be a SuperUser objDTOStatus = MakeUserASuperUser(objRegister.userName); #region Set the upload file path try { string strDefaultFilesPath = ADefHelpDeskApp.Controllers.ApplicationSettingsController.GetFilesPath(_DefaultFilesPath, GetConnectionString()); // Get GeneralSettings GeneralSettings objGeneralSettings = new GeneralSettings(GetConnectionString()); objGeneralSettings.UpdateFileUploadPath(GetConnectionString(), strDefaultFilesPath); } catch { // Do nothing if this fails // Admin can set the file path manually } #endregion if (!objDTOStatus.Success) { // If there is an error return it objRegisterStatus.isSuccessful = false; objRegisterStatus.status = objDTOStatus.StatusMessage; } } } } return(objRegisterStatus); }