diff --git a/src/SampleCRM.Browser/Properties/launchSettings.json b/src/SampleCRM.Browser/Properties/launchSettings.json index a90ba89..7310201 100644 --- a/src/SampleCRM.Browser/Properties/launchSettings.json +++ b/src/SampleCRM.Browser/Properties/launchSettings.json @@ -6,7 +6,7 @@ "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, - "applicationUrl": "http://localhost:57249;https://localhost:57248", + "applicationUrl": "https://localhost:54845", "hotReloadEnabled": false } } diff --git a/src/SampleCRM.Web/Global.asax.cs b/src/SampleCRM.Web/Global.asax.cs index b5b3cc1..8f81fc7 100644 --- a/src/SampleCRM.Web/Global.asax.cs +++ b/src/SampleCRM.Web/Global.asax.cs @@ -55,8 +55,13 @@ protected void Session_Start(object sender, EventArgs e) } protected void Application_BeginRequest(object sender, EventArgs e) - { - HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*"); + { +#if RELEASE + HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "https://samplecrm-webservices.azurewebsites.net"); +#else + HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "https://localhost:54845"); +#endif + HttpContext.Current.Response.AddHeader("Access-Control-Allow-Credentials", "true"); if (HttpContext.Current.Request.HttpMethod == "OPTIONS") { diff --git a/src/SampleCRM.Web/Models/User.cs b/src/SampleCRM.Web/Models/User.cs index 264e88c..c1f8192 100644 --- a/src/SampleCRM.Web/Models/User.cs +++ b/src/SampleCRM.Web/Models/User.cs @@ -1,13 +1,15 @@ -using OpenRiaServices.DomainServices.Server.ApplicationServices; +using OpenRiaServices.DomainServices.Server.Authentication; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; namespace SampleCRM.Web { /// /// Class containing information about the authenticated user. /// - public partial class User : UserBase + public partial class User : IUser { - //// NOTE: Profile properties can be added for use in Silverlight application. + //// NOTE: Profile properties can be added for use in application. //// To enable profiles, edit the appropriate section of web.config file. //// //// public string MyProfileProperty { get; set; } @@ -16,5 +18,10 @@ public partial class User : UserBase /// Gets and sets the friendly name of the user. /// public string FriendlyName { get; set; } + + [Key] + public string Name { get; set; } + + public IEnumerable Roles { get; set; } = new List(); } -} +} \ No newline at end of file diff --git a/src/SampleCRM.Web/SampleCRM.Web.csproj b/src/SampleCRM.Web/SampleCRM.Web.csproj index 993ae85..c73ef82 100644 --- a/src/SampleCRM.Web/SampleCRM.Web.csproj +++ b/src/SampleCRM.Web/SampleCRM.Web.csproj @@ -1,295 +1,307 @@ - - - - - - - Debug - AnyCPU - true - true - true - - - 2.0 - {A8AA986C-4AEF-489F-86EC-19029369765E} - {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} - Library - Properties - SampleCRM.Web - SampleCRM.Web - v4.8 - true - - - - - - - 4.0 - - - - - - - - - - - - true - full - false - bin\ - TRACE;DEBUG;OPENSILVER - prompt - 4 - false - x64 - - - pdbonly - true - bin\ - TRACE - prompt - 4 - false - - - - ..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.dll - - - ..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.SqlServer.dll - - - - $(SolutionDir)packages\OpenRiaServices.EntityFramework.4.6.0\lib\net45\OpenRiaServices.DomainServices.EntityFramework.dll - - - $(SolutionDir)packages\OpenRiaServices.Server.4.6.0\lib\net45\OpenRiaServices.DomainServices.Hosting.dll - - - $(SolutionDir)packages\OpenRiaServices.Server.4.6.0\lib\net45\OpenRiaServices.DomainServices.Server.dll - - - $(SolutionDir)packages\SQLiteMembershipProvider.1.1.0.0\lib\net40\SQLiteMembershipProvider.dll - - - - - - ..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.118.0\lib\net46\System.Data.SQLite.dll - - - ..\packages\System.Data.SQLite.EF6.1.0.118.0\lib\net46\System.Data.SQLite.EF6.dll - - - ..\packages\System.Data.SQLite.Linq.1.0.118.0\lib\net46\System.Data.SQLite.Linq.dll - - - - - - - - - - - - - $(SolutionDir)packages\Microsoft.AspNet.Providers.Core.2.0.0\lib\net40\System.Web.Providers.dll - - - - - - - - - - - - - PreserveNewest - - - TextTemplatingFileGenerator - SampleCRMModel.edmx - SampleCRMModel.Context.cs - - - TextTemplatingFileGenerator - SampleCRMModel.edmx - SampleCRMModel.cs - - - - Web.config - - - Web.config - - - - - - Global.asax - - - Images.ashx - - - SampleCRMModel.tt - - - - SampleCRMModel.tt - - - SampleCRMModel.tt - - - SampleCRMModel.tt - - - SampleCRMModel.tt - - - SampleCRMModel.tt - - - SampleCRMModel.tt - - - SampleCRMModel.tt - - - SampleCRMModel.tt - - - - - SampleCRMModel.tt - - - True - True - SampleCRMModel.Context.tt - - - True - True - SampleCRMModel.tt - - - True - True - SampleCRMModel.edmx - - - SampleCRMModel.tt - - - - - - - - - - - - - - - - - - - - - EntityModelCodeGenerator - SampleCRMModel.Designer.cs - - - SampleCRMModel.edmx - - - PreserveNewest - - - PreserveNewest - - - - - - - - - - 10.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - true - bin\ - TRACE;DEBUG;OPENSILVER - full - x64 - 7.3 - prompt - - - bin\ - TRACE - true - pdbonly - x64 - 7.3 - prompt - - - - - - - - - True - True - 54837 - / - http://localhost:54837/ - False - False - - - False - - - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - - - - + + + + + + Debug + AnyCPU + true + true + true + + + 2.0 + {A8AA986C-4AEF-489F-86EC-19029369765E} + {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} + Library + Properties + SampleCRM.Web + SampleCRM.Web + v4.8 + true + + + + + + + 4.0 + + 44350 + + + + + + + + + + true + full + false + bin\ + TRACE;DEBUG;OPENSILVER + prompt + 4 + false + x64 + + + pdbonly + true + bin\ + TRACE + prompt + 4 + false + + + + ..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.dll + + + ..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.SqlServer.dll + + + + ..\packages\OpenRiaServices.EntityFramework.5.0.0-preview0003\lib\net46\OpenRiaServices.DomainServices.EntityFramework.dll + + + ..\packages\OpenRiaServices.Server.5.0.0-preview0003\lib\net46\OpenRiaServices.DomainServices.Hosting.dll + + + ..\packages\OpenRiaServices.Endpoints.5.0.0-preview0003\lib\net46\OpenRiaServices.DomainServices.Hosting.Endpoint.dll + + + ..\packages\OpenRiaServices.Server.5.0.0-preview0003\lib\net46\OpenRiaServices.DomainServices.Server.dll + + + ..\packages\OpenRiaServices.Server.Authentication.AspNetMembership.5.0.0-preview0003\lib\net46\OpenRiaServices.DomainServices.Server.Authentication.AspNetMembership.dll + + + $(SolutionDir)packages\SQLiteMembershipProvider.1.1.0.0\lib\net40\SQLiteMembershipProvider.dll + + + + + + ..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.118.0\lib\net46\System.Data.SQLite.dll + + + ..\packages\System.Data.SQLite.EF6.1.0.118.0\lib\net46\System.Data.SQLite.EF6.dll + + + ..\packages\System.Data.SQLite.Linq.1.0.118.0\lib\net46\System.Data.SQLite.Linq.dll + + + ..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll + + + + + ..\packages\System.Threading.Tasks.Extensions.4.5.3\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll + + + + + + + + + + + $(SolutionDir)packages\Microsoft.AspNet.Providers.Core.2.0.0\lib\net40\System.Web.Providers.dll + + + + + + + + + + + + + PreserveNewest + + + TextTemplatingFileGenerator + SampleCRMModel.edmx + SampleCRMModel.Context.cs + + + TextTemplatingFileGenerator + SampleCRMModel.edmx + SampleCRMModel.cs + + + + Web.config + + + Web.config + + + + + + Global.asax + + + Images.ashx + + + SampleCRMModel.tt + + + + SampleCRMModel.tt + + + SampleCRMModel.tt + + + SampleCRMModel.tt + + + SampleCRMModel.tt + + + SampleCRMModel.tt + + + SampleCRMModel.tt + + + SampleCRMModel.tt + + + SampleCRMModel.tt + + + + + SampleCRMModel.tt + + + True + True + SampleCRMModel.Context.tt + + + True + True + SampleCRMModel.tt + + + True + True + SampleCRMModel.edmx + + + SampleCRMModel.tt + + + + + + + + + + + + + + + + + + + + + EntityModelCodeGenerator + SampleCRMModel.Designer.cs + + + SampleCRMModel.edmx + + + PreserveNewest + + + PreserveNewest + + + + + + + + + + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + true + bin\ + TRACE;DEBUG;OPENSILVER + full + x64 + 7.3 + prompt + + + bin\ + TRACE + true + pdbonly + x64 + 7.3 + prompt + + + + + + + + + True + True + 44350 + / + https://localhost:44350/ + False + False + + + False + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + \ No newline at end of file diff --git a/src/SampleCRM.Web/Services/AuthenticationService.cs b/src/SampleCRM.Web/Services/AuthenticationService.cs index 1867de8..10663e7 100644 --- a/src/SampleCRM.Web/Services/AuthenticationService.cs +++ b/src/SampleCRM.Web/Services/AuthenticationService.cs @@ -1,5 +1,10 @@ using OpenRiaServices.DomainServices.Hosting; -using OpenRiaServices.DomainServices.Server.ApplicationServices; +using OpenRiaServices.DomainServices.Server; +using OpenRiaServices.DomainServices.Server.Authentication; +using System; +using System.Security.Principal; +using System.Web; +using System.Web.Security; namespace SampleCRM.Web { @@ -17,6 +22,92 @@ namespace SampleCRM.Web /// Most of the functionality is already provided by the AuthenticationBase class. /// [EnableClientAccess] - public class AuthenticationService : AuthenticationBase - { } -} + public class AuthenticationService : DomainService, IAuthentication + { + private static readonly User DefaultUser = new User + { + Name = string.Empty + }; + + /// + /// Use this method to fill your User object with additional data (from database, for example) + /// + /// + /// + private User MapMembershipUser(MembershipUser user) + { + return new User + { + Name = user.UserName + }; + } + + public bool ValidateUser(string userName, string password) => Membership.ValidateUser(userName, password); + + [Query(IsComposable = false)] + public User GetUser() + { + IIdentity identity = null; + try + { + identity = ServiceContext?.User?.Identity; + } + catch (InvalidOperationException) + { + + } + + if (identity is null) return DefaultUser; + + if (identity.IsAuthenticated) + { + var user = Membership.GetUser(identity.Name); + + return MapMembershipUser(user); + } + + return DefaultUser; + } + + public User Login(string userName, string password, bool isPersistent, string customData) + { + if (!ValidateUser(userName, password)) return default; + + // if IsPersistent is true, will keep logged in for up to a week (or until you logout) + var ticket = new FormsAuthenticationTicket( + version: 1, + name: userName, + issueDate: DateTime.Now, + expiration: DateTime.Now.AddMinutes(60), + isPersistent, + userData: customData ?? string.Empty, + FormsAuthentication.FormsCookiePath); + + var encryptedTicket = FormsAuthentication.Encrypt(ticket); + var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket) + { + HttpOnly = false, + Expires = ticket.Expiration + }; + + var httpContext = (HttpContextBase)ServiceContext.GetService(typeof(HttpContextBase)); + httpContext.Response.Cookies.Add(authCookie); + + var user = Membership.GetUser(userName); + + if (user == null) return default; + + return MapMembershipUser(user); + } + + public User Logout() + { + FormsAuthentication.SignOut(); + return DefaultUser; + } + + public void UpdateUser(User user) + { + } + } +} \ No newline at end of file diff --git a/src/SampleCRM.Web/Web.config b/src/SampleCRM.Web/Web.config index 990f35c..68d80b4 100644 --- a/src/SampleCRM.Web/Web.config +++ b/src/SampleCRM.Web/Web.config @@ -16,7 +16,9 @@ --> - + + + @@ -99,6 +101,12 @@ + + + + + + diff --git a/src/SampleCRM.Web/packages.config b/src/SampleCRM.Web/packages.config index 784c63b..4bf882e 100644 --- a/src/SampleCRM.Web/packages.config +++ b/src/SampleCRM.Web/packages.config @@ -1,13 +1,17 @@ - - - - - - - - - - - - + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/SampleCRM/App.xaml.cs b/src/SampleCRM/App.xaml.cs index 9f4f116..c5c301f 100644 --- a/src/SampleCRM/App.xaml.cs +++ b/src/SampleCRM/App.xaml.cs @@ -7,6 +7,7 @@ #endif using System; +using System.Net; using System.Windows; namespace SampleCRM @@ -20,6 +21,8 @@ public partial class App : Application public App() { + Current.Host.Settings.DefaultSoapCredentialsMode = CredentialsMode.Enabled; + Startup += Application_Startup; UnhandledException += Application_UnhandledException; @@ -33,7 +36,7 @@ public App() #if LOCAL_DEBUG BaseUrl = "http://localhost:7002/"; #elif DEBUG - BaseUrl = "http://localhost:54837/"; + BaseUrl = "https://localhost:44350/"; #elif LOCAL_RELEASE BaseUrl = "http://localhost:7002/"; #elif RELEASE @@ -41,7 +44,10 @@ public App() #else throw new NotSupportedException(); #endif - ((DomainClientFactory)DomainContext.DomainClientFactory).ServerBaseUri = new Uri(BaseUrl); + DomainContext.DomainClientFactory = new OpenRiaServices.DomainServices.Client.Web.WebAssemblySoapDomainClientFactory() + { + ServerBaseUri = new Uri(BaseUrl) + }; } private void Application_Startup(object sender, StartupEventArgs e) diff --git a/src/SampleCRM/SampleCRM.csproj b/src/SampleCRM/SampleCRM.csproj index 687ac30..d1b96c6 100644 --- a/src/SampleCRM/SampleCRM.csproj +++ b/src/SampleCRM/SampleCRM.csproj @@ -254,14 +254,8 @@ - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + MSBuild:Compile Designer