public IContainer BuildContainer() { var builder = new ContainerBuilder(); var userSubject = new Subject <User>(); builder.Register(x => userSubject).As <IObserver <User> >().SingleInstance(); builder.Register(x => userSubject).As <IObservable <User> >().SingleInstance(); #region Account builder.RegisterType <AccountDbContext>().As <IDbContext>().SingleInstance(); builder.RegisterType <AccountStore>().As <IUserStore <User> >().SingleInstance(); builder.RegisterType <AccountManager>().SingleInstance(); builder.RegisterType <AccountContext>().As <IAccountContext>().SingleInstance(); builder.RegisterType <RoleManager>().SingleInstance(); builder.RegisterType <ClientStore>().As <IClientStore>().SingleInstance(); #endregion #region Mail var mailService = new SMTPMailService(AppSettings.Get <SMTPMailSettings>(), AppSettings.Get <ProprietorSettings>()); builder.Register(m => mailService).As <IEmailService>().SingleInstance(); #endregion #region Storage builder.Register(c => new BlobService()).As <IBlobService>().SingleInstance(); builder.RegisterType <StorageRepository>().AsImplementedInterfaces <IStorageRepository, ConcreteReflectionActivatorData>().SingleInstance(); #endregion builder.RegisterApiControllers(typeof(Startup).Assembly); return(builder.Build()); }
public async Task <IHttpActionResult> ResendConfirmationEmail(string userId) { var user = await accountContext.FindUser(userId); if (user.EmailConfirmed) { return(Content( HttpStatusCode.BadRequest, new ErrorResponse() { Message = string.Concat("User with ", userId, " has already his email confirmed"), Data = new { emailAlreadyConfirmed = true } }, new JsonMediaTypeFormatter())); } var clientSettings = AppSettings.Get <ClientSettings>(); clientSettings.Validate(); var result = await accountContext.NotifyUserCreationByMail(user, clientSettings.WebCatUrl, clientSettings.ConfirmEmailPath, EmailTemplatesConfig.WelcomeEmailTemplate); if (!result.Success) { return(Content(HttpStatusCode.InternalServerError, result, new JsonMediaTypeFormatter())); } else { return(Ok(result)); } }
private static void ConfigureOAuth(IAppBuilder app, IContainer container) { var OAuthServerOptions = new OAuthAuthorizationServerOptions { AllowInsecureHttp = true, TokenEndpointPath = new PathString("/api/auth/token"), AccessTokenExpireTimeSpan = TimeSpan.FromDays(2), Provider = container.Resolve <IOAuthAuthorizationServerProvider>(), AccessTokenFormat = new TaskCatJWTFormat(AppSettings.Get <ClientSettings>().AuthenticationIssuerName, container.Resolve <IClientStore>()), RefreshTokenProvider = container.Resolve <IAuthenticationTokenProvider>() }; app.UseExternalSignInCookie(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ExternalCookie); // Generating Token with Providers app.UseOAuthAuthorizationServer(OAuthServerOptions); var externalLoginSettings = AppSettings.Get <ExternalLoginSettings>(); if (externalLoginSettings != null && externalLoginSettings.Facebook != null) { var facebookAuthOptions = new FacebookAuthenticationOptions() { AppId = externalLoginSettings.Facebook.AppId, AppSecret = externalLoginSettings.Facebook.AppSecret, Provider = new FacebookAuthProvider() }; app.UseFacebookAuthentication(facebookAuthOptions); } }
public IContainer BuildContainer(IAppBuilder app) { var builder = new ContainerBuilder(); #region Account builder.RegisterType <AuthDbContext>().As <IDbContext>().SingleInstance(); builder.RegisterType <AccountStore>().As <IUserStore <User> >().SingleInstance(); builder.RegisterType <AccountManager>().SingleInstance(); builder.RegisterType <AccountContext>().As <IAccountContext>().SingleInstance(); builder.RegisterType <RoleManager>().SingleInstance(); builder.RegisterType <ClientStore>().As <IClientStore>().SingleInstance(); #endregion #region Mail var mailService = new SMTPMailService(AppSettings.Get <SMTPMailSettings>(), AppSettings.Get <ProprietorSettings>()); builder.Register(m => mailService).As <IEmailService>().SingleInstance(); #endregion #region Storage builder.Register(c => new BlobService()).As <IBlobService>().SingleInstance(); builder.RegisterType <StorageRepository>().AsImplementedInterfaces <IStorageRepository, ConcreteReflectionActivatorData>().SingleInstance(); #endregion #region Auth builder.RegisterType <TaskCatOAuthProvider>() .AsImplementedInterfaces <IOAuthAuthorizationServerProvider, ConcreteReflectionActivatorData>().SingleInstance(); builder.RegisterType <TaskCatRefreshTokenProvider>() .AsImplementedInterfaces <IAuthenticationTokenProvider, ConcreteReflectionActivatorData>().SingleInstance(); #endregion builder.RegisterApiControllers(typeof(Startup).Assembly); return(builder.Build()); }
public async Task Test_ResendConfirmationEmail_With_FailedResult() { AppSettings.Set <ClientSettings>(new ClientSettings() { AuthenticationIssuerName = "TaskCat.Auth", ConfirmEmailPath = "confirmEmail", HostingAddress = "TestHostAddress", WebCatUrl = "WebCatUrl" }); Mock <IAccountContext> accountContextMock = new Mock <IAccountContext>(); accountContextMock.Setup(x => x.FindUser(It.IsAny <string>())).ReturnsAsync( new User(new UserRegistrationModel(), new UserProfile())); accountContextMock.Setup(x => x.NotifyUserCreationByMail(It.IsAny <User>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .ReturnsAsync(new SendEmailResponse(HttpStatusCode.InternalServerError, "Random mail error")); AccountController accountController = new AccountController(accountContextMock.Object); var result = await accountController.ResendConfirmationEmail("123"); Assert.IsInstanceOf <FormattedContentResult <SendEmailResponse> >(result); Assert.IsNotNull(result); FormattedContentResult <SendEmailResponse> convertedResult = result as FormattedContentResult <SendEmailResponse>; Assert.IsNotNull(convertedResult.Content); Assert.IsFalse(convertedResult.Content.Success); Assert.AreEqual(HttpStatusCode.InternalServerError, convertedResult.Content.StatusCode); }
public TaskCatAccountService() { #if DEBUG AppSettings.Precedence = new[] { "local", "production" }; #else AppSettings.Precedence = new[] { "production", "local" }; #endif this.listeningAddress = string.IsNullOrWhiteSpace(AppSettings.Get <ClientSettings>().HostingAddress) ? AppConstants.DefaultHostingAddress : AppSettings.Get <ClientSettings>().HostingAddress; }
public static void Configure() { var settings = AppSettings.Get <EmailTemplatePathSettings>(); // TODO: Need to fix this Assembly assembly = Assembly.GetExecutingAssembly(); string path = System.IO.Path.GetDirectoryName(assembly.Location); using (TextReader reader = new StreamReader(string.Concat(path, "/App_Data/EmailTemplates/", nameof(settings.Welcome), ".html"))) { WelcomeEmailTemplate = reader.ReadToEnd(); } //TODO: Adding email templates here for razor templating for ourselves //Engine.Razor.AddTemplate(nameof(settings.Welcome), ); }
private void InitiateConnection() { try { var searchSettings = AppSettings.Get <ElasticSearchSettings>(); if (searchSettings == null) { SearchEnabled = false; return; } var connectionUrl = new Uri(searchSettings.ConnectionString); var settings = new ConnectionSettings(connectionUrl); this.Client = new ElasticClient(settings); } catch (Exception) { //TODO: Log problems here } }
public async Task <IHttpActionResult> Register(RegistrationModelBase userModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = await accountContext.RegisterUser(userModel); if (!result.Result.Succeeded) { return(GetErrorResult(result.Result)); } var clientSettings = AppSettings.Get <ClientSettings>(); clientSettings.Validate(); await accountContext.NotifyUserCreationByMail(result.User, clientSettings.WebCatUrl, clientSettings.ConfirmEmailPath, EmailTemplatesConfig.WelcomeEmailTemplate); return(Created <UserModel>(Url.Link(AppConstants.GetUserProfileByIdRoute, new { userId = result.User.Id }), result.User.ToModel(isUserAuthenticated: false))); }
private static void ConfigureResourceOAuth(IAppBuilder app, IContainer container) { // INFO: As this is a auth-server and api-server together, Im adding back all possible added clients in the system and // allowing all of them to be able to access this api anyway var issuer = AppSettings.Get <ClientSettings>().AuthenticationIssuerName; var clientStore = container.Resolve <IClientStore>(); var allClients = clientStore.GetAllClients().GetAwaiter().GetResult(); var allowedAudiences = allClients.Select(x => x.Id); var issuerSecurityTokenProviders = allClients.Select( x => new SymmetricKeyIssuerSecurityTokenProvider(issuer, TextEncodings.Base64Url.Decode(x.Secret))); // Api controllers with an [Authorize] attribute will be validated with JWT app.UseJwtBearerAuthentication( new JwtBearerAuthenticationOptions { AuthenticationMode = AuthenticationMode.Active, AllowedAudiences = allowedAudiences, IssuerSecurityTokenProviders = issuerSecurityTokenProviders }); }
public IContainer BuildContainer() { var builder = new ContainerBuilder(); var jobActivitySubject = new Subject <JobActivity>(); builder.Register(x => jobActivitySubject).As <Subject <JobActivity> >().SingleInstance(); var jobSearchSubject = new Subject <Job>(); builder.Register(x => jobSearchSubject).As <IObserver <Job> >().SingleInstance(); builder.Register(x => jobSearchSubject).As <IObservable <Job> >().SingleInstance(); builder.RegisterType <ApiDbContext>().As <IDbContext>().SingleInstance(); builder.RegisterType <SearchContext>().As <ISearchContext>().SingleInstance(); #region Account builder.RegisterType <AccountStore>().As <IUserStore <User> >().SingleInstance(); builder.RegisterType <AccountManager>().SingleInstance(); builder.RegisterType <AccountContext>().As <IAccountContext>().SingleInstance(); builder.RegisterType <RoleManager>().SingleInstance(); builder.RegisterType <ClientStore>().As <IClientStore>().SingleInstance(); #endregion #region Payment builder.RegisterType <PaymentManager>().AsImplementedInterfaces <IPaymentManager, ConcreteReflectionActivatorData>().SingleInstance(); builder.RegisterType <PaymentService>().AsImplementedInterfaces <IPaymentService, ConcreteReflectionActivatorData>().SingleInstance(); #endregion #region Mail var mailService = new SMTPMailService(AppSettings.Get <SMTPMailSettings>(), AppSettings.Get <ProprietorSettings>()); builder.Register(m => mailService).As <IEmailService>().SingleInstance(); #endregion #region Job builder.RegisterType <LocalityService>() .AsImplementedInterfaces <ILocalityService, ConcreteReflectionActivatorData>() .SingleInstance(); builder.RegisterType <JobStore>().SingleInstance(); builder.RegisterType <JobManager>().AsImplementedInterfaces <IJobManager, ConcreteReflectionActivatorData>().SingleInstance(); builder.RegisterType <JobRepository>().AsImplementedInterfaces <IJobRepository, ConcreteReflectionActivatorData>().SingleInstance(); #endregion #region Order builder.RegisterType <SupportedOrderStore>().SingleInstance(); builder.RegisterType <OrderRepository>().AsImplementedInterfaces <IOrderRepository, ConcreteReflectionActivatorData>().SingleInstance(); #endregion #region Storage builder.Register(c => new BlobService()).As <IBlobService>().SingleInstance(); builder.RegisterType <StorageRepository>().AsImplementedInterfaces <IStorageRepository, ConcreteReflectionActivatorData>().SingleInstance(); #endregion #region Asset builder.RegisterType <DefaultAssetProvider>().AsImplementedInterfaces <IAssetProvider, ConcreteReflectionActivatorData>().SingleInstance(); #endregion #region Hrid builder.RegisterType <HRIDService>().AsImplementedInterfaces <IHRIDService, ConcreteReflectionActivatorData>().SingleInstance(); #endregion #region DropPoint builder.RegisterType <DropPointService>().AsImplementedInterfaces <IDropPointService, ConcreteReflectionActivatorData>().SingleInstance(); #endregion #region Vendor builder.RegisterType <VendorService>().AsImplementedInterfaces <IVendorService, ConcreteReflectionActivatorData>().SingleInstance(); #endregion #region Comment builder.RegisterType <CommentService>().AsImplementedInterfaces <ICommentService, ConcreteReflectionActivatorData>().SingleInstance(); #endregion #region Tags builder.RegisterType <DataTagService>().As <IDataTagService>().SingleInstance(); var tagsIndexSubject = new Subject <TagActivity>(); builder.Register(x => tagsIndexSubject).As <IObserver <TagActivity> >().SingleInstance(); builder.Register(x => tagsIndexSubject).As <IObservable <TagActivity> >().SingleInstance(); #endregion builder.RegisterApiControllers(typeof(Startup).Assembly); return(builder.Build()); }