Skip to content

Commit

Permalink
Added recipe steps for user and email settings
Browse files Browse the repository at this point in the history
  • Loading branch information
jersiovic committed May 17, 2020
1 parent 5e8f2a1 commit 391c154
Show file tree
Hide file tree
Showing 10 changed files with 254 additions and 0 deletions.
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 Melon"]</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 Melon"]</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 Melon"]</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. Melon"]
@T["Please "]<a asp-route-area="OrchardCore.Users" asp-controller="Account" asp-action="Login">@T["Click here to log in"]</a>
</p>

0 comments on commit 391c154

Please sign in to comment.