Files
Umbraco-CMS/src/Umbraco.Web/Install/InstallSteps/NewInstallStep.cs
T
Shannon b96ba05d22 Merge remote-tracking branch 'origin/dev-v7' into temp8
# Conflicts:
#	build/Modules/Umbraco.Build/Get-UmbracoBuildEnv.ps1
#	build/NuSpecs/UmbracoCms.Core.nuspec
#	build/NuSpecs/UmbracoCms.nuspec
#	build/NuSpecs/tools/Readme.txt
#	src/Umbraco.Core/Configuration/UmbracoConfig.cs
#	src/Umbraco.Core/Configuration/UmbracoSettings/ContentElement.cs
#	src/Umbraco.Core/Configuration/UmbracoSettings/IContentSection.cs
#	src/Umbraco.Core/Constants-Conventions.cs
#	src/Umbraco.Core/Constants-System.cs
#	src/Umbraco.Core/IO/MediaFileSystem.cs
#	src/Umbraco.Core/Media/Exif/ImageFile.cs
#	src/Umbraco.Core/Models/Property.cs
#	src/Umbraco.Core/Models/PropertyTagBehavior.cs
#	src/Umbraco.Core/Models/PropertyTags.cs
#	src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenTwelveZero/SetDefaultTagsStorageType.cs
#	src/Umbraco.Core/Persistence/Repositories/AuditRepository.cs
#	src/Umbraco.Core/Persistence/Repositories/UserRepository.cs
#	src/Umbraco.Core/Persistence/Repositories/VersionableRepositoryBase.cs
#	src/Umbraco.Core/Security/AuthenticationExtensions.cs
#	src/Umbraco.Core/Security/BackOfficeCookieAuthenticationProvider.cs
#	src/Umbraco.Core/Services/Implement/PackagingService.cs
#	src/Umbraco.Core/Services/ServerRegistrationService.cs
#	src/Umbraco.Core/StringExtensions.cs
#	src/Umbraco.Core/packages.config
#	src/Umbraco.Tests/ApplicationUrlHelperTests.cs
#	src/Umbraco.Tests/Persistence/Repositories/AuditRepositoryTest.cs
#	src/Umbraco.Tests/Persistence/Repositories/UserRepositoryTest.cs
#	src/Umbraco.Tests/Web/TemplateUtilitiesTests.cs
#	src/Umbraco.Tests/packages.config
#	src/Umbraco.Web.UI.Client/package.json
#	src/Umbraco.Web.UI.Client/src/common/directives/components/content/umbcontentnodeinfo.directive.js
#	src/Umbraco.Web.UI.Client/src/common/directives/components/imaging/umbimagegravity.directive.js
#	src/Umbraco.Web.UI.Client/src/common/directives/components/tree/umbtreeitem.directive.js
#	src/Umbraco.Web.UI.Client/src/common/resources/log.resource.js
#	src/Umbraco.Web.UI.Client/src/common/services/user.service.js
#	src/Umbraco.Web.UI.Client/src/less/belle.less
#	src/Umbraco.Web.UI.Client/src/less/components/card.less
#	src/Umbraco.Web.UI.Client/src/less/navs.less
#	src/Umbraco.Web.UI.Client/src/less/panel.less
#	src/Umbraco.Web.UI.Client/src/less/property-editors.less
#	src/Umbraco.Web.UI.Client/src/less/tree.less
#	src/Umbraco.Web.UI.Client/src/views/common/dialogs/login.controller.js
#	src/Umbraco.Web.UI.Client/src/views/common/dialogs/login.html
#	src/Umbraco.Web.UI.Client/src/views/common/infiniteeditors/mediapicker/mediapicker.controller.js
#	src/Umbraco.Web.UI.Client/src/views/common/overlays/iconpicker/iconpicker.controller.js
#	src/Umbraco.Web.UI.Client/src/views/common/overlays/iconpicker/iconpicker.html
#	src/Umbraco.Web.UI.Client/src/views/common/overlays/linkpicker/linkpicker.controller.js
#	src/Umbraco.Web.UI.Client/src/views/common/overlays/mediaPicker/mediapicker.html
#	src/Umbraco.Web.UI.Client/src/views/components/content/umb-content-node-info.html
#	src/Umbraco.Web.UI.Client/src/views/components/notifications/umb-notifications.html
#	src/Umbraco.Web.UI.Client/src/views/components/umb-color-swatches.html
#	src/Umbraco.Web.UI.Client/src/views/components/umb-table.html
#	src/Umbraco.Web.UI.Client/src/views/propertyeditors/colorpicker/colorpicker.html
#	src/Umbraco.Web.UI.Client/src/views/propertyeditors/contentpicker/contentpicker.controller.js
#	src/Umbraco.Web.UI.Client/src/views/propertyeditors/fileupload/fileupload.controller.js
#	src/Umbraco.Web.UI.Client/src/views/propertyeditors/imagecropper/imagecropper.html
#	src/Umbraco.Web.UI.Client/src/views/propertyeditors/listview/listview.controller.js
#	src/Umbraco.Web.UI.Client/src/views/propertyeditors/mediapicker/mediapicker.html
#	src/Umbraco.Web.UI.Client/src/views/propertyeditors/rte/rte.controller.js
#	src/Umbraco.Web.UI.Client/src/views/propertyeditors/textarea/textarea.html
#	src/Umbraco.Web.UI/Umbraco/config/lang/en.xml
#	src/Umbraco.Web.UI/Umbraco/config/lang/en_us.xml
#	src/Umbraco.Web.UI/config/umbracoSettings.Release.config
#	src/Umbraco.Web.UI/packages.config
#	src/Umbraco.Web.UI/web.Template.Debug.config
#	src/Umbraco.Web.UI/web.Template.config
#	src/Umbraco.Web/Editors/AuthenticationController.cs
#	src/Umbraco.Web/Editors/BackOfficeController.cs
#	src/Umbraco.Web/Editors/CanvasDesignerController.cs
#	src/Umbraco.Web/Editors/ContentController.cs
#	src/Umbraco.Web/Editors/DashboardController.cs
#	src/Umbraco.Web/Editors/LogController.cs
#	src/Umbraco.Web/Editors/MediaController.cs
#	src/Umbraco.Web/Install/InstallHelper.cs
#	src/Umbraco.Web/Install/InstallSteps/NewInstallStep.cs
#	src/Umbraco.Web/Media/EmbedProviders/AbstractOEmbedProvider.cs
#	src/Umbraco.Web/Models/Mapping/DataTypeModelMapper.cs
#	src/Umbraco.Web/Models/Mapping/PreValueDisplayResolver.cs
#	src/Umbraco.Web/Mvc/MasterControllerFactory.cs
#	src/Umbraco.Web/PropertyEditors/FileUploadPropertyValueEditor.cs
#	src/Umbraco.Web/PropertyEditors/ImageCropperPropertyValueEditor.cs
#	src/Umbraco.Web/PropertyEditors/TextAreaPropertyEditor.cs
#	src/Umbraco.Web/PropertyEditors/ValueConverters/MultiNodeTreePickerPropertyConverter.cs
#	src/Umbraco.Web/PublishedCache/MemberPublishedContent.cs
#	src/Umbraco.Web/Routing/RedirectTrackingEventHandler.cs
#	src/Umbraco.Web/Scheduling/HealthCheckNotifier.cs
#	src/Umbraco.Web/Scheduling/KeepAlive.cs
#	src/Umbraco.Web/Scheduling/LogScrubber.cs
#	src/Umbraco.Web/Scheduling/ScheduledPublishing.cs
#	src/Umbraco.Web/Scheduling/ScheduledTasks.cs
#	src/Umbraco.Web/Scheduling/Scheduler.cs
#	src/Umbraco.Web/Templates/TemplateUtilities.cs
#	src/Umbraco.Web/Trees/DataTypeTreeController.cs
#	src/Umbraco.Web/UmbracoModule.cs
#	src/Umbraco.Web/_Legacy/Packager/Installer.cs
#	src/Umbraco.Web/packages.config
#	src/Umbraco.Web/umbraco.presentation/keepAliveService.cs
#	src/Umbraco.Web/umbraco.presentation/umbraco/dashboard/FeedProxy.aspx.cs
#	src/umbraco.businesslogic/IO/IOHelper.cs
#	src/umbraco.cms/packages.config
#	src/umbraco.cms/umbraco.cms.csproj
#	src/umbraco.controls/packages.config
#	src/umbraco.controls/umbraco.controls.csproj
#	src/umbraco.editorControls/packages.config
#	src/umbraco.editorControls/umbraco.editorControls.csproj
2018-10-01 14:32:46 +02:00

153 lines
6.1 KiB
C#

using System;
using System.Collections.Specialized;
using System.Configuration;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Web;
using System.Web.Security;
using Newtonsoft.Json;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.Migrations.Install;
using Umbraco.Core.Services;
using Umbraco.Web.Install.Models;
namespace Umbraco.Web.Install.InstallSteps
{
/// <summary>
/// This is the first UI step for a brand new install
/// </summary>
/// <remarks>
/// By default this will show the user view which is the most basic information to configure a new install, but if an install get's interupted because of an
/// error, etc... and the end-user refreshes the installer then we cannot show the user screen because they've already entered that information so instead we'll
/// display a simple continue installation view.
/// </remarks>
[InstallSetupStep(InstallationType.NewInstall, "User", 20, "")]
internal class NewInstallStep : InstallSetupStep<UserModel>
{
private readonly HttpContextBase _http;
private readonly IUserService _userService;
private readonly DatabaseBuilder _databaseBuilder;
private static HttpClient _httpClient;
private readonly IGlobalSettings _globalSettings;
public NewInstallStep(HttpContextBase http, IUserService userService, DatabaseBuilder databaseBuilder, IGlobalSettings globalSettings)
{
_http = http;
_userService = userService;
_databaseBuilder = databaseBuilder;
_globalSettings = globalSettings;
}
//TODO: Change all logic in this step to use ASP.NET Identity NOT MembershipProviders
private MembershipProvider CurrentProvider
{
get
{
var provider = Core.Security.MembershipProviderExtensions.GetUsersMembershipProvider();
return provider;
}
}
public override InstallSetupResult Execute(UserModel user)
{
var admin = _userService.GetUserById(Constants.Security.SuperUserId);
if (admin == null)
{
throw new InvalidOperationException("Could not find the super user!");
}
var membershipUser = CurrentProvider.GetUser(Constants.Security.SuperUserId, true);
if (membershipUser == null)
{
throw new InvalidOperationException($"No user found in membership provider with id of {Constants.Security.SuperUserId}.");
}
try
{
var success = membershipUser.ChangePassword("default", user.Password.Trim());
if (success == false)
{
throw new FormatException("Password must be at least " + CurrentProvider.MinRequiredPasswordLength + " characters long and contain at least " + CurrentProvider.MinRequiredNonAlphanumericCharacters + " symbols");
}
}
catch (Exception)
{
throw new FormatException("Password must be at least " + CurrentProvider.MinRequiredPasswordLength + " characters long and contain at least " + CurrentProvider.MinRequiredNonAlphanumericCharacters + " symbols");
}
admin.Email = user.Email.Trim();
admin.Name = user.Name.Trim();
admin.Username = user.Email.Trim();
_userService.Save(admin);
if (user.SubscribeToNewsLetter)
{
if (_httpClient == null)
_httpClient = new HttpClient();
var values = new NameValueCollection { { "name", admin.Name }, { "email", admin.Email } };
var content = new StringContent(JsonConvert.SerializeObject(values), Encoding.UTF8, "application/json");
try
{
var response = _httpClient.PostAsync("https://shop.umbraco.com/base/Ecom/SubmitEmail/installer.aspx", content).Result;
}
catch { /* fail in silence */ }
}
return null;
}
/// <summary>
/// Return a custom view model for this step
/// </summary>
public override object ViewModel
{
get
{
var provider = Core.Security.MembershipProviderExtensions.GetUsersMembershipProvider();
return new
{
minCharLength = provider.MinRequiredPasswordLength,
minNonAlphaNumericLength = provider.MinRequiredNonAlphanumericCharacters
};
}
}
public override string View
{
get
{
return RequiresExecution(null)
//the user UI
? "user"
//the continue install UI
: "continueinstall";
}
}
public override bool RequiresExecution(UserModel model)
{
//now we have to check if this is really a new install, the db might be configured and might contain data
var databaseSettings = ConfigurationManager.ConnectionStrings[Constants.System.UmbracoConnectionName];
//if there's already a version then there should def be a user but in some cases someone may have
// left a version number in there but cleared out their db conn string, in that case, it's really a new install.
if (_globalSettings.ConfigurationStatus.IsNullOrWhiteSpace() == false && databaseSettings != null) return false;
if (_databaseBuilder.IsConnectionStringConfigured(databaseSettings) && _databaseBuilder.IsDatabaseConfigured)
return _databaseBuilder.HasSomeNonDefaultUser() == false;
// In this one case when it's a brand new install and nothing has been configured, make sure the
// back office cookie is cleared so there's no old cookies lying around causing problems
_http.ExpireCookie(UmbracoConfig.For.UmbracoSettings().Security.AuthCookieName);
return true;
}
}
}