no-more-circle-autorisation-to-file
This commit is contained in:
parent
5f12e17907
commit
6106cd4c7e
17 changed files with 2892 additions and 795 deletions
|
|
@ -16,11 +16,11 @@ namespace cli
|
|||
CommandArgument critCommandArg = null;
|
||||
CommandOption sendHelpOption = null;
|
||||
CommandLineApplication sendMailCommandApp
|
||||
= rootApp.Command("send-monthly",
|
||||
= rootApp.Command("send-email",
|
||||
(target) =>
|
||||
{
|
||||
target.FullName = "Send email";
|
||||
target.Description = "Sends monthly emails using given template from code";
|
||||
target.Description = "Sends emails using given template from code";
|
||||
sendHelpOption = target.HelpOption("-? | -h | --help");
|
||||
critCommandArg = target.Argument(
|
||||
"criteria",
|
||||
|
|
|
|||
|
|
@ -47,11 +47,23 @@ namespace cli.Commands
|
|||
ApplicationDbContext dbContext = app.Services.GetService<ApplicationDbContext>();
|
||||
Func<ApplicationUser, bool> criteria = UserPolicies.Criterias["user-to-remove"];
|
||||
|
||||
if (userManager==null)
|
||||
{
|
||||
logger.LogError("No user manager");
|
||||
throw new Exception("No user manager");
|
||||
}
|
||||
|
||||
logger.LogInformation("Starting emailling");
|
||||
mailer.SendEmailFromCriteria("user-to-remove");
|
||||
foreach (ApplicationUser user in dbContext.ApplicationUser.Where(
|
||||
u => criteria(u)
|
||||
))
|
||||
try {
|
||||
mailer.SendEmailFromCriteria("user-to-remove");
|
||||
}
|
||||
catch (NoMaillingTemplateException ex)
|
||||
{
|
||||
logger.LogWarning(ex.Message);
|
||||
}
|
||||
ApplicationUser [] users = dbContext.ApplicationUser.Where(
|
||||
u => criteria(u)).ToArray();
|
||||
foreach (ApplicationUser user in users)
|
||||
{
|
||||
dbContext.DeviceDeclaration.RemoveRange(dbContext.DeviceDeclaration.Where(g => g.DeviceOwnerId == user.Id));
|
||||
await userManager.DeleteAsync(user);
|
||||
|
|
|
|||
|
|
@ -121,6 +121,7 @@ namespace cli
|
|||
new AuthCommander(loggerFactory).Integrate(cliapp);
|
||||
new GenerationCommander().Integrate(cliapp);
|
||||
new Streamer(loggerFactory, cxSettings, usercxSettings ).Integrate(cliapp);
|
||||
new UserListCleanUp().Integrate(cliapp);
|
||||
|
||||
if (args.Length == 0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -21,6 +21,13 @@ using Yavsc.Server.Settings;
|
|||
|
||||
namespace cli.Services
|
||||
{
|
||||
public class NoMaillingTemplateException : Exception
|
||||
{
|
||||
public NoMaillingTemplateException(string templateCode) : base ($"No template found under id {templateCode}.")
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class EMailer
|
||||
{
|
||||
|
|
@ -74,7 +81,7 @@ namespace cli.Services
|
|||
|
||||
var templateInfo = dbContext.MailingTemplate.FirstOrDefault(t => t.Id == templateCode);
|
||||
|
||||
if (templateInfo==null) throw new Exception($"No template found under id {templateCode}.");
|
||||
if (templateInfo==null) throw new NoMaillingTemplateException(templateCode);
|
||||
logger.LogInformation($"Using code: {templateCode}, subject: {subtemp} ");
|
||||
logger.LogInformation("And body:\n"+templateInfo.Body);
|
||||
using (StringReader reader = new StringReader(templateInfo.Body))
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ using System.Collections.Generic;
|
|||
using Microsoft.Extensions.CodeGeneration.EntityFramework;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using Microsoft.AspNet.Identity;
|
||||
using Microsoft.AspNet.Identity.EntityFramework;
|
||||
|
||||
namespace cli
|
||||
{
|
||||
|
|
@ -143,6 +145,7 @@ namespace cli
|
|||
services.AddSingleton(typeof(IAssemblyLoadContextAccessor), svs => PlatformServices.Default.AssemblyLoadContextAccessor);
|
||||
services.AddSingleton(typeof(IAssemblyLoaderContainer), svs => PlatformServices.Default.AssemblyLoaderContainer);
|
||||
services.AddSingleton(typeof(ILibraryManager), svs => PlatformServices.Default.LibraryManager);
|
||||
services.AddSingleton<UserManager<ApplicationDbContext>>();
|
||||
|
||||
services.AddSingleton(typeof(BootstrapperContext),
|
||||
svs => new BootstrapperContext
|
||||
|
|
@ -247,6 +250,12 @@ Microsoft.Extensions.CodeGeneration.ICodeGeneratorActionsService),
|
|||
services.AddTransient(typeof(IPackageInstaller),typeof(PackageInstaller));
|
||||
services.AddTransient(typeof(Microsoft.Extensions.CodeGeneration.ILogger),typeof(Microsoft.Extensions.CodeGeneration.ConsoleLogger));
|
||||
|
||||
services.AddIdentity<ApplicationUser, IdentityRole>(
|
||||
option =>
|
||||
{
|
||||
option.User.RequireUniqueEmail = true;
|
||||
}
|
||||
).AddEntityFrameworkStores<ApplicationDbContext>();
|
||||
Services = services;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue