diff --git a/DOL.WHD.Section14c.Api/Controllers/AccountController.cs b/DOL.WHD.Section14c.Api/Controllers/AccountController.cs index 8d9753de..325cad8e 100644 --- a/DOL.WHD.Section14c.Api/Controllers/AccountController.cs +++ b/DOL.WHD.Section14c.Api/Controllers/AccountController.cs @@ -1,5 +1,4 @@ using System; -using System.Configuration; using System.Net; using System.Net.Http; using System.Threading.Tasks; @@ -18,6 +17,7 @@ using System.Linq; using System.Collections.Generic; using System.Data.Entity; +using DOL.WHD.Section14c.Common; using DOL.WHD.Section14c.Domain.Models.Identity; namespace DOL.WHD.Section14c.Api.Controllers @@ -56,8 +56,8 @@ public async Task Register(RegisterViewModel model) } // Validate Recaptcha - var reCaptchaVerfiyUrl = ConfigurationManager.AppSettings["ReCaptchaVerfiyUrl"]; - var reCaptchaSecretKey = ConfigurationManager.AppSettings["ReCaptchaSecretKey"]; + var reCaptchaVerfiyUrl = AppSettings.Get("ReCaptchaVerfiyUrl"); + var reCaptchaSecretKey = AppSettings.Get("ReCaptchaSecretKey"); if (!string.IsNullOrEmpty(reCaptchaVerfiyUrl) && !string.IsNullOrEmpty(reCaptchaSecretKey)) { var remoteIpAddress = Request.GetOwinContext().Request.RemoteIpAddress; diff --git a/DOL.WHD.Section14c.Api/DOL.WHD.Section14c.Api.csproj b/DOL.WHD.Section14c.Api/DOL.WHD.Section14c.Api.csproj index d13c3891..3fcdba79 100644 --- a/DOL.WHD.Section14c.Api/DOL.WHD.Section14c.Api.csproj +++ b/DOL.WHD.Section14c.Api/DOL.WHD.Section14c.Api.csproj @@ -314,6 +314,10 @@ {7cd1d7dd-ce24-4280-b8bd-0b8b9abb0ffc} DOL.WHD.Section14c.Business + + {9C06ABE3-28D2-4BAB-BAA4-11B6C404B329} + DOL.WHD.Section14c.Common + {F7033F89-ED1B-4784-AEAB-D8808FBBEC92} DOL.WHD.Section14c.DataAccess diff --git a/DOL.WHD.Section14c.Api/Filters/AuthorizeHttps.cs b/DOL.WHD.Section14c.Api/Filters/AuthorizeHttps.cs index c6363ab9..f2abfc17 100644 --- a/DOL.WHD.Section14c.Api/Filters/AuthorizeHttps.cs +++ b/DOL.WHD.Section14c.Api/Filters/AuthorizeHttps.cs @@ -3,6 +3,7 @@ using System.Net.Http; using System.Web.Http; using System.Web.Http.Controllers; +using DOL.WHD.Section14c.Common; namespace DOL.WHD.Section14c.Api.Filters { @@ -10,10 +11,7 @@ public class AuthorizeHttps : AuthorizeAttribute { public override void OnAuthorization(HttpActionContext actionContext) { - if (SkipAuthorization(actionContext)) - return; - - if (actionContext.Request.RequestUri.Scheme != Uri.UriSchemeHttps) + if (actionContext.Request.RequestUri.Scheme != Uri.UriSchemeHttps && AppSettings.Get("RequireHttps")) { actionContext.Response = new HttpResponseMessage(System.Net.HttpStatusCode.Forbidden) { @@ -22,6 +20,9 @@ public override void OnAuthorization(HttpActionContext actionContext) } else { + if (SkipAuthorization(actionContext)) + return; + base.OnAuthorization(actionContext); } } diff --git a/DOL.WHD.Section14c.Api/Parameters.xml b/DOL.WHD.Section14c.Api/Parameters.xml index 2951a196..dfc120cc 100644 --- a/DOL.WHD.Section14c.Api/Parameters.xml +++ b/DOL.WHD.Section14c.Api/Parameters.xml @@ -53,5 +53,7 @@ - + + + \ No newline at end of file diff --git a/DOL.WHD.Section14c.Api/Providers/ApplicationOAuthProvider.cs b/DOL.WHD.Section14c.Api/Providers/ApplicationOAuthProvider.cs index eca952ed..dd9c385d 100644 --- a/DOL.WHD.Section14c.Api/Providers/ApplicationOAuthProvider.cs +++ b/DOL.WHD.Section14c.Api/Providers/ApplicationOAuthProvider.cs @@ -1,17 +1,14 @@ using System; using System.Collections.Generic; -using System.Configuration; using System.Data.Entity; using System.Security.Claims; using System.Threading.Tasks; using DOL.WHD.Section14c.DataAccess.Identity; -using DOL.WHD.Section14c.Domain.Models; using Microsoft.AspNet.Identity.Owin; using Microsoft.Owin.Security; using Microsoft.Owin.Security.Cookies; using Microsoft.Owin.Security.OAuth; -using System.Linq; -using DOL.WHD.Section14c.Domain.Models.Identity; +using DOL.WHD.Section14c.Common; namespace DOL.WHD.Section14c.Api.Providers { @@ -38,7 +35,7 @@ public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwner if (user != null) { var passwordExpired = false; - var passwordExpirationDays = Convert.ToInt32(ConfigurationManager.AppSettings["PasswordExpirationDays"]); + var passwordExpirationDays = AppSettings.Get("PasswordExpirationDays"); if (passwordExpirationDays > 0) { passwordExpired = user.LastPasswordChangedDate.AddDays(passwordExpirationDays) < DateTime.Now; diff --git a/DOL.WHD.Section14c.Api/Providers/RestrictedMultipartMemoryStreamProvider.cs b/DOL.WHD.Section14c.Api/Providers/RestrictedMultipartMemoryStreamProvider.cs index cf9876f7..a8a0891f 100644 --- a/DOL.WHD.Section14c.Api/Providers/RestrictedMultipartMemoryStreamProvider.cs +++ b/DOL.WHD.Section14c.Api/Providers/RestrictedMultipartMemoryStreamProvider.cs @@ -1,9 +1,8 @@ -using System; -using System.Configuration; -using System.IO; +using System.IO; using System.Net.Http; using System.Net.Http.Headers; using System.Text.RegularExpressions; +using DOL.WHD.Section14c.Common; namespace DOL.WHD.Section14c.Api.Providers { @@ -11,7 +10,7 @@ public class RestrictedMultipartMemoryStreamProvider : MultipartMemoryStreamProv { public override Stream GetStream(HttpContent parent, HttpContentHeaders headers) { - var pattern = ConfigurationManager.AppSettings["AllowedFileNamesRegex"]; + var pattern = AppSettings.Get("AllowedFileNamesRegex"); var fileNameRegex = new Regex(pattern); var fileName = headers.ContentDisposition.FileName; diff --git a/DOL.WHD.Section14c.Api/Web.config b/DOL.WHD.Section14c.Api/Web.config index fdd3b34b..dbaaf310 100644 --- a/DOL.WHD.Section14c.Api/Web.config +++ b/DOL.WHD.Section14c.Api/Web.config @@ -23,6 +23,7 @@ +