public virtual ActionResult Edit() { var user = userService.FindByUsername(currentUser.Identity.Name); var profiles = profilesService.GetUserProfiles(user); var twitter = profiles.Where(x => x.Name == SiteProfileConstants.Twitter).Select(p => p.Url.Replace(SiteProfileConstants.TwitterProfilePrefix, string.Empty)).FirstOrDefault(); var github = profiles.Where(x => x.Name == SiteProfileConstants.Github).Select(p=> p.Url.Replace(SiteProfileConstants.GithubProfilePrefix, string.Empty)).FirstOrDefault(); var codeplex = profiles.Where(x => x.Name == SiteProfileConstants.Codeplex).Select(p=>p.Url.Replace(SiteProfileConstants.CodeplexProfilePrefix, string.Empty)).FirstOrDefault(); var stackExchange = profiles.Where(x => x.Name == SiteProfileConstants.StackExchange).Select(p=>p.Url).FirstOrDefault(); var homepage = profiles.Where(x => x.Name == SiteProfileConstants.Homepage).Select(p=>p.Url).FirstOrDefault(); var blogUrl = profiles.Where(x => x.Name == SiteProfileConstants.Blog).Select(p => p.Url).FirstOrDefault(); var packagesRepo = profiles.Where(x => x.Name == SiteProfileConstants.PackagesRepository).Select(p => p.Url).FirstOrDefault(); var packagesRepoAuto = profiles.Where(x => x.Name == SiteProfileConstants.PackagesRepositoryAuto).Select(p => p.Url).FirstOrDefault(); var model = new EditProfileViewModel { EmailAddress = user.EmailAddress, EmailAllowed = user.EmailAllowed, PendingNewEmailAddress = user.UnconfirmedEmailAddress, TwitterUserName = twitter, GithubUserName = github, CodeplexUserName = codeplex, StackExchangeUrl = stackExchange, HomepageUrl = homepage, BlogUrl = blogUrl, PackagesRepository = packagesRepo, PackagesRepositoryAuto = packagesRepoAuto }; return View(model); }
public virtual ActionResult Edit() { var user = _userService.FindByUsername(_currentUser.Identity.Name); var model = new EditProfileViewModel { EmailAddress = user.EmailAddress, EmailAllowed = user.EmailAllowed, PendingNewEmailAddress = user.UnconfirmedEmailAddress }; return View(model); }
public void SaveProfiles(User user, EditProfileViewModel profile) { var siteProfiles = GetUserProfiles(user).AsQueryable(); CompareAndPrepareProfile(SiteProfileConstants.Blog, profile.BlogUrl, user.Username, string.Empty, siteProfiles, prefix: string.Empty); CompareAndPrepareProfile(SiteProfileConstants.Codeplex, profile.CodeplexUserName, user.Username, SiteProfileConstants.Images.codeplex, siteProfiles, prefix: SiteProfileConstants.CodeplexProfilePrefix); CompareAndPrepareProfile(SiteProfileConstants.Github, profile.GithubUserName, user.Username, SiteProfileConstants.Images.github, siteProfiles, prefix: SiteProfileConstants.GithubProfilePrefix); CompareAndPrepareProfile(SiteProfileConstants.Homepage, profile.HomepageUrl, user.Username, string.Empty, siteProfiles, prefix: string.Empty); CompareAndPrepareProfile(SiteProfileConstants.StackExchange, profile.StackExchangeUrl, user.Username, SiteProfileConstants.Images.stackexchange, siteProfiles, prefix: string.Empty); CompareAndPrepareProfile(SiteProfileConstants.Twitter, profile.TwitterUserName, user.Username, SiteProfileConstants.Images.twitter, siteProfiles, prefix: SiteProfileConstants.TwitterProfilePrefix); CompareAndPrepareProfile(SiteProfileConstants.PackagesRepository, profile.PackagesRepository, user.Username, string.Empty, siteProfiles, prefix: string.Empty); CompareAndPrepareProfile(SiteProfileConstants.PackagesRepositoryAuto, profile.PackagesRepositoryAuto, user.Username, string.Empty, siteProfiles, prefix: string.Empty); profileRepo.CommitChanges(); }
public virtual ActionResult Edit(EditProfileViewModel profile) { if (ModelState.IsValid) { var user = userService.FindByUsername(currentUser.Identity.Name); if (user == null) { return HttpNotFound(); } string existingConfirmationToken = user.EmailConfirmationToken; try { userService.UpdateProfile(user, profile.EmailAddress, profile.EmailAllowed); } catch (EntityException ex) { ModelState.AddModelError(String.Empty, ex.Message); return View(profile); } if (existingConfirmationToken == user.EmailConfirmationToken) { TempData["Message"] = "Account settings saved!"; } else { TempData["Message"] = "Account settings saved! We sent a confirmation email to verify your new email. When you confirm the email address, it will take effect and we will forget the old one."; var confirmationUrl = Url.ConfirmationUrl(MVC.Users.Confirm(), user.Username, user.EmailConfirmationToken, protocol: Request.Url.Scheme); messageService.SendEmailChangeConfirmationNotice(new MailAddress(profile.EmailAddress, user.Username), confirmationUrl); } profilesService.SaveProfiles(user,profile); return RedirectToAction(MVC.Users.Account()); } return View(profile); }
public void UpdatesEmailAllowedSetting() { var user = new User { EmailAddress = "*****@*****.**", EmailAllowed = true }; var userService = new Mock <IUserService>(); userService.Setup(u => u.FindByUsername(It.IsAny <string>())).Returns(user); userService.Setup(u => u.UpdateProfile(user, "*****@*****.**", false)).Verifiable(); var controller = CreateController(userSvc: userService); var model = new EditProfileViewModel { EmailAddress = "*****@*****.**", EmailAllowed = false }; var result = controller.Edit(model) as RedirectToRouteResult; Assert.NotNull(result); userService.Verify(u => u.UpdateProfile(user, "*****@*****.**", false)); Assert.Equal("Account settings saved!", controller.TempData["Message"]); }
public virtual ActionResult Edit(EditProfileViewModel profile) { if (ModelState.IsValid) { var user = userService.FindByUsername(currentUser.Identity.Name); if (user == null) { return(HttpNotFound()); } string existingConfirmationToken = user.EmailConfirmationToken; try { userService.UpdateProfile(user, profile.EmailAddress, profile.EmailAllowed); } catch (EntityException ex) { ModelState.AddModelError(String.Empty, ex.Message); return(View(profile)); } if (existingConfirmationToken == user.EmailConfirmationToken) { TempData["Message"] = "Account settings saved!"; } else { TempData["Message"] = "Account settings saved! We sent a confirmation email to verify your new email. When you confirm the email address, it will take effect and we will forget the old one."; var confirmationUrl = Url.ConfirmationUrl(MVC.Users.Confirm(), user.Username, user.EmailConfirmationToken, protocol: Request.Url.Scheme); messageService.SendEmailChangeConfirmationNotice(new MailAddress(profile.EmailAddress, user.Username), confirmationUrl); } return(RedirectToAction(MVC.Users.Account())); } return(View(profile)); }
public void SendsEmailChangeConfirmationNoticeWhenEmailConfirmationTokenChanges() { var user = new User { EmailAddress = "*****@*****.**", EmailAllowed = true }; var userService = new Mock <IUserService>(); userService.Setup(u => u.FindByUsername(It.IsAny <string>())).Returns(user); userService.Setup(u => u.UpdateProfile(user, "*****@*****.**", true)).Callback(() => user.EmailConfirmationToken = "token"); var controller = CreateController(userSvc: userService); var model = new EditProfileViewModel { EmailAddress = "*****@*****.**", EmailAllowed = true }; var result = controller.Edit(model) as RedirectToRouteResult; Assert.NotNull(result); Assert.Equal( "Account settings saved! We sent a confirmation email to verify your new email. When you confirm the email address, it will take effect and we will forget the old one.", controller.TempData["Message"]); }
public void UpdatesEmailAllowedSetting() { var user = new User("aUsername") { EmailAddress = "*****@*****.**", EmailAllowed = true }; var controller = GetController <UsersController>(); controller.SetCurrentUser(user); GetMock <IUserService>() .Setup(u => u.UpdateProfile(user, false)); var model = new EditProfileViewModel { EmailAddress = "*****@*****.**", EmailAllowed = false }; var result = controller.Edit(model); var viewModel = ResultAssert.IsView <EditProfileViewModel>(result); Assert.Same(model, viewModel); GetMock <IUserService>().Verify(u => u.UpdateProfile(user, false)); }
public void UpdatesEmailAllowedSetting() { var user = new User { EmailAddress = "*****@*****.**", EmailAllowed = true }; var userService = new Mock<IUserService>(); userService.Setup(u => u.FindByUsername(It.IsAny<string>())).Returns(user); userService.Setup(u => u.UpdateProfile(user, "*****@*****.**", false)).Verifiable(); var controller = CreateController(userSvc: userService); var model = new EditProfileViewModel { EmailAddress = "*****@*****.**", EmailAllowed = false }; var result = controller.Edit(model) as RedirectToRouteResult; Assert.NotNull(result); userService.Verify(u => u.UpdateProfile(user, "*****@*****.**", false)); Assert.Equal("Account settings saved!", controller.TempData["Message"]); }
public void SendsEmailChangeConfirmationNoticeWhenEmailConfirmationTokenChanges() { var user = new User { EmailAddress = "*****@*****.**", EmailAllowed = true }; var userService = new Mock<IUserService>(); userService.Setup(u => u.FindByUsername(It.IsAny<string>())).Returns(user); userService.Setup(u => u.UpdateProfile(user, "*****@*****.**", true)).Callback(() => user.EmailConfirmationToken = "token"); var controller = CreateController(userSvc: userService); var model = new EditProfileViewModel { EmailAddress = "*****@*****.**", EmailAllowed = true }; var result = controller.Edit(model) as RedirectToRouteResult; Assert.NotNull(result); Assert.Equal("Account settings saved! We sent a confirmation email to verify your new email. When you confirm the email address, it will take effect and we will forget the old one.", controller.TempData["Message"]); }
public void DoesNotSendEmailChangeConfirmationNoticeWhenTokenDoesNotChange() { var user = new User { EmailAddress = "*****@*****.**", EmailAllowed = true, EmailConfirmationToken = "token" }; var userService = new Mock<IUserService>(); userService.Setup(u => u.FindByUsername(It.IsAny<string>())).Returns(user); userService.Setup(u => u.UpdateProfile(user, It.IsAny<string>(), true)); var messageService = new Mock<IMessageService>(); messageService.Setup(m => m.SendEmailChangeConfirmationNotice(It.IsAny<MailAddress>(), It.IsAny<string>())).Throws(new InvalidOperationException()); var controller = CreateController(userSvc: userService, messageSvc: messageService); var model = new EditProfileViewModel { EmailAddress = "*****@*****.**", EmailAllowed = true }; var result = controller.Edit(model) as RedirectToRouteResult; Assert.NotNull(result); Assert.Equal("Account settings saved!", controller.TempData["Message"]); }
public virtual ActionResult Edit(EditProfileViewModel profile) { var user = UserService.FindByUsername(Identity.Name); if (user == null) { return HttpNotFound(); } profile.EmailAddress = user.EmailAddress; profile.Username = user.Username; profile.PendingNewEmailAddress = user.UnconfirmedEmailAddress; UserService.UpdateProfile(user, profile.EmailAllowed); return View(profile); }
public virtual ActionResult Edit() { var user = GetCurrentUser(); var model = new EditProfileViewModel { Username = user.Username, EmailAddress = user.EmailAddress, EmailAllowed = user.EmailAllowed, PendingNewEmailAddress = user.UnconfirmedEmailAddress }; return View(model); }
public void SaveProfiles(User user, EditProfileViewModel profile) { var siteProfiles = GetUserProfiles(user).AsQueryable(); CompareAndPrepareProfile( SiteProfileConstants.Blog, profile.BlogUrl, user.Username, string.Empty, siteProfiles, prefix: string.Empty); CompareAndPrepareProfile( SiteProfileConstants.Codeplex, profile.CodeplexUserName, user.Username, SiteProfileConstants.Images.codeplex, siteProfiles, prefix: SiteProfileConstants.CodeplexProfilePrefix); CompareAndPrepareProfile( SiteProfileConstants.Github, profile.GithubUserName, user.Username, SiteProfileConstants.Images.github, siteProfiles, prefix: SiteProfileConstants.GithubProfilePrefix); CompareAndPrepareProfile( SiteProfileConstants.Homepage, profile.HomepageUrl, user.Username, string.Empty, siteProfiles, prefix: string.Empty); CompareAndPrepareProfile( SiteProfileConstants.StackExchange, profile.StackExchangeUrl, user.Username, SiteProfileConstants.Images.stackexchange, siteProfiles, prefix: string.Empty); CompareAndPrepareProfile( SiteProfileConstants.Twitter, profile.TwitterUserName, user.Username, SiteProfileConstants.Images.twitter, siteProfiles, prefix: SiteProfileConstants.TwitterProfilePrefix); CompareAndPrepareProfile( SiteProfileConstants.PackagesRepository, profile.PackagesRepository, user.Username, string.Empty, siteProfiles, prefix: string.Empty); CompareAndPrepareProfile( SiteProfileConstants.PackagesRepositoryAuto, profile.PackagesRepositoryAuto, user.Username, string.Empty, siteProfiles, prefix: string.Empty); profileRepo.CommitChanges(); }
public void UpdatesEmailAllowedSetting() { var user = new User("aUsername") { EmailAddress = "*****@*****.**", EmailAllowed = true }; var controller = GetController<UsersController>(); controller.SetCurrentUser(user); GetMock<IUserService>() .Setup(u => u.UpdateProfile(user, false)); var model = new EditProfileViewModel { EmailAddress = "*****@*****.**", EmailAllowed = false }; var result = controller.Edit(model); var viewModel = ResultAssert.IsView<EditProfileViewModel>(result); Assert.Same(model, viewModel); GetMock<IUserService>().Verify(u => u.UpdateProfile(user, false)); }