Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added recipe steps for user and email settings #6203

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"sdk": {
"version": "3.1.201"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<ProjectReference Include="..\..\OrchardCore\OrchardCore.DisplayManagement\OrchardCore.DisplayManagement.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Navigation.Core\OrchardCore.Navigation.Core.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Email.Abstractions\OrchardCore.Email.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Recipes.Abstractions\OrchardCore.Recipes.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Workflows.Abstractions\OrchardCore.Workflows.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.ResourceManagement\OrchardCore.ResourceManagement.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using OrchardCore.Email;
using OrchardCore.Entities;
using OrchardCore.Recipes.Models;
using OrchardCore.Recipes.Services;
using OrchardCore.Settings;

namespace OrchardCore.Email.Recipes
{
/// <summary>
/// This recipe step sets general login settings.
/// </summary>
public class SmtpSettingsStep : IRecipeStepHandler
{
private readonly ISiteService _siteService;

public SmtpSettingsStep(ISiteService siteService)
=> _siteService = siteService;

public async Task ExecuteAsync(RecipeExecutionContext context)
{
if (!string.Equals(context.Name, nameof(SmtpSettings), StringComparison.OrdinalIgnoreCase))
{
return;
}

var model = context.Step.ToObject<SmtpSettingsStepModel>();

var site = await _siteService.LoadSiteSettingsAsync();
var settings = site.As<SmtpSettings>();
settings.DefaultSender = model.DefaultSender;
settings.DeliveryMethod = model.DeliveryMethod;
settings.PickupDirectoryLocation = model.PickupDirectoryLocation;
settings.Host = model.Host;
settings.Port = model.Port;
settings.AutoSelectEncryption = model.AutoSelectEncryption;
settings.RequireCredentials = model.RequireCredentials;
settings.UseDefaultCredentials = model.UseDefaultCredentials;
settings.EncryptionMethod = model.EncryptionMethod;
settings.UserName = model.UserName;
settings.Password = model.Password;
site.Put<SmtpSettings>(settings);
await _siteService.UpdateSiteSettingsAsync(site);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using OrchardCore.Email;

namespace OrchardCore.Email
{
public class SmtpSettingsStepModel
{
public string DefaultSender { get; set; }
public SmtpDeliveryMethod DeliveryMethod { get; set; }
public string PickupDirectoryLocation { get; set; }
public string Host { get; set; }
public int Port { get; set; } = 25;
public bool AutoSelectEncryption { get; set; }
public bool RequireCredentials { get; set; }
public bool UseDefaultCredentials { get; set; }
public SmtpEncryptionMethod EncryptionMethod { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using OrchardCore.Entities;
using OrchardCore.Recipes.Models;
using OrchardCore.Recipes.Services;
using OrchardCore.Settings;
using OrchardCore.Users.Models;

namespace OrchardCore.Users.Recipes
{
/// <summary>
/// This recipe step sets general login settings.
/// </summary>
public class LoginSettingsStep : IRecipeStepHandler
{
private readonly ISiteService _siteService;

public LoginSettingsStep(ISiteService siteService)
=> _siteService = siteService;

public async Task ExecuteAsync(RecipeExecutionContext context)
{
if (!string.Equals(context.Name, nameof(LoginSettings), StringComparison.OrdinalIgnoreCase))
{
return;
}

var model = context.Step.ToObject<LoginSettingsStepModel>();

var site = await _siteService.LoadSiteSettingsAsync();
var settings = site.As<LoginSettings>();
settings.UseSiteTheme = model.UseSiteTheme;
settings.UseExternalProviderIfOnlyOneDefined = model.UseExternalProviderIfOnlyOneDefined;
settings.DisableLocalLogin = model.DisableLocalLogin;
settings.UseScriptToSyncRoles = model.UseScriptToSyncRoles;
settings.SyncRolesScript = model.SyncRolesScript;
site.Put<LoginSettings>(settings);
await _siteService.UpdateSiteSettingsAsync(site);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace OrchardCore.Users
{
public class LoginSettingsStepModel
{
public bool UseSiteTheme { get; set; }

public bool UseExternalProviderIfOnlyOneDefined { get; set; }

public bool DisableLocalLogin { get; set; }

public bool UseScriptToSyncRoles { get; set; }

public string SyncRolesScript { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using OrchardCore.Entities;
using OrchardCore.Recipes.Models;
using OrchardCore.Recipes.Services;
using OrchardCore.Settings;
using OrchardCore.Users.Models;

namespace OrchardCore.Users.Recipes
{
/// <summary>
/// This recipe step sets general reset password settings.
/// </summary>
public class ResetPasswordSettingsStep : IRecipeStepHandler
{
private readonly ISiteService _siteService;

public ResetPasswordSettingsStep(ISiteService siteService)
=> _siteService = siteService;

public async Task ExecuteAsync(RecipeExecutionContext context)
{
if (!string.Equals(context.Name, nameof(ResetPasswordSettings), StringComparison.OrdinalIgnoreCase))
{
return;
}

var model = context.Step.ToObject<ResetPasswordSettingsStepModel>();

var site = await _siteService.LoadSiteSettingsAsync();
var settings = site.As<ResetPasswordSettings>();
settings.AllowResetPassword = model.AllowResetPassword;
settings.UseSiteTheme = model.UseSiteTheme;
site.Put<ResetPasswordSettings>(settings);
await _siteService.UpdateSiteSettingsAsync(site);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace OrchardCore.Users
{
public class ResetPasswordSettingsStepModel
{
public bool AllowResetPassword { get; set; }
public bool UseSiteTheme { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@model OrchardCore.Users.ViewModels.ForgotPasswordViewModel

@{
ViewLayout = "Layout__Login";
}

<h2>@T["Forgot password?"]</h2>
<h4>@T["Please check your email or user name to reset your password."]</h4>
<hr />
<div class="row">
<div class="col-md-8">
<form asp-controller="ResetPassword" asp-action="ForgotPassword" method="post" class="form-horizontal">
<div asp-validation-summary="All" class="text-danger"></div>
<div class="form-group">
<label asp-for="UserIdentifier" class="col-md-4 control-label">@T["Email or user name"]</label>
<div class="col-md-9">
<input asp-for="UserIdentifier" class="form-control" />
</div>
</div>
@await RenderSectionAsync("AfterForgotPassword", required: false)
<div class="form-group">
<div class="col-md-offset-4 col-md-8">
<button type="submit" class="btn btn-primary">@T["Submit"]</button>
</div>
</div>
</form>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@{
ViewLayout = "Layout__Login";
}

<h1>@T["Forgot Password confirmation"]</h1>
<p>@T["Please check your email to reset your password."]</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
@model OrchardCore.Users.ViewModels.ResetPasswordViewModel

@{
ViewLayout = "Layout__Login";
}

<form asp-controller="ResetPassword" asp-action="ResetPassword" method="post" class="form-horizontal">
<h4>@T["Reset password"]</h4>
<hr />
<div asp-validation-summary="All" class="text-danger"></div>
<div class="form-group">
<label asp-for="Email" class="col-md-3 control-label">@T["Email"]</label>
<div class="col-md-9">
<input asp-for="Email" class="form-control" />
<span asp-validation-for="Email" class="text-danger"></span>
</div>
</div>
<div class="form-group">
<label asp-for="NewPassword" class="col-md-3 control-label">@T["New password"]</label>
<div class="col-md-9">
<input asp-for="NewPassword" class="form-control" />
<div id="passwordStrength"></div>
<span asp-validation-for="NewPassword" class="text-danger"></span>
</div>
</div>
<div class="form-group">
<label asp-for="PasswordConfirmation" class="col-md-3 control-label">@T["New password confirmation"]</label>
<div class="col-md-9">
<input asp-for="PasswordConfirmation" class="form-control" />
<span asp-validation-for="PasswordConfirmation" class="text-danger"></span>
</div>
</div>
@await RenderSectionAsync("AfterResetPassword", required: false)
<input asp-for="ResetToken" type="hidden" />
<div class="form-group">
<div class="col-md-offset-3 col-md-9">
<button type="submit" class="btn btn-primary">@T["Reset password"]</button>
</div>
</div>
</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@{
ViewLayout = "Layout__Login";
}

<h1>@T["Reset Password"]</h1>
<p>
@T["Your password has been reset."]
@T["Please "]<a asp-route-area="OrchardCore.Users" asp-controller="Account" asp-action="Login">@T["Click here to log in"]</a>
</p>