From 0a73c161917c9d684df8d14dfcbdcb163221b49a Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Wed, 29 Mar 2017 01:55:25 +0200 Subject: [PATCH] drop obsolete code --- Yavsc/Controllers/AccountController.cs | 8 +-- Yavsc/Controllers/AdministrationController.cs | 8 +-- Yavsc/Controllers/BlogspotController.cs | 15 +++-- Yavsc/Controllers/CommandController.cs | 9 ++- Yavsc/Controllers/HomeController.cs | 4 +- Yavsc/Controllers/ManageController.cs | 30 ++++----- Yavsc/Filters/LanguageActionFilter.cs | 61 ------------------- Yavsc/Startup/Startup.cs | 21 ++++--- 8 files changed, 49 insertions(+), 107 deletions(-) delete mode 100644 Yavsc/Filters/LanguageActionFilter.cs diff --git a/Yavsc/Controllers/AccountController.cs b/Yavsc/Controllers/AccountController.cs index 46aa79cf..5e0691a0 100644 --- a/Yavsc/Controllers/AccountController.cs +++ b/Yavsc/Controllers/AccountController.cs @@ -20,7 +20,7 @@ using Microsoft.Data.Entity; namespace Yavsc.Controllers { - [ServiceFilter(typeof(LanguageActionFilter)), AllowAnonymous] + [AllowAnonymous] public class AccountController : Controller { private readonly UserManager _userManager; @@ -231,12 +231,12 @@ namespace Yavsc.Controllers // Sign in the user with this external login provider if the user already has a login. info.ProviderDisplayName = info.ExternalPrincipal.Claims.First(c=>c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name")?.Value; - + var result = await _signInManager.ExternalLoginSignInAsync(info.LoginProvider, info.ProviderKey, isPersistent: false); if (result.Succeeded) { _logger.LogInformation(5, $"User logged in with {info.LoginProvider} provider, as {info.ProviderDisplayName} ({info.ProviderKey})." ); - + var ninfo = _dbContext.UserLogins.First(l=>l.ProviderKey == info.ProviderKey && l.LoginProvider == info.LoginProvider); ninfo.ProviderDisplayName = info.ProviderDisplayName; @@ -361,7 +361,7 @@ namespace Yavsc.Controllers // Don't reveal that the user does not exist or is not confirmed if (user == null) _logger.LogWarning($"ForgotPassword: Email {model.Email} not found"); - else + else _logger.LogWarning($"ForgotPassword: Email {model.Email} not confirmed"); return View("ForgotPasswordConfirmation"); } diff --git a/Yavsc/Controllers/AdministrationController.cs b/Yavsc/Controllers/AdministrationController.cs index 2ee03a44..acd0a2ea 100644 --- a/Yavsc/Controllers/AdministrationController.cs +++ b/Yavsc/Controllers/AdministrationController.cs @@ -13,7 +13,7 @@ using Yavsc.ViewModels.Administration; namespace Yavsc.Controllers { - [ServiceFilter(typeof(LanguageActionFilter)), Authorize()] + [Authorize()] public class AdministrationController : Controller { private readonly UserManager _userManager; @@ -55,7 +55,7 @@ namespace Yavsc.Controllers } return Ok(new { message = "you owned it." }); } - + [Authorize(Roles = Constants.AdminGroupName)] [Produces("application/json")] public async Task Index() @@ -72,7 +72,7 @@ namespace Yavsc.Controllers Name = x.Name, Users = x.Users.Select(u=>u.UserId).ToArray() }); - + return View(new AdminViewModel { Roles = roles.ToArray(), @@ -80,7 +80,7 @@ namespace Yavsc.Controllers YouAreAdmin = youAreAdmin }); } - + public IActionResult Role(string id) { IdentityRole role = _roleManager.Roles diff --git a/Yavsc/Controllers/BlogspotController.cs b/Yavsc/Controllers/BlogspotController.cs index c178b038..f0778b9f 100644 --- a/Yavsc/Controllers/BlogspotController.cs +++ b/Yavsc/Controllers/BlogspotController.cs @@ -16,7 +16,6 @@ using Microsoft.AspNet.Mvc.Rendering; namespace Yavsc.Controllers { - [ServiceFilter(typeof(LanguageActionFilter))] public class BlogspotController : Controller { ILogger _logger; @@ -114,7 +113,7 @@ namespace Yavsc.Controllers } if (!await _authorizationService.AuthorizeAsync(User, blog, new ViewRequirement())) { - return new ChallengeResult(); + return new ChallengeResult(); } return View(blog); } @@ -165,11 +164,11 @@ namespace Yavsc.Controllers ViewBag.ACL = _context.Circle.Where( c=>c.OwnerId == blog.AuthorId) .Select( - c => new SelectListItem - { - Text = c.Name, - Value = c.Id.ToString(), - Selected = blog.AuthorizeCircle(c.Id) + c => new SelectListItem + { + Text = c.Name, + Value = c.Id.ToString(), + Selected = blog.AuthorizeCircle(c.Id) }  ); return View(blog); @@ -195,7 +194,7 @@ namespace Yavsc.Controllers _context.SaveChanges(User.GetUserId()); ViewData["StatusMessage"] = "Post modified"; return RedirectToAction("Index"); - } + } else { ViewData["StatusMessage"] = "Accès restreint"; diff --git a/Yavsc/Controllers/CommandController.cs b/Yavsc/Controllers/CommandController.cs index 0f494123..3319810a 100644 --- a/Yavsc/Controllers/CommandController.cs +++ b/Yavsc/Controllers/CommandController.cs @@ -18,8 +18,7 @@ namespace Yavsc.Controllers using Models.Relationship; using Models.Workflow; using Services; - - [ServiceFilter(typeof(LanguageActionFilter))] + public class CommandController : Controller { protected UserManager _userManager; @@ -128,7 +127,7 @@ namespace Yavsc.Controllers [ValidateAntiForgeryToken] public async Task Create(RdvQuery command) { - + var uid = User.GetUserId(); var prid = command.PerformerId; if (string.IsNullOrWhiteSpace(uid) @@ -151,10 +150,10 @@ namespace Yavsc.Controllers // ModelState.ClearValidationState("Client.Avatar"); // ModelState.ClearValidationState("ClientId"); ModelState.MarkFieldSkipped("ClientId"); - + if (ModelState.IsValid) { - var existingLocation = _context.Locations.FirstOrDefault( x=>x.Address == command.Location.Address + var existingLocation = _context.Locations.FirstOrDefault( x=>x.Address == command.Location.Address && x.Longitude == command.Location.Longitude && x.Latitude == command.Location.Latitude ); if (existingLocation!=null) { diff --git a/Yavsc/Controllers/HomeController.cs b/Yavsc/Controllers/HomeController.cs index 21ffdd02..26280245 100644 --- a/Yavsc/Controllers/HomeController.cs +++ b/Yavsc/Controllers/HomeController.cs @@ -14,8 +14,8 @@ using System.Threading.Tasks; namespace Yavsc.Controllers { using Models; - - [ServiceFilter(typeof(LanguageActionFilter)),AllowAnonymous] + + [AllowAnonymous] public class HomeController : Controller { public IHostingEnvironment Hosting { get; set; } diff --git a/Yavsc/Controllers/ManageController.cs b/Yavsc/Controllers/ManageController.cs index eedfc70d..c8d28475 100644 --- a/Yavsc/Controllers/ManageController.cs +++ b/Yavsc/Controllers/ManageController.cs @@ -26,7 +26,7 @@ namespace Yavsc.Controllers using PayPal.PayPalAPIInterfaceService; using PayPal.PayPalAPIInterfaceService.Model; - [Authorize, ServiceFilter(typeof(LanguageActionFilter))] + [Authorize] public class ManageController : Controller { private readonly UserManager _userManager; @@ -372,14 +372,14 @@ namespace Yavsc.Controllers if (result.Succeeded) { /* Obsolete : files are no more prefixed using the user name. - + var userdirinfo = new DirectoryInfo( Path.Combine(_siteSettings.UserFiles.DirName, oldUserName)); var newdir = Path.Combine(_siteSettings.UserFiles.DirName, model.NewUserName); if (userdirinfo.Exists) - userdirinfo.MoveTo(newdir); + userdirinfo.MoveTo(newdir); */ await _signInManager.SignInAsync(user, isPersistent: false); @@ -529,7 +529,7 @@ namespace Yavsc.Controllers { if (ModelState.IsValid) { - + var exSiren = await _dbContext.ExceptionsSIREN.FirstOrDefaultAsync( ex => ex.SIREN == model.SIREN ); @@ -609,12 +609,12 @@ namespace Yavsc.Controllers [HttpGet, Route("/Manage/Credits")] public IActionResult Credits() { - + return View(); } public Dictionary PaypalConfig {  get {  - var config = + var config = new Dictionary(); config.Add("mode", "sandbox"); config.Add("account1.apiUsername", _payPalSettings.UserId); @@ -622,7 +622,7 @@ namespace Yavsc.Controllers config.Add("account1.apiSignature", _payPalSettings.Signature); return config; } - } + } protected IActionResult DoDirectCredit(DoDirectCreditViewModel model) @@ -679,7 +679,7 @@ namespace Yavsc.Controllers // Important: The notify URL applies only to DoExpressCheckoutPayment. This value is ignored when set in SetExpressCheckout or GetExpressCheckoutDetails. requestDetails.PaymentDetails.NotifyURL = model.IpnNotificationUrl.Trim(); - // (Optional) Buyer's shipping address information. + // (Optional) Buyer's shipping address information. AddressType billingAddr = new AddressType(); if (model.FirstName != string.Empty && model.LastName != string.Empty && model.Street1 != string.Empty && model.Country != string.Empty) @@ -708,7 +708,7 @@ namespace Yavsc.Controllers // Note: You must set the currencyID attribute to one of the 3-character currency codes for any of the supported PayPal currencies. CurrencyCodeType currency = (CurrencyCodeType) Enum.Parse(typeof(CurrencyCodeType), model.CurrencyCode); - BasicAmountType paymentAmount = new BasicAmountType(currency, model.Amount); + BasicAmountType paymentAmount = new BasicAmountType(currency, model.Amount); requestDetails.PaymentDetails.OrderTotal = paymentAmount; // Invoke the API @@ -716,17 +716,17 @@ namespace Yavsc.Controllers wrapper.DoDirectPaymentRequest = request; // Configuration map containing signature credentials and other required configuration. - // For a full list of configuration parameters refer in wiki page + // For a full list of configuration parameters refer in wiki page // [https://github.com/paypal/sdk-core-dotnet/wiki/SDK-Configuration-Parameters] //// TODO clean Dictionary configurationMap = Configuration.GetAcctAndConfig(); // Create the PayPalAPIInterfaceServiceService service object to make the API call PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(PaypalConfig); - // # API call - // Invoke the DoDirectPayment method in service wrapper object + // # API call + // Invoke the DoDirectPayment method in service wrapper object DoDirectPaymentResponseType response = service.DoDirectPayment(wrapper); - + // Check for API return status return setKeyResponseObjects(service, response); } @@ -749,7 +749,7 @@ namespace Yavsc.Controllers } else { - HttpContext.Items.Add("Response_error", null); + HttpContext.Items.Add("Response_error", null); responseParams.Add("Transaction Id", response.TransactionID); responseParams.Add("Payment status", response.PaymentStatus.ToString()); if(response.PendingReason != null) { @@ -759,7 +759,7 @@ namespace Yavsc.Controllers HttpContext.Items.Add("Response_keyResponseObject", responseParams); return View("APIResponse"); } - + #region Helpers private void AddErrors(IdentityResult result) diff --git a/Yavsc/Filters/LanguageActionFilter.cs b/Yavsc/Filters/LanguageActionFilter.cs deleted file mode 100644 index 77ec2dfe..00000000 --- a/Yavsc/Filters/LanguageActionFilter.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System.Globalization; - -namespace Yavsc -{ - using Microsoft.AspNet.Mvc.Filters; - using Microsoft.Extensions.Logging; - - public class LanguageActionFilter : ActionFilterAttribute - { - private readonly ILogger _logger; - - public LanguageActionFilter(ILoggerFactory loggerFactory) - { - _logger = loggerFactory.CreateLogger("LanguageActionFilter"); - } - - public override void OnActionExecuting(ActionExecutingContext context) - { - string culture = null; - var routedCulture = context.RouteData.Values["culture"]; - if (routedCulture != null) { - culture = routedCulture.ToString(); - _logger.LogInformation($"Setting the culture from the URL: {culture}"); - - } - else { - if (context.HttpContext.Request.Headers.ContainsKey("accept-language")) - { - // fr,en-US;q=0.7,en;q=0.3 - string spec = context.HttpContext.Request.Headers["accept-language"]; - _logger.LogInformation($"Setting the culture from language header spec: {spec}"); - - string firstpart = spec.Split(';')[0]; - foreach (string lang in firstpart.Split(',')) - { - // TODO do it from the given options ... - // just take the main part :-) - string mainlang = lang.Split('-')[0]; - if (mainlang=="fr"||mainlang=="en") { - culture = mainlang; - _logger.LogInformation($"Setting the culture from header: {culture}"); - break; - } - } - } - } - if (culture != null) { -#if DNX451 - // System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo(culture); - System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture); -#else - // CultureInfo.CurrentCulture = new CultureInfo(culture); - CultureInfo.CurrentUICulture = new CultureInfo(culture); -#endif -} - base.OnActionExecuting(context); - } - } -} - - diff --git a/Yavsc/Startup/Startup.cs b/Yavsc/Startup/Startup.cs index 72012b85..7a8cc6e9 100755 --- a/Yavsc/Startup/Startup.cs +++ b/Yavsc/Startup/Startup.cs @@ -113,11 +113,16 @@ namespace Yavsc // - QueryStringRequestCultureProvider, sets culture via "culture" and "ui-culture" query string values, useful for testing // - CookieRequestCultureProvider, sets culture via "ASPNET_CULTURE" cookie // - AcceptLanguageHeaderRequestCultureProvider, sets culture via the "Accept-Language" request header + //options.RequestCultureProviders.Insert(0, new CustomRequestCultureProvider(async context => //{ // // My custom request culture logic - // return new ProviderCultureResult("en"); + // return new ProviderCultureResult("fr"); //})); + + options.RequestCultureProviders.Insert(0, new AcceptLanguageHeaderRequestCultureProvider()); + options.RequestCultureProviders.Insert(0, new CookieRequestCultureProvider()); + }); @@ -184,7 +189,7 @@ namespace Yavsc services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); - + services.AddMvc(config => { var policy = new AuthorizationPolicyBuilder() @@ -207,7 +212,7 @@ namespace Yavsc options.ResourcesPath = "Resources"; }).AddDataAnnotationsLocalization(); - services.AddScoped(); + // services.AddScoped(); // Inject ticket formatting services.AddTransient(typeof(ISecureDataFormat<>), typeof(SecureDataFormat<>)); @@ -223,7 +228,7 @@ namespace Yavsc { options.ResourcesPath = "Resources"; }); - + } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. @@ -241,7 +246,7 @@ namespace Yavsc Startup.UserFilesDirName = new DirectoryInfo(siteSettings.Value.UserFiles.Blog).FullName; Startup.UserBillsDirName = new DirectoryInfo(siteSettings.Value.UserFiles.Bills).FullName; Startup.Temp = siteSettings.Value.TempDir; - + // TODO implement an installation & upgrade procedure // Create required directories foreach (string dir in new string[] { UserFilesDirName, UserBillsDirName, SiteSetup.TempDir }) @@ -339,14 +344,14 @@ namespace Yavsc ConfigureWorkflow(app, SiteSetup, logger); app.UseRequestLocalization(localizationOptions.Value, (RequestCulture) new RequestCulture((string)"fr")); app.UseSession(); - + app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); - + } // Entry point for the application. @@ -354,4 +359,4 @@ namespace Yavsc } } -// +//