// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } StaticFileOptions staticFileOptions = new StaticFileOptions() { OnPrepareResponse = context => { context.Context.Response.Headers["Cache-Control"] = "no-cache"; //context.Context.Response.Headers["Expires"] = DateTime.UtcNow.AddHours(12).ToString("R"); } }; GravatarOptions gravatarOptions = new GravatarOptions() { DefaultGravatarPath = "/avatar/default-avatar.jpg" }; //Handle the /gravatar/ path and apply a not found fallback app.UseGravatarMiddleware(gravatarOptions); app.UseStaticFiles(staticFileOptions); app.Run((context) => { context.Response.StatusCode = 404; return(Task.FromResult(0)); }); }
public static HtmlString GravatarImage(this HtmlHelper htmlHelper, string emailAddress, GravatarOptions options = null) { if (options == null) { options = GravatarOptions.GetDefaults(); } var imgTag = new TagBuilder("img"); emailAddress = string.IsNullOrEmpty(emailAddress) ? string.Empty : emailAddress.Trim().ToLower(); // <-- adding support for CSS if (!string.IsNullOrEmpty(options.CssClass)) { imgTag.AddCssClass(options.CssClass); } // adding support for CSS --> imgTag.Attributes.Add("src", string.Format("http://www.gravatar.com/avatar/{0}?s={1}{2}{3}", GetMd5Hash(emailAddress), options.Size, "&d=" + options.DefaultImageType, "&r=" + options.RatingLevel ) ); return(new HtmlString(imgTag.ToString(TagRenderMode.SelfClosing))); }
public GravatarTagHelper(GravatarOptions options = null) { this.options = options ?? GravatarOptions.Default; }
protected void Page_Load(object sender, EventArgs e) { var authResponseCode = Request.QueryString["code"]; var responseState = Request.QueryString["state"]; if (!string.IsNullOrEmpty(authResponseCode)) { var tokens = SpotifyServices.ProcessAuthCode(authResponseCode, responseState); if (tokens != null) { tokens.ReceivedTime = DateTime.UtcNow; Model.Spotify.SpotifyUser spotifyUser = SpotifyServices.GetAuthenticatedUser(tokens); var spotifyAuthenticatedUser = StateManager.Db.FindExistingUser(spotifyUser); if (spotifyAuthenticatedUser != null) { using (var session = StateManager.CurrentSession) { session.UserId = spotifyAuthenticatedUser.UserId; } } using (User currentUser = StateManager.CurrentUser) { currentUser.SpotifyAuthTokens = tokens; currentUser.SpotifyUser = spotifyUser; } if (!string.IsNullOrWhiteSpace(responseState)) { Response.Redirect(responseState); } Response.Redirect("UserManagement.aspx"); } } using (User user = StateManager.CurrentUser) { if (user.IsLoggedIn) { KnownUser.Visible = true; UnknownUser.Visible = false; var verifyingEmailId = Request.QueryString["emailverification"]; if (!string.IsNullOrWhiteSpace(verifyingEmailId)) { var userEmailToVerify = user.Emails.FirstOrDefault(item => item.PendingVerificationId == verifyingEmailId); if (userEmailToVerify != null) { userEmailToVerify.IsVerified = true; Response.Redirect(SpotifyServices.RedirectUrl, false); return; } } var useIcon = Request.QueryString["useIcon"]; if (!string.IsNullOrEmpty(useIcon)) { int parsedIconIdndex; if (int.TryParse(useIcon, out parsedIconIdndex) && GravatarOptions.Count() > parsedIconIdndex) { user.AvatarUrl = GravatarOptions.Skip(parsedIconIdndex).First().Url; Response.Redirect(SpotifyServices.RedirectUrl, false); return; } } string gameToDelete = Request.QueryString["deletegameid"]; if (!string.IsNullOrWhiteSpace(gameToDelete)) { StateManager.Db.DeleteGame(gameToDelete); } if (IsPostBack) { if (!string.IsNullOrWhiteSpace(NameBox.Value) && NameBox.Value != user.DisplayName) { user.DisplayName = NameBox.Value; } var newPassword = PasswordUpdate.Value; var repeatPassword = PasswordRepeat.Value; if (!string.IsNullOrWhiteSpace(newPassword) && !string.IsNullOrWhiteSpace(repeatPassword) && newPassword == repeatPassword) { user.Password = newPassword; } string newEmail = (Request.Form["newemail"] ?? string.Empty).ToLower(); if (!string.IsNullOrWhiteSpace(newEmail)) { var existingUser = StateManager.Db.FindExistingUser(newEmail); if (existingUser != null) { existingUser.ShouldAutoSave = false; } else { user.Emails.Add(new UserEmail { Address = newEmail }); } } } else { if (string.IsNullOrWhiteSpace(user.UserName)) { UserNameAsLabelWrapper.Visible = false; } else { UserNameAsLabel.Text = user.UserName; } NameBox.Value = user.DisplayName; } if (user.SpotifyAuthTokens != null && !string.IsNullOrWhiteSpace(user.SpotifyAuthTokens.AccessToken)) { SpotifyAuthLink.Visible = false; SpotifyInfo.Visible = true; } else { SpotifyAuthLink.Visible = true; SpotifyInfo.Visible = false; } } else { KnownUser.Visible = false; UnknownUser.Visible = true; var existingUserEmailOrName = Request.Form["existingUserEmailOrUsername"]; var existingUserPassword = Request.Form["existingUserPassword"]; if (!string.IsNullOrWhiteSpace(existingUserEmailOrName) && !string.IsNullOrWhiteSpace(existingUserPassword)) { var foundUser = StateManager.Db.FindExistingUser(existingUserEmailOrName); if (foundUser != null && foundUser.Password == existingUserPassword) { using (var session = StateManager.CurrentSession) { session.UserId = foundUser.UserId; } Response.Redirect("/"); } else { //TODO: print error stating that login failed } } var newUserEmail = Request.Form["newUserEmail"]; var newUserName = Request.Form["newUserName"]; var newPassword = Request.Form["newPassword"]; if (!string.IsNullOrWhiteSpace(newUserEmail) && !string.IsNullOrWhiteSpace(newUserName) && !string.IsNullOrWhiteSpace(newPassword)) { newUserEmail = newUserEmail.ToLower(); var existingUser = StateManager.Db.FindExistingUser(newUserEmail) ?? StateManager.Db.FindExistingUser(newUserName); if (existingUser != null) { //TODO: say that the email or username is taken } else { user.UserName = newUserName; user.Password = newPassword; user.Emails.Add(new UserEmail { Address = newUserEmail }); RestServicesController controller = new RestServicesController(); controller.VerifyEmail(new VerifyEmailRequest { Email = newUserEmail }); } } } } DataBind(); }