public async Task <ActionResult> Register(RegisterViewModel model) { if (this.ModelState.IsValid) { if (string.IsNullOrEmpty(model.AvatarUrl) && !string.IsNullOrEmpty(model.Email)) { model.AvatarUrl = GravatarHelper.CreateGravatarUrl(model.Email, 200, GravatarHelper.DefaultImageIdenticon, GravatarRating.G, false, false); } var user = this.Mapper.Map <User>(model); var result = await this.UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await this.SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return(this.RedirectToAction("Index", "Home")); } this.AddErrors(result); } // If we got this far, something failed, redisplay form return(this.View(model)); }
/// <summary> /// Gets the model for the blog post page /// </summary> /// <param name="currentPage">The current page</param> /// <param name="currentMember">The current member</param> /// <returns>The page model</returns> public BlogPostViewModel GetBlogPostPageModel(IPublishedContent currentPage, IMember currentMember) { var model = GetPageModel <BlogPostViewModel>(currentPage, currentMember); model.ImageUrl = GravatarHelper.CreateGravatarUrl(model.Author.Email, 200, string.Empty, null, null, null); return(model); }
public async Task check_if_gravatar_helper_creates_correct_url() { var userUrl = GravatarHelper.CreateGravatarUrl("Test"); var content = await _httpService.GetByteArrayAsync(userUrl); Assert.NotNull(content); }
public async Task <IResult> RegisterUserAsync([FromBody] UserRegisterWriteModel userRegister) { if (!ModelState.IsValid) { var errors = ModelState.Values.SelectMany(v => v.Errors).Select(v => v.ErrorMessage).ToArray(); return(CreateResult(ResultStateEnum.Failed, errors)); } var gravatarUrl = GravatarHelper.CreateGravatarUrl(userRegister.UserName); userRegister.Gravatar = await _httpService.GetByteArrayAsync(gravatarUrl); return(await _userAuthDomainServiceProxy.CreateUserAsync(userRegister)); }
/// <summary> /// Method to get the model for the main navigation /// </summary> /// <param name="currentPage">The current page</param> /// <param name="currentMember">The current member</param> /// <returns>Navigation model</returns> public MainNavigationViewModel GetMainNavigation(IPublishedContent currentPage, IMember currentMember) { var login = Root.Descendant(ContentTypeAliases.Login); var model = new MainNavigationViewModel { Items = GetMenuItems(currentPage, Root, 0, 3), Login = login != null?MapItem(currentPage, login) : null }; if (currentMember == null) { return(model); } model.IsLoggedIn = true; model.Name = currentMember.Name; model.ImageUrl = GravatarHelper.CreateGravatarUrl(currentMember.Email, 30, string.Empty, null, null, null); return(model); }
public static string GetImageUrl(this IHaveEmail self) { return(GravatarHelper.CreateGravatarUrl(self.Email, 200, defaultImage: null, rating: GravatarRating.PG, addExtension: true, forceDefault: false)); }
/// <summary> /// Creates a URI to facilitate unit testing using CreateGravatarUrl. /// </summary> /// <param name="email">Email address to generate the Gravatar for.</param> /// <param name="imageSize">Gravatar size in pixels.</param> /// <param name="defaultImage">The default image to use if the user does not have a Gravatar setup, /// can either be a url to an image or one of the DefaultImage* constants</param> /// <param name="rating">The content rating of the images to display.</param> /// <param name="addExtension">Whether to add the .jpg extension to the provided Gravatar.</param> /// <param name="forceDefault">Forces Gravatar to always serve the default image.</param> /// <param name="forceSecureUrl">Forces the use of https</param> /// <returns>The Gravatar url wrapped inside an Uri.</returns> private static Uri CreateGravatarUri(string email = DefaultEmailAddress, int imageSize = DefaultImageSize, string defaultImage = null, GravatarRating?rating = null, bool?addExtension = null, bool?forceDefault = null, bool forceSecureUrl = false) { var url = GravatarHelper.CreateGravatarUrl(email, imageSize, defaultImage, rating, addExtension, forceDefault, forceSecureUrl); return(new Uri(url)); }