public ImageSliderHomeController(INccSettingsService nccSettingsService, ILoggerFactory factory, NccImageSliderService nccImageSliderService) { _logger = factory.CreateLogger <ImageSliderHomeController>(); nccImageSliderSettings = new NccImageSliderSettings(); _nccSettingsService = nccSettingsService; _nccImageSliderService = nccImageSliderService; nccImageSliderSettings = _nccSettingsService.GetByKey <NccImageSliderSettings>() ?? new NccImageSliderSettings(); }
public ActionResult EmailSettings() { var model = _settingsService.GetByKey <SmtpSettings>(); if (model == null) { model = new SmtpSettings(); } return(View(model)); }
public NeCategoryController(INccSettingsService nccSettingsService, ILoggerFactory factory, NeCategoryService neCategoryService, NccUserService nccUserService, IMemoryCache memoryCache) { _logger = factory.CreateLogger <NeCategoryController>(); nccNewsSettings = new NewsSettings(); _nccSettingsService = nccSettingsService; _neCategoryService = neCategoryService; _nccUserService = nccUserService; this._cache = memoryCache; nccNewsSettings = _nccSettingsService.GetByKey <NewsSettings>() ?? new NewsSettings(); }
public Task SendEmailAsync(string email, string subject, string message) { var smtpSettings = _nccSettingsService.GetByKey <SmtpSettings>(); if (smtpSettings == null) { _logger.LogError("SMTP Settings not found"); GlobalMessageRegistry.RegisterMessage( new GlobalMessage() { For = GlobalMessage.MessageFor.Both, Registrater = nameof(AuthMessageSender), Type = GlobalMessage.MessageType.Error, Text = "Email Send Failed. SMTP Settings not set yet." }, new System.TimeSpan(0, 1, 0) ); } else { var emailMessage = new MimeMessage(); emailMessage.From.Add(new MailboxAddress(smtpSettings.FromName, smtpSettings.FromEmail)); emailMessage.To.Add(new MailboxAddress("User", email)); emailMessage.Subject = subject; emailMessage.Body = new TextPart(TextFormat.Html) { Text = message }; using (var client = new SmtpClient()) { client.LocalDomain = smtpSettings.Host; client.ConnectAsync(smtpSettings.Host, smtpSettings.Port, smtpSettings.UseSSL).Wait(); client.Authenticate(new NetworkCredential(smtpSettings.UserName, smtpSettings.Password)); client.SendAsync(emailMessage).Wait(); client.DisconnectAsync(true).Wait(); } } return(Task.FromResult(0)); }
public static IServiceCollection AddCustomizedIdentity(this IServiceCollection services, INccSettingsService nccSettingsService) { services.AddIdentity <NccUser, NccRole>( configure => { if (GlobalContext.HostingEnvironment.IsDevelopment()) { configure.Password.RequiredLength = 1; configure.Password.RequireDigit = false; configure.Password.RequireLowercase = false; configure.Password.RequireNonAlphanumeric = false; configure.Password.RequireUppercase = false; } else { configure.Password.RequiredLength = 6; configure.Password.RequireDigit = true; configure.Password.RequireLowercase = false; configure.Password.RequireNonAlphanumeric = false; configure.Password.RequireUppercase = false; } configure.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(365 * 200); configure.Lockout.MaxFailedAccessAttempts = 5; configure.SignIn.RequireConfirmedEmail = false; configure.SignIn.RequireConfirmedPhoneNumber = false; } ) .AddEntityFrameworkStores <NccDbContext>() .AddRoleStore <NccRoleStore>() .AddUserStore <NccUserStore>() .AddDefaultTokenProviders() .AddSignInManager <SignInManager <NccUser> >(); var authBuilder = services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme); authBuilder = authBuilder.AddCookie(options => { options.Cookie.Name = ".NetCoreCMS.Cookie"; options.Cookie.Expiration = new TimeSpan(0, 20, 0); options.LoginPath = "/Account/Login"; options.LogoutPath = "/Account/Logoff"; options.AccessDeniedPath = "/Account/AccessDenied"; }); if (nccSettingsService != null) { var settings = nccSettingsService.GetByKey <OpenIdSettings>(); if (settings != null && string.IsNullOrEmpty(settings.GoogleClientId) == false && string.IsNullOrEmpty(settings.GoogleClientSecret) == false) { authBuilder = authBuilder.AddGoogle(GoogleDefaults.AuthenticationScheme, x => { x.ClientId = settings.GoogleClientId; x.ClientSecret = settings.GoogleClientSecret; x.CallbackPath = "/Account/ExternalLoginCallback"; x.Events = new OAuthEvents { OnRemoteFailure = ctx => HandleRemoteLoginFailure(ctx) }; }); } if (settings != null && string.IsNullOrEmpty(settings.MicrosoftAppId) == false && string.IsNullOrEmpty(settings.MicrosoftAppPassword) == false) { authBuilder = authBuilder.AddMicrosoftAccount(x => { x.ClientId = settings.MicrosoftAppId; x.ClientSecret = settings.MicrosoftAppPassword; x.CallbackPath = "/Account/ExternalLoginCallback"; }); } if (settings != null && string.IsNullOrEmpty(settings.TwitterConsumerKey) == false && string.IsNullOrEmpty(settings.TwitterCustomerSecret) == false) { authBuilder = authBuilder.AddTwitter(TwitterDefaults.AuthenticationScheme, x => { x.CallbackPath = "/Account/ExternalLoginCallback"; x.ConsumerKey = settings.TwitterConsumerKey; x.ConsumerSecret = settings.TwitterCustomerSecret; }); } if (settings != null && string.IsNullOrEmpty(settings.FacebookAppId) == false && string.IsNullOrEmpty(settings.FacebookAppSecret) == false) { authBuilder = authBuilder.AddFacebook(FacebookDefaults.AuthenticationScheme, x => { x.AppId = settings.FacebookAppId; x.AppSecret = settings.FacebookAppSecret; x.CallbackPath = "/Account/ExternalLoginCallback"; x.Scope.Add("email"); x.Fields.Add("name"); x.Fields.Add("email"); x.SaveTokens = true; x.Events = new OAuthEvents { OnRemoteFailure = ctx => HandleRemoteLoginFailure(ctx) }; }); } } services.ConfigureApplicationCookie(options => { options.LoginPath = "/Account/Login"; }); /* * services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) * .AddCookie(o => o.LoginPath = new PathString("/Account/login")) * * .AddFacebook(x => * { * x.AppId = ""; * x.AppSecret = ""; * * x.Events = new OAuthEvents * { * OnRemoteFailure = ctx => HandleRemoteLoginFailure(ctx) * }; * }) * .AddGoogle(x => * { * x.ClientId = ""; * x.ClientSecret = ""; * x.Events = new OAuthEvents * { * OnRemoteFailure = ctx => HandleRemoteLoginFailure(ctx) * }; * }); */ return(services); }
public static IServiceCollection AddCustomizedIdentity(this IServiceCollection services, INccSettingsService nccSettingsService) { services.AddIdentity <NccUser, NccRole>( configure => { configure.Password.RequireDigit = false; configure.Password.RequireLowercase = false; configure.Password.RequireNonAlphanumeric = false; configure.Password.RequireUppercase = false; configure.Password.RequiredLength = 1; configure.Lockout.MaxFailedAccessAttempts = 5; configure.SignIn.RequireConfirmedEmail = false; configure.SignIn.RequireConfirmedPhoneNumber = false; } ) .AddEntityFrameworkStores <NccDbContext>() .AddRoleStore <NccRoleStore>() .AddUserStore <NccUserStore>() .AddDefaultTokenProviders(); var authBuilder = services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(options => { options.Cookie.Name = ".NetCoreCMS.Cookie"; options.Cookie.Expiration = new TimeSpan(0, 20, 0); options.LoginPath = "/Account/Login"; options.LogoutPath = "/Account/Logoff"; }); if (nccSettingsService != null) { var settings = nccSettingsService.GetByKey <OpenIdSettings>(); if (settings != null) { authBuilder.AddFacebook(x => { x.AppId = settings.FacebookAppId; x.AppSecret = settings.FacebookAppSecret; x.Events = new OAuthEvents { OnRemoteFailure = ctx => HandleRemoteLoginFailure(ctx) }; }) .AddGoogle(x => { x.ClientId = settings.GoogleClientId; x.ClientSecret = settings.GoogleClientSecret; x.Events = new OAuthEvents { OnRemoteFailure = ctx => HandleRemoteLoginFailure(ctx) }; }); } } services.ConfigureApplicationCookie(options => options.LoginPath = "/Account/Login"); /* * services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) * .AddCookie(o => o.LoginPath = new PathString("/Account/login")) * * .AddFacebook(x => * { * x.AppId = ""; * x.AppSecret = ""; * * x.Events = new OAuthEvents * { * OnRemoteFailure = ctx => HandleRemoteLoginFailure(ctx) * }; * }) * .AddGoogle(x => * { * x.ClientId = ""; * x.ClientSecret = ""; * x.Events = new OAuthEvents * { * OnRemoteFailure = ctx => HandleRemoteLoginFailure(ctx) * }; * }); */ return(services); }
public StoreSettingsController(INccSettingsService nccSettingsService, ILoggerFactory factory) { _nccSettingsService = nccSettingsService; _logger = factory.CreateLogger <StoreSettingsController>(); storeSettings = _nccSettingsService.GetByKey <StoreSettings>() ?? new StoreSettings(); }