public ApiController(IErpService service, IStorageService storage) : base(service) { Storage = storage; recMan = new RecordManager(service); secMan = new SecurityManager(service); entityManager = new EntityManager(storage); }
public ApiDevelopersController(IErpService service) : base(service) { em = new EntityManager(service.StorageService); rm = new EntityRelationManager(service.StorageService); recMan = new RecordManager(service); fs = service.StorageService.GetFS(); }
public void Authenticate(HttpContext context, IErpService service) { var tokenString = context.Request.Headers[AUTH_TOKEN_KEY]; if (string.IsNullOrEmpty(tokenString)) tokenString = context.Request.Cookies.Get(AUTH_TOKEN_KEY); if (tokenString != null) { AuthToken token = AuthToken.Decrypt(tokenString); if (token != null && token.Verify()) { var identity = GetIdentityFromCache(token.UserId); if (identity == null) { identity = CreateIdentity(token.UserId, service); //user has token, but identity cannot be created //1. user is disabled //2. user is missing if (identity == null) return; AddIdentityToCache(token.UserId, identity); } //when user is modified and issue old token //1. we don't authenticate it //2. clear identity from cache if (identity.User.ModifiedOn != token.LastModified) return; context.User = new ErpPrincipal(identity); } } }
/// <summary> /// The contructor /// </summary> /// <param name="service"></param> public RecordManager(IErpService service) { erpService = service; entityCache = new List<Entity>(); entityManager = new EntityManager(erpService.StorageService); entityRelationManager = new EntityRelationManager(erpService.StorageService); }
public void Login(HttpContext context, Guid userId, DateTime? modifiedOn, bool rememberMe, IErpService service) { var identity = CreateIdentity(userId, service); if (identity == null) throw new Exception("Try to login with invalid user."); if (modifiedOn != identity.User.ModifiedOn) modifiedOn = identity.User.ModifiedOn; string token = AuthToken.Create(userId, modifiedOn, rememberMe).Encrypt(); if (rememberMe) { CookieOptions options = new CookieOptions(); options.Expires = DateTime.Today.AddDays(AUTH_REMEMBER_IDENTITY_DAYS); context.Response.Cookies.Append(AUTH_TOKEN_KEY, token, options); } else context.Response.Cookies.Append(AUTH_TOKEN_KEY, token); context.User = new ErpPrincipal(identity); //TODO //var dataGateway = new DataGateway(service); //dataGateway.UpdateUserLastLoginTime(userId); //dataGateway.CreateLoginLog(identity.User, identity.Customer); }
public static void Configure(IErpService service) { if (alreadyConfigured) return; lock( lockObj ) { if (alreadyConfigured) return; alreadyConfigured = true; Mapper.CreateMap<Guid, string>().ConvertUsing<GuidToStringConverter>(); Mapper.CreateMap<DateTimeOffset, DateTime>().ConvertUsing<DateTimeTypeConverter>(); Mapper.AddProfile(new EntityRelationProfile(service)); Mapper.AddProfile(new EntityProfile(service)); Mapper.AddProfile(new RecordPermissionsProfile(service)); Mapper.AddProfile(new FieldPermissionsProfile(service)); Mapper.AddProfile(new FieldProfile(service)); Mapper.AddProfile(new RecordsListProfile(service)); Mapper.AddProfile(new RecordViewProfile(service)); Mapper.AddProfile(new RecordTreeProfile(service)); Mapper.AddProfile(new EntityRelationOptionsProfile(service)); //Mapper.AddProfile(new RecordViewFieldProfile(service)); Mapper.CreateMap<EntityRecord, ErpUser>().ConvertUsing(new ErpUserConverter()); Mapper.CreateMap<ErpUser, EntityRecord>().ConvertUsing(new ErpUserConverterOposite()); Mapper.CreateMap<EntityRecord, ErpRole>().ConvertUsing(new ErpRoleConverter()); } }
public static void Configure(IErpService service) { if (alreadyConfigured) { return; } lock ( lockObj ) { if (alreadyConfigured) { return; } alreadyConfigured = true; Mapper.CreateMap <Guid, string>().ConvertUsing <GuidToStringConverter>(); Mapper.CreateMap <DateTimeOffset, DateTime>().ConvertUsing <DateTimeTypeConverter>(); Mapper.AddProfile(new EntityRelationProfile(service)); Mapper.AddProfile(new EntityProfile(service)); Mapper.AddProfile(new RecordPermissionsProfile(service)); Mapper.AddProfile(new FieldPermissionsProfile(service)); Mapper.AddProfile(new FieldProfile(service)); Mapper.AddProfile(new RecordsListProfile(service)); Mapper.AddProfile(new RecordViewProfile(service)); Mapper.AddProfile(new RecordTreeProfile(service)); Mapper.AddProfile(new EntityRelationOptionsProfile(service)); //Mapper.AddProfile(new RecordViewFieldProfile(service)); Mapper.CreateMap <EntityRecord, ErpUser>().ConvertUsing(new ErpUserConverter()); Mapper.CreateMap <ErpUser, EntityRecord>().ConvertUsing(new ErpUserConverterOposite()); Mapper.CreateMap <EntityRecord, ErpRole>().ConvertUsing(new ErpRoleConverter()); } }
public static string Login(HttpContext context, Guid userId, DateTime? modifiedOn, bool rememberMe, IErpService service) { var identity = CreateIdentity(userId, service); if (identity == null) throw new Exception("Try to login with invalid user."); if (modifiedOn != identity.User.ModifiedOn) modifiedOn = identity.User.ModifiedOn; ErpUser user = new SecurityManager(service).GetUser(userId); string token = AuthToken.Create(user, rememberMe).Encrypt(); if (rememberMe) { CookieOptions options = new CookieOptions(); options.Expires = DateTime.Today.AddDays(AUTH_REMEMBER_IDENTITY_DAYS); context.Response.Cookies.Append(AUTH_TOKEN_KEY, token, options); } else context.Response.Cookies.Append(AUTH_TOKEN_KEY, token); context.User = new ErpPrincipal(identity); new SecurityManager(service).UpdateUserLastLoginTime(userId); return token; }
public CheckoutController(IShoppingCartService shoppingCartService, ICatalogService catalogService, IFinanceService financeService, IErpService erpService, ApplicationUserManager userManager) { this.shoppingCartService = shoppingCartService; this.catalogService = catalogService; this.financeService = financeService; this.erpService = erpService; this.userManager = userManager; }
public OrderOnlineService( IEmalService emailService, IErpService erpService ) { _emailService = emailService; _erpService = erpService; }
internal RecordManager(IErpService service, bool ignoreSecurity = false) { erpService = service; entityCache = new List<Entity>(); entityManager = new EntityManager(erpService.StorageService); entityRelationManager = new EntityRelationManager(erpService.StorageService); this.ignoreSecurity = ignoreSecurity; }
public AdminController(IErpService erpService) { recMan = new RecordManager(); secMan = new SecurityManager(); entMan = new EntityManager(); relMan = new EntityRelationManager(); this.erpService = erpService; }
public static IApplicationBuilder UseErp(this IApplicationBuilder app, List <JobType> additionalJobTypes = null, string configFolder = null) { using (var secCtx = SecurityContext.OpenSystemScope()) { IConfiguration configuration = app.ApplicationServices.GetService <IConfiguration>(); IHostingEnvironment env = app.ApplicationServices.GetService <IHostingEnvironment>(); string configPath = "config.json"; if (!string.IsNullOrWhiteSpace(configFolder)) { configPath = System.IO.Path.Combine(configFolder, configPath); } var configurationBuilder = new ConfigurationBuilder().SetBasePath(env.ContentRootPath).AddJsonFile(configPath); ErpSettings.Initialize(configurationBuilder.Build()); IErpService service = null; try { DbContext.CreateContext(ErpSettings.ConnectionString); service = app.ApplicationServices.GetService <IErpService>(); var cfg = ErpAutoMapperConfiguration.MappingExpressions; // var cfg = new AutoMapper.Configuration.MapperConfigurationExpression(); ErpAutoMapperConfiguration.Configure(cfg); ErpWebAutoMapperConfiguration.Configure(cfg); //this method append plugin automapper configuration service.SetAutoMapperConfiguration(); //this should be called after plugin init AutoMapper.Mapper.Initialize(cfg); service.InitializeSystemEntities(); CheckCreateHomePage(); service.InitializeBackgroundJobs(additionalJobTypes); ErpAppContext.Init(app.ApplicationServices); //this is called after automapper setup service.InitializePlugins(app.ApplicationServices); } finally { DbContext.CloseContext(); } if (service != null) { service.StartBackgroundJobProcess(); } return(app); } }
public static void Authenticate(HttpContext context, IErpService service) { string tokenString = context.Request.Headers[AUTH_TOKEN_KEY]; if (String.IsNullOrEmpty(tokenString)) { var cookie = context.Request.Cookies.FirstOrDefault(c => c.Key == AUTH_TOKEN_KEY); tokenString = cookie.Value.FirstOrDefault(); } if (tokenString != null) { AuthToken token = AuthToken.Decrypt(tokenString); if (token != null && token.Verify()) { var identity = GetIdentityFromCache(token.UserId); if (identity == null) { identity = CreateIdentity(token.UserId, service); //user has token, but identity cannot be created //1. user is disabled //2. user is missing if (identity == null) { return; } AddIdentityToCache(token.UserId, identity); } //when user is modified and issue old token //1. we don't authenticate it //2. clear identity from cache if (identity.User.ModifiedOn != token.LastModified) { RemoveIdentityFromCache(identity.User.Id); identity = CreateIdentity(token.UserId, service); //user has token, but identity cannot be created //1. user is disabled //2. user is missing if (identity == null) { return; } AddIdentityToCache(token.UserId, identity); return; } context.User = new ErpPrincipal(identity); } } }
public ProductsViewModel(IMvxNavigationService navigationService, IErpService service, IMvxMessenger messenger, IAuthenticationService authenticationService) { this.navigationService = navigationService; this.service = service; this.CurrentUserName = authenticationService.UserName; this.productUpdatedMessageToken = messenger.SubscribeOnThreadPoolThread <ProductUpdatedMessage>(OnProductUpdated); this.productDeletedMessageToken = messenger.SubscribeOnMainThread <ProductDeletedMessage>(OnProductDeleted); this.ProductStockCount = 12800; ExpectedStockQuantitues = new NameValuePair[] { new NameValuePair(DateTime.Today.AddMonths(-2).ToString("MMMM"), 1500), new NameValuePair(DateTime.Today.AddMonths(-1).ToString("MMMM"), 1400), new NameValuePair(DateTime.Today.ToString("MMMM"), 1600), }; ActualStockQuantitues = new NameValuePair[] { new NameValuePair(DateTime.Today.AddMonths(-2).ToString("MMMM"), 1723), new NameValuePair(DateTime.Today.AddMonths(-1).ToString("MMMM"), 1413), new NameValuePair(DateTime.Today.ToString("MMMM"), 2313), }; TopStockProducts = new NameValuePair[] { new NameValuePair("A", 1423), new NameValuePair("B", 2621), new NameValuePair("C", 1724), new NameValuePair("D", 2223), new NameValuePair("E", 1383) }; TopSoldProducts = new NameValuePair[] { new NameValuePair("A", 14100), new NameValuePair("B", 12200), new NameValuePair("C", 11300) }; StorageLocations = new NameValuePair[] { new NameValuePair("New York", 0.35), new NameValuePair("Ohio", 0.30), new NameValuePair("California", 0.35), }; currentLayoutMode = LayoutMode.Grid; ToggleLayoutModeCommand = new Command <LayoutMode?>(ChangeLayoutMode); this.CreateProductCommand = new MvxCommand(OnCreateProduct); this.EditProductCommand = new MvxCommand <Product>(OnEditProduct); this.DeleteProductCommand = new MvxAsyncCommand <Product>(OnDeleteProduct); this.SearchCommand = new MvxAsyncCommand(OnSearch); this.AboutCommand = new MvxCommand(ShowAboutPage); this.listDescription = "All Products"; }
internal static ErpIdentity CreateIdentity(Guid?userId, IErpService service) { SecurityManager secMan = new SecurityManager(service); ErpUser user = secMan.GetUser(userId.Value); if (user == null || !user.Enabled) { return(null); } return(new ErpIdentity { User = user }); }
public VendorsViewModel(IMvxNavigationService navigationService, IErpService service, IMvxMessenger messenger, IAuthenticationService authenticationService) { this.navigationService = navigationService; this.service = service; this.CurrentUserName = authenticationService.UserName; this.vendorUpdatedMessageToken = messenger.SubscribeOnThreadPoolThread <VendorUpdatedMessage>(OnVendorUpdated); this.vendorDeletedMessageToken = messenger.SubscribeOnMainThread <VendorDeletedMessage>(OnVendorDeleted); this.currentLayoutMode = LayoutMode.Grid; this.ToggleLayoutModeCommand = new Command <LayoutMode?>(ChangeLayoutMode); this.SearchCommand = new MvxAsyncCommand(OnSearch); this.AboutCommand = new MvxCommand(ShowAboutPage); this.CreateVendorCommand = new MvxCommand(OnCreateVendor); this.EditVendorCommand = new MvxCommand <Vendor>(OnEditVendor); this.DeleteVendorCommand = new MvxAsyncCommand <Vendor>(OnDeleteVendor); this.listDescription = "All Vendors"; }
public ApiControllerBase(IErpService service) { this.service = service; }
public FieldPermissionsProfile(IErpService service) { this.service = service; }
public HomeController(IErpService service) : base(service) { }
public EntityRelationOptionsProfile(IErpService service) { this.service = service; }
public void Configure(IApplicationBuilder app, IHostingEnvironment env) { //TODO Create db context CultureInfo.DefaultThreadCurrentCulture = CultureInfo.GetCultureInfo("en-US"); CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.GetCultureInfo("en-US"); Settings.Initialize(Configuration); try { DbContext.CreateContext(Settings.ConnectionString); IErpService service = app.ApplicationServices.GetService <IErpService>(); AutoMapperConfiguration.Configure(); service.InitializeSystemEntities(); //app.UseDebugLogMiddleware(); app.UseSecurityMiddleware(); app.UseDatabaseContextMiddleware(); IPluginService pluginService = app.ApplicationServices.GetService <IPluginService>(); IHostingEnvironment hostingEnvironment = app.ApplicationServices.GetRequiredService <IHostingEnvironment>(); pluginService.Initialize(hostingEnvironment); IWebHookService webHookService = app.ApplicationServices.GetService <IWebHookService>(); webHookService.Initialize(pluginService); } finally { DbContext.CloseContext(); } //Enable CORS //app.Use((context, next) => //{ // context.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" }); // context.Response.Headers.Add("Access-Control-Allow-Headers", new[] { "*" }); // context.Response.Headers.Add("Access-Control-Allow-Methods", new[] { "*" }); // return next(); //}); //app.Run(async context => //{ // IErpService service = app.ApplicationServices.GetService<IErpService>(); // service.Run(); // context.Response.ContentType = "text/html"; // context.Response.StatusCode = 200; // System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding(); // byte[] buffer = encoding.GetBytes("<h1>test</h1>"); // await context.Response.Body.WriteAsync(buffer, 0, buffer.Length); //}); // Add the following to the request pipeline only in development environment. if (string.Equals(env.EnvironmentName, "Development", StringComparison.OrdinalIgnoreCase)) { app.UseDeveloperExceptionPage(); } else { // Add Error handling middleware which catches all application specific errors and // send the request to the following path or controller action. app.UseExceptionHandler("/Home/Error"); } app.UseIISPlatformHandler(options => options.AutomaticAuthentication = false); // Add static files to the request pipeline. app.UseStaticFiles(); // Add MVC to the request pipeline. app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller}/{action}/{id?}", defaults: new { controller = "Home", action = "Index" }); // Uncomment the following line to add a route for porting Web API 2 controllers. // routes.MapWebApiRoute("DefaultApi", "api/{controller}/{id?}"); }); }
public RecordViewProfile(IErpService service) { this.service = service; }
internal static object GetCurrentUserPermissions(HttpContext context, IErpService service) { if (context == null) { throw new NullReferenceException("context"); } ErpUser user = null; if (context.User != null && context.User is ErpPrincipal) { var identity = (context.User as ErpPrincipal).Identity as ErpIdentity; if (identity != null) { user = identity.User; } } EntityManager entMan = new EntityManager(service.StorageService); var entities = entMan.ReadEntities().Object.Entities; List <object> permissions = new List <object>(); foreach (var entity in entities) { bool canRead = false; bool canCreate = false; bool canUpdate = false; bool canDelete = false; if (user != null) { canRead = user.Roles.Any(x => entity.RecordPermissions.CanRead.Any(z => z == x.Id)); canCreate = user.Roles.Any(x => entity.RecordPermissions.CanCreate.Any(z => z == x.Id)); canUpdate = user.Roles.Any(x => entity.RecordPermissions.CanUpdate.Any(z => z == x.Id)); canDelete = user.Roles.Any(x => entity.RecordPermissions.CanDelete.Any(z => z == x.Id)); } else { canRead = entity.RecordPermissions.CanRead.Any(z => z == SystemIds.GuestRoleId); canCreate = entity.RecordPermissions.CanCreate.Any(z => z == SystemIds.GuestRoleId); canUpdate = entity.RecordPermissions.CanUpdate.Any(z => z == SystemIds.GuestRoleId); canDelete = entity.RecordPermissions.CanDelete.Any(z => z == SystemIds.GuestRoleId); } if (canRead || canCreate || canUpdate || canDelete) { permissions.Add(new { entityId = entity.Id, entityName = entity.Name, canRead = canRead, canCreate = canCreate, canUpdate = canUpdate, canDelete = canDelete }); } } return(permissions); }
public SecurityManager(IErpService service) { this.service = service; }
public RecordTreeProfile(IErpService service) { this.service = service; }
public AppStart(IMvxApplication application, IMvxNavigationService navigationService, IAuthenticationService authenticationService, IErpService erpService) : base(application, navigationService) { this.authenticationService = authenticationService; this.erpService = erpService; }
public static IApplicationBuilder UseErp(this IApplicationBuilder app, List <JobType> additionalJobTypes = null, string configFolder = null) { using (var secCtx = SecurityContext.OpenSystemScope()) { IConfiguration configuration = app.ApplicationServices.GetService <IConfiguration>(); IHostingEnvironment env = app.ApplicationServices.GetService <IHostingEnvironment>(); string configPath = "config.json"; if (!string.IsNullOrWhiteSpace(configFolder)) { configPath = System.IO.Path.Combine(configFolder, configPath); } var configurationBuilder = new ConfigurationBuilder().SetBasePath(env.ContentRootPath).AddJsonFile(configPath); ErpSettings.Initialize(configurationBuilder.Build()); var defaultThreadCulture = CultureInfo.DefaultThreadCurrentCulture; var defaultThreadUICulture = CultureInfo.DefaultThreadCurrentUICulture; CultureInfo customCulture = new CultureInfo("en-US"); customCulture.NumberFormat.NumberDecimalSeparator = "."; IErpService service = null; try { DbContext.CreateContext(ErpSettings.ConnectionString); service = app.ApplicationServices.GetService <IErpService>(); var cfg = ErpAutoMapperConfiguration.MappingExpressions; // var cfg = new AutoMapper.Configuration.MapperConfigurationExpression(); ErpAutoMapperConfiguration.Configure(cfg); ErpWebAutoMapperConfiguration.Configure(cfg); //this method append plugin automapper configuration service.SetAutoMapperConfiguration(); //this should be called after plugin init AutoMapper.Mapper.Initialize(cfg); //we used en-US based culture settings for initialization and patch execution { CultureInfo.DefaultThreadCurrentCulture = customCulture; CultureInfo.DefaultThreadCurrentUICulture = customCulture; service.InitializeSystemEntities(); CultureInfo.DefaultThreadCurrentCulture = defaultThreadCulture; CultureInfo.DefaultThreadCurrentUICulture = defaultThreadUICulture; } CheckCreateHomePage(); service.InitializeBackgroundJobs(additionalJobTypes); ErpAppContext.Init(app.ApplicationServices); { //switch culture for patch executions and initializations CultureInfo.DefaultThreadCurrentCulture = customCulture; CultureInfo.DefaultThreadCurrentUICulture = customCulture; //this is called after automapper setup service.InitializePlugins(app.ApplicationServices); CultureInfo.DefaultThreadCurrentCulture = defaultThreadCulture; CultureInfo.DefaultThreadCurrentUICulture = defaultThreadUICulture; } } finally { DbContext.CloseContext(); CultureInfo.DefaultThreadCurrentCulture = defaultThreadCulture; CultureInfo.DefaultThreadCurrentUICulture = defaultThreadUICulture; } if (service != null) { service.StartBackgroundJobProcess(); } return(app); } }
public PriceService(IErpService erpService) { _erpService = erpService; }
public RecordPermissionsProfile(IErpService service) { this.service = service; }
public ErpDebugLogMiddleware(RequestDelegate next, IErpService service) { this.next = next; this.service = service; }
internal static ErpIdentity CreateIdentity(Guid? userId, IErpService service) { SecurityManager secMan = new SecurityManager(service); ErpUser user = secMan.GetUser(userId.Value); if (user == null || !user.Enabled) return null; return new ErpIdentity { User = user }; }
/// <summary> /// The contructor /// </summary> /// <param name="service"></param> public RecordManager(IErpService service) : this(service, false) { }
public SecurityMiddleware(RequestDelegate next, IErpService service) { this.next = next; this.service = service; }
public EntityProfile(IErpService service) { this.service = service; }
internal static object GetCurrentUserPermissions(HttpContext context, IErpService service) { if (context == null) throw new NullReferenceException("context"); ErpUser user = null; if (context.User != null && context.User is ErpPrincipal) { var identity = (context.User as ErpPrincipal).Identity as ErpIdentity; if (identity != null) user = identity.User; } EntityManager entMan = new EntityManager(service.StorageService); var entities = entMan.ReadEntities().Object.Entities; List<object> permissions = new List<object>(); foreach (var entity in entities) { bool canRead = false; bool canCreate = false; bool canUpdate = false; bool canDelete = false; if (user != null) { canRead = user.Roles.Any(x => entity.RecordPermissions.CanRead.Any(z => z == x.Id)); canCreate = user.Roles.Any(x => entity.RecordPermissions.CanCreate.Any(z => z == x.Id)); canUpdate = user.Roles.Any(x => entity.RecordPermissions.CanUpdate.Any(z => z == x.Id)); canDelete = user.Roles.Any(x => entity.RecordPermissions.CanDelete.Any(z => z == x.Id)); } else { canRead = entity.RecordPermissions.CanRead.Any(z => z == SystemIds.GuestRoleId); canCreate = entity.RecordPermissions.CanCreate.Any(z => z == SystemIds.GuestRoleId); canUpdate = entity.RecordPermissions.CanUpdate.Any(z => z == SystemIds.GuestRoleId); canDelete = entity.RecordPermissions.CanDelete.Any(z => z == SystemIds.GuestRoleId); } if (canRead || canCreate || canUpdate || canDelete) permissions.Add(new { entityId = entity.Id, entityName = entity.Name, canRead = canRead, canCreate = canCreate, canUpdate = canUpdate, canDelete = canDelete }); } return permissions; }
public void Configure(IApplicationBuilder app, IServiceProvider serviceProvider) { //TODO Create db context CultureInfo.DefaultThreadCurrentCulture = CultureInfo.GetCultureInfo("en-US"); CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.GetCultureInfo("en-US"); Settings.Initialize(Configuration); IErpService service = null; try { DbContext.CreateContext(Settings.ConnectionString); service = app.ApplicationServices.GetService <IErpService>(); AutoMapperConfiguration.Configure(); service.InitializeSystemEntities(); service.InitializeBackgroundJobs(); app.UseErpMiddleware(); //IHostingEnvironment env = app.ApplicationServices.GetService<IHostingEnvironment>(); //if (env.IsDevelopment()) app.UseDeveloperExceptionPage(); IPluginService pluginService = app.ApplicationServices.GetService <IPluginService>(); IHostingEnvironment hostingEnvironment = app.ApplicationServices.GetRequiredService <IHostingEnvironment>(); pluginService.Initialize(serviceProvider); IWebHookService webHookService = app.ApplicationServices.GetService <IWebHookService>(); webHookService.Initialize(pluginService); NotificationContext.Initialize(); NotificationContext.Current.SendNotification(new Notification { Channel = "*", Message = "ERP configuration loaded and completed." }); } finally { DbContext.CloseContext(); } if (service != null) { service.StartBackgroundJobProcess(); } //Enable CORS //app.Use((context, next) => //{ // context.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" }); // context.Response.Headers.Add("Access-Control-Allow-Headers", new[] { "*" }); // context.Response.Headers.Add("Access-Control-Allow-Methods", new[] { "*" }); // return next(); //}); //app.Run(async context => //{ // IErpService service = app.ApplicationServices.GetService<IErpService>(); // service.Run(); // context.Response.ContentType = "text/html"; // context.Response.StatusCode = 200; // System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding(); // byte[] buffer = encoding.GetBytes("<h1>test</h1>"); // await context.Response.Body.WriteAsync(buffer, 0, buffer.Length); //}); // Add the following to the request pipeline only in development environment. if (string.Equals(hostingEnviroment.EnvironmentName, "Development", StringComparison.OrdinalIgnoreCase)) { app.UseDeveloperExceptionPage(); } else { // Add Error handling middleware which catches all application specific errors and // send the request to the following path or controller action. app.UseExceptionHandler("/Home/Error"); } //TODO Check what was done here in RC1 //app.UseIISPlatformHandler(options => options.AutomaticAuthentication = false); //Should be before Static files app.UseResponseCompression(); // Add static files to the request pipeline. Should be last middleware. app.UseStaticFiles(new StaticFileOptions { OnPrepareResponse = ctx => { const int durationInSeconds = 60 * 60 * 24 * 30; //30 days caching of these resources ctx.Context.Response.Headers[HeaderNames.CacheControl] = "public,max-age=" + durationInSeconds; } }); // Add MVC to the request pipeline. app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller}/{action}/{id?}", defaults: new { controller = "Home", action = "Index" }); // Uncomment the following line to add a route for porting Web API 2 controllers. // routes.MapWebApiRoute("DefaultApi", "api/{controller}/{id?}"); }); }
public DebugLogMiddleware(RequestDelegate next, IErpService service) { this.next = next; this.service = service; }
internal ErpIdentity CreateIdentity(Guid? userId, IErpService service) { return null; //User userClaim = new User(); //userClaim.Id = user.Id; //userClaim.FirstName = user.FirstName; //userClaim.LastName = user.LastName; //userClaim.Email = user.Email; //userClaim.ModifiedOn = user.ModifiedOn; //userClaim.Roles = user.Roles; //return CreateIdentity(userClaim); }
public FieldProfile(IErpService service) { this.service = service; }
public static string Login(HttpContext context, Guid userId, DateTime?modifiedOn, bool rememberMe, IErpService service) { var identity = CreateIdentity(userId, service); if (identity == null) { throw new Exception("Try to login with invalid user."); } if (modifiedOn != identity.User.ModifiedOn) { modifiedOn = identity.User.ModifiedOn; } ErpUser user = new SecurityManager(service).GetUser(userId); string token = AuthToken.Create(user, rememberMe).Encrypt(); if (rememberMe) { CookieOptions options = new CookieOptions(); options.Expires = DateTime.Today.AddDays(AUTH_REMEMBER_IDENTITY_DAYS); context.Response.Cookies.Append(AUTH_TOKEN_KEY, token, options); } else { context.Response.Cookies.Append(AUTH_TOKEN_KEY, token); } context.User = new ErpPrincipal(identity); new SecurityManager(service).UpdateUserLastLoginTime(userId); return(token); }
public EntityRelationProfile(IErpService service) { this.service = service; }
public ApiSandboxController(IErpService service) : base(service) { }
public RecordsListProfile(IErpService service) { this.service = service; }