/// <summary> /// Use predefined credential routine, return a logged-in WikiSite instance. /// </summary> public static async Task <WikiSite> EarlyLoginAsync(IWikiClient wikiClient, SiteOptions options) { if (wikiClient == null) { throw new ArgumentNullException(nameof(wikiClient)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } if (EarlyLoginCoreAsyncHandler == null) { throw new NotSupportedException("To enable login feature, you should set `EarlyLoginCoreAsyncHandler` in `Initialize` private function. See http://github.com/cxuesong/WikiClientLibrary for more information."); } var site = await EarlyLoginCoreAsyncHandler(wikiClient, options); if (!site.Initialization.IsCompleted) { throw new InvalidOperationException("You forgot to await WikiSite.Initialization in your EarlyLoginCoreAsyncHandler implementation."); } if (site == null) { throw new NotSupportedException("Your EarlyLoginCoreAsyncHandler implementation returned null for site: " + options.ApiEndpoint + "."); } if (!site.AccountInfo.IsUser) { throw new NotSupportedException("Failed to login into: " + site + " . Check your EarlyLoginCoreAsyncHandler implementation."); } return(site); }
protected override void UpdateAttribute(IUpdateBuilder <UserEntity> update, string name, object value) { switch (name) { case nameof(UserResource.ParatextId): if (value == null) { update.Unset(u => u.ParatextId); update.Unset(u => u.ParatextTokens); } break; case nameof(UserResource.Site): SiteOptions siteOptions = _siteOptions.Value; string siteKey = siteOptions.Id; if (value == null) { update.Unset(u => u.Sites[siteKey]); } else if (((Site)value).CurrentProjectId == null) { update.Unset(u => u.Sites[siteKey].CurrentProjectId); } else { update.Set(u => u.Sites[siteKey].CurrentProjectId, ((Site)value).CurrentProjectId); } break; default: base.UpdateAttribute(update, name, value); break; } }
public SiteAdministratorClaimsTransformation( SiteOptions siteOptions, ILogger <SiteAdministratorClaimsTransformation> logger) { _siteOptions = siteOptions; _logger = logger; }
private void ConfigureAuthentication(IServiceCollection services) { var siteOptions = new SiteOptions(); Configuration.GetSection("site").Bind(siteOptions); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, RequireExpirationTime = true, RequireSignedTokens = true, LifetimeValidator = (DateTime? notBefore, DateTime? expires, SecurityToken securityToken, TokenValidationParameters validationParameters) => { var before = notBefore == null || notBefore <= DateTime.UtcNow; var after = expires == null || expires >= DateTime.UtcNow; return(before && after); }, ValidIssuer = siteOptions.Jwt.ValidIssuer, ValidAudience = siteOptions.Jwt.ValidAudience, IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(siteOptions.Jwt.IssuerSigningKey)), }; }); }
/// <summary> /// Builds the value to use for the <c>Public-Key-Pins</c> HTTP response header. /// </summary> /// <param name="options">The current site configuration options.</param> /// <param name="reportOnly">Whether to generate the header as report-only.</param> /// <returns> /// A <see cref="string"/> containing the <c>Public-Key-Pins</c> value to use. /// </returns> private static string BuildPublicKeyPins(SiteOptions options, bool reportOnly) { var builder = new StringBuilder(); if (options?.PublicKeyPins?.Sha256Hashes?.Length > 0) { builder.AppendFormat("max-age={0};", (int)options.PublicKeyPins.MaxAge.TotalSeconds); foreach (var hash in options.PublicKeyPins.Sha256Hashes) { builder.Append($@" pin-sha256=""{hash}"";"); } if (options.PublicKeyPins.IncludeSubdomains) { builder.Append(" includeSubDomains;"); } if (reportOnly && options?.ExternalLinks?.Reports?.PublicKeyPinsReportOnly != null) { builder.Append($" report-uri=\"{options.ExternalLinks.Reports.PublicKeyPinsReportOnly}\";"); } if (!reportOnly) { builder.Append($" report-uri=\"{options.ExternalLinks.Reports.PublicKeyPins}\";"); } } return(builder.ToString()); }
public Sites(long siteid) { this.SiteNotificationTemplates = new SiteNotificationTemplates(this); this.SiteOptions = new SiteOptions(this); this.ID = siteid; this.ParentID = -1L; this.OwnerUserID = -1L; this.Name = ""; this.LogoUrl = ""; this.Company = ""; this.Address = ""; this.PostCode = ""; this.ResponsiblePerson = ""; this.ContactPerson = ""; this.Telephone = ""; this.Fax = ""; this.Mobile = ""; this.Email = ""; this.QQ = ""; this.ServiceTelephone = ""; this.ICPCert = ""; this.Level = -1; this.ON = false; this.BonusScale = 0.0; this.MaxSubSites = 0; this.UseLotteryListRestrictions = ""; this.UseLotteryList = ""; this.UseLotteryListQuickBuy = ""; this.AdministratorID = -1L; this._urls = ""; this.Url = ""; this.PageTitle = ""; this.PageKeywords = ""; }
/// <summary> /// Builds the value to use for the <c>Expect-CT</c> HTTP response header. /// </summary> /// <param name="options">The current site configuration options.</param> /// <returns> /// A <see cref="string"/> containing the <c>Expect-CT</c> value to use. /// </returns> private static string BuildExpectCT(SiteOptions options) { var builder = new StringBuilder(); bool enforce = options.CertificateTransparency?.Enforce == true; if (enforce) { builder.Append("enforce; "); } builder.AppendFormat( CultureInfo.InvariantCulture, "max-age={0};", (int)options.CertificateTransparency?.MaxAge.TotalSeconds); if (enforce) { if (options?.ExternalLinks?.Reports?.ExpectCTEnforce != null) { builder.Append($" report-uri {options.ExternalLinks.Reports.ExpectCTEnforce}"); } } else { if (options?.ExternalLinks?.Reports?.ExpectCTReportOnly != null) { builder.Append($" report-uri {options.ExternalLinks.Reports.ExpectCTReportOnly}"); } } return(builder.ToString()); }
/// <summary> /// Returns an <see cref="ApplicationAuthorizationBuilder"/> used to configure authentication for the application. /// </summary> /// <param name="builder">The <see cref="AuthenticationBuilder"/> to create the builder with.</param> /// <param name="options">The <see cref="SiteOptions"/> to use.</param> /// <param name="applicationServices">A delegate to a method that retrieves the application services.</param> /// <returns> /// The <see cref="ApplicationAuthorizationBuilder"/> to use to configure authentication for the application. /// </returns> private static ApplicationAuthorizationBuilder AsApplicationBuilder( this AuthenticationBuilder builder, SiteOptions options, Func <IServiceProvider> applicationServices) { return(new ApplicationAuthorizationBuilder(builder, options, applicationServices)); }
/// <summary> /// Create a wiki site, login if necessary. /// </summary> private async Task <WikiSite> CreateWikiSiteAsync(IWikiClient wikiClient, string url) { WikiSite site; if (url.Contains(".wikia.com")) { var uri = new Uri(url, UriKind.Absolute); var options = new WikiaSiteOptions(uri.GetLeftPart(UriPartial.Authority) + "/") { AccountAssertion = AccountAssertionBehavior.AssertAll, }; site = new WikiaSite(wikiClient, options) { Logger = OutputLoggerFactory.CreateLogger <WikiaSite>() }; } else { var options = new SiteOptions(url) { AccountAssertion = AccountAssertionBehavior.AssertAll, }; site = new WikiSite(wikiClient, options) { Logger = OutputLoggerFactory.CreateLogger <WikiSite>() }; } await site.Initialization; if (sitesNeedsLogin.Contains(url)) { await CredentialManager.LoginAsync(site); } return(site); }
public async Task SendEmailAsync(string email, string subject, string body) { SiteOptions siteOptions = _options.Value; string fromAddress = siteOptions.EmailFromAddress; string title = siteOptions.Name; var mimeMessage = new MimeMessage(); mimeMessage.From.Add(new MailboxAddress(title, fromAddress)); mimeMessage.To.Add(new MailboxAddress("", email)); mimeMessage.Subject = subject; var bodyBuilder = new BodyBuilder(); bodyBuilder.HtmlBody = body; mimeMessage.Body = bodyBuilder.ToMessageBody(); if (siteOptions.SendEmail) { using (var client = new SmtpClient()) { await client.ConnectAsync(siteOptions.SmtpServer, Convert.ToInt32(siteOptions.PortNumber), SecureSocketOptions.None); await client.SendAsync(mimeMessage); await client.DisconnectAsync(true); } } _logger.LogInformation("Email Sent\n{0}", mimeMessage.ToString()); }
public SitemapService(ICrowdactionService crowdactionService, IImageService imageService, IOptions <SiteOptions> siteOptions, ILogger <SitemapService> logger) { this.logger = logger; this.crowdactionService = crowdactionService; this.imageService = imageService; this.siteOptions = siteOptions.Value; }
public AccountController( IHtmlLocalizer htmlLocalizer, IStringLocalizer stringLocalizer, IViewProviderManager <UserRegistration> registerViewProvider, IViewProviderManager <LoginPage> loginViewProvider, IOptions <IdentityOptions> identityOptions, IPlatoUserManager <User> platoUserManager, IPlatoUserStore <User> platoUserStore, IBreadCrumbManager breadCrumbManager, IOptions <SiteOptions> siteOptions, ILogger <AccountController> logger, SignInManager <User> signInManage, UserManager <User> userManager, IUserEmails userEmails) { _registerViewProvider = registerViewProvider; _breadCrumbManager = breadCrumbManager; _loginViewProvider = loginViewProvider; _platoUserManager = platoUserManager; _identityOptions = identityOptions; _platoUserStore = platoUserStore; _siteOptions = siteOptions.Value; _signInManager = signInManage; _userManager = userManager; _userEmails = userEmails; _logger = logger; T = htmlLocalizer; S = stringLocalizer; }
/// <summary> /// Converts a virtual (relative) path to an CDN absolute URI, if configured. /// </summary> /// <param name="value">The <see cref="IUrlHelper"/>.</param> /// <param name="contentPath">The virtual path of the content.</param> /// <param name="options">The current site configuration.</param> /// <param name="appendVersion">Whether to append a version query string parameter to the URL.</param> /// <returns>The CDN absolute URI, if configured; otherwise the application absolute URI..</returns> public static string CdnContent(this IUrlHelper value, string contentPath, SiteOptions options, bool appendVersion = true) { var cdn = options?.ExternalLinks?.Cdn; // Prefer empty images to a NullReferenceException if (cdn == null) { return(string.Empty); } #pragma warning disable CA1308 // Normalize strings to uppercase // Azure Blob storage is case-sensitive, so force all URLs to lowercase string url = value.ToAbsolute(cdn.Host, $"london-travel_{contentPath.ToLowerInvariant().TrimStart(ForwardSlash)}"); #pragma warning restore CA1308 // Normalize strings to uppercase // asp-append-version="true" does not work for non-local resources if (appendVersion) { url += $"?v={GitMetadata.Commit}"; } return(url); }
public ActionResult UploadFile(SiteOptions model) { HttpPostedFileBase postedFile = Request.Files[0] as HttpPostedFileBase; string baseUrl = "/Content/Uploaded/"; if (postedFile.ContentLength > 0) { //Sätt vilken adress det är till den folder som ska användas string folderPath = Server.MapPath(baseUrl); //Skapa foldern Directory.CreateDirectory(folderPath); //Koppla den skapade foldern med de nya filens namn för en url string saveFileName = Server.MapPath(baseUrl + postedFile.FileName); //Spara postedFile.SaveAs(saveFileName); model.ImageUrl = baseUrl + postedFile.FileName; if (ModelState.IsValid) { db.SiteOptions.Add(model); db.SaveChanges(); return(RedirectToAction("Index")); } } else { return(Content("Invalid File")); } return(View()); }
/// <summary> /// Configures the application to use identity. /// </summary> /// <param name="app">The <see cref="IApplicationBuilder"/> to configure.</param> /// <param name="options">The current site configuration.</param> public static void UseIdentity(this IApplicationBuilder app, SiteOptions options) { if (options?.Authentication?.IsEnabled == true) { app.UseAuthentication(); } }
public ActionResult DeleteConfirmed(int id) { SiteOptions siteOptions = db.SiteOptions.Find(id); db.SiteOptions.Remove(siteOptions); db.SaveChanges(); return(RedirectToAction("Index")); }
public HomeController(IMessageService messageService, IPeopleApi pco, IDataAccess db, IOptions <SiteOptions> options, IMemoryCache cache) { _options = options.Value; _messageService = messageService; _pco = pco; _db = db; _cache = cache; }
public void Update(SiteOptions site) { if (cache.TryGetValue(site.Id, out var oldSite)) { oldSite.Host = site.Host; oldSite.PingFrequency = site.PingFrequency; } }
public ThemeSelector( IOptions <ThemeOptions> themeOptionsAccessor, IOptions <SiteOptions> siteOptionsAccessor, IHttpContextAccessor httpContextAccessor) { _themeOptions = themeOptionsAccessor.Value; _siteOptions = siteOptionsAccessor.Value; _httpContext = httpContextAccessor.HttpContext; }
public SiteResources( IHtmlLocalizer <SiteResources> htmlLocalizer, IStringLocalizer <SiteResources> localizer, SiteOptions options) { _htmlLocalizer = htmlLocalizer; _localizer = localizer; _options = options; }
public LocalDateTimeTagHelper( ILocalDateTimeProvider localDateTimeProvider, IOptions <SiteOptions> siteSettings, IContextFacade contextFacade) { _localDateTimeProvider = localDateTimeProvider; _contextFacade = contextFacade; _settings = siteSettings.Value; }
/// <summary> /// Initializes a new instance of the <see cref="ApplicationAuthorizationBuilder"/> class. /// </summary> /// <param name="builder">The <see cref="AuthenticationBuilder"/> to use.</param> /// <param name="options">The <see cref="SiteOptions"/> to use.</param> /// <param name="serviceProviderFactory">A delegate to a method that returns the <see cref="IServiceProvider"/> to use.</param> public ApplicationAuthorizationBuilder( AuthenticationBuilder builder, SiteOptions options, Func <IServiceProvider> serviceProviderFactory) { _builder = builder; _options = options; _serviceProviderFactory = serviceProviderFactory; }
public MailService(SiteOptions siteOptions, MailTokenService mailTokenService, MailSender mailSender, ITemplateProvider templateProvider) { _mailTokenService = mailTokenService; _mailSender = mailSender; _templateProvider = templateProvider; _siteUrls = new EmailUrls(siteOptions.Root); }
public ActionResult Edit([Bind(Include = "Id,ImageUrl")] SiteOptions siteOptions) { if (ModelState.IsValid) { db.Entry(siteOptions).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(siteOptions)); }
/// <summary> /// Initializes a new instance of the <see cref="AlexaController"/> class. /// </summary> /// <param name="userManager">The <see cref="UserManager{TUser}"/> to use.</param> /// <param name="telemetry">The <see cref="ISiteTelemetry"/> to use.</param> /// <param name="siteOptions">The current site options.</param> /// <param name="logger">The <see cref="ILogger"/> to use.</param> public AlexaController( UserManager <LondonTravelUser> userManager, ISiteTelemetry telemetry, SiteOptions siteOptions, ILogger <AlexaController> logger) { _userManager = userManager; _telemetry = telemetry; _options = siteOptions?.Alexa; _logger = logger; }
/* Required functionality for Windows Forms initialization */ public MainWindow() { InitializeComponent(); // required winforms boilerplate graphicsSvc = GraphicsDeviceService.AddRef(this.Handle, 10, 10); // get an XNA graphics device for later use siteOptions = SiteOptions.Load(Boku.Common.StorageSource.TitleSpace | Boku.Common.StorageSource.UserSpace); ConstrainToHardwareCapabilities(); CopySettingsToUI(); }
private void SaveSiteOptions(Dictionary <string, int> hashes) { var outPath = Path.Combine(this.configuration.JsonDirectoryPath, "siteOptions.json"); var jsonSerializer = new DataContractJsonSerializer(typeof(SiteOptions)); var siteOptions = new SiteOptions(); siteOptions.Hashes = hashes; using (var fileWriter = new StreamWriter(outPath)) { jsonSerializer.WriteObject(fileWriter.BaseStream, siteOptions); } }
public ApiAuthClientFactory( IOptions <SiteOptions> siteOptions, ILogger <ApiAuthClientFactory> logger, IHttpClientFactory httpClientFactory, ITokenProvider tokenProvider, IHttpContextAccessor httpContextAccessor) { _logger = logger; _siteOptions = siteOptions.Value; _httpClientFactory = httpClientFactory; _sharedClient = new Lazy <HttpClient>(() => CreateHttpClient()); _tokenProvider = tokenProvider; _httpContextAccessor = httpContextAccessor; }
public LoginModel(SignInManager <IdentityUser> signInManager, ILogger <LoginModel> logger, UserManager <IdentityUser> userManager, IEmailSender emailSender, ITokenProvider tokenProvider, IOptions <SiteOptions> siteOptions) { _userManager = userManager; _signInManager = signInManager; _emailSender = emailSender; _logger = logger; _tokenProvider = tokenProvider; _siteOptions = siteOptions.Value; }
// GET: SiteOptions/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SiteOptions siteOptions = db.SiteOptions.Find(id); if (siteOptions == null) { return(HttpNotFound()); } return(View(siteOptions)); }
public Sites(long siteid) { SiteNotificationTemplates = new SiteNotificationTemplates(this); SiteOptions = new SiteOptions(this); ID = siteid; ParentID = -1; OwnerUserID = -1; Name = ""; LogoUrl = ""; Company = ""; Address = ""; PostCode = ""; ResponsiblePerson = ""; ContactPerson = ""; Telephone = ""; Fax = ""; Mobile = ""; Email = ""; QQ = ""; ServiceTelephone = ""; ICPCert = ""; Level = -1; ON = false; BonusScale = 0; MaxSubSites = 0; UseLotteryListRestrictions = ""; UseLotteryList = ""; UseLotteryListQuickBuy = ""; AdministratorID = -1; _urls = ""; Url = ""; PageTitle = ""; PageKeywords = ""; }