public async void TestOpslaan_EmailGewijzigd_RedirectsToIndex() { _userManager.Setup(u => u.GetUserAsync(It.IsAny <ClaimsPrincipal>())) .Returns(() => Task.FromResult(new ApplicationUser())); _jobcoachRepository.Setup(j => j.GetById(It.IsAny <int>())).Returns(_dbContext.Thomas); ProfielViewModel model = new ProfielViewModel(_dbContext.Thomas); model.Email = "iets anders"; var result = await _controller.Opslaan(model) as RedirectToActionResult; Assert.Equal("Index", result?.ActionName); _userManager.Verify(u => u.GetUserAsync(It.IsAny <ClaimsPrincipal>()), Times.Once); _userManager.Verify(u => u.GenerateChangeEmailTokenAsync(It.IsAny <ApplicationUser>(), It.IsAny <string>()), Times.Once); _userManager.Verify(u => u.ChangeEmailAsync(It.IsAny <ApplicationUser>(), It.IsAny <string>(), It.IsAny <string>()), Times.Once); _userManager.Verify(u => u.UpdateAsync(It.IsAny <ApplicationUser>()), Times.Once); _signInManager.Verify(s => s.SignOutAsync(), Times.Once); _jobcoachRepository.Verify(j => j.GetById(_dbContext.Thomas.PersoonId), Times.Once); _jobcoachRepository.Verify(j => j.Save(), Times.Once); }
public IActionResult Profiel(long id) { Account account = _userManager.FindByIdAsync(id.ToString()).Result; ProfielViewModel vm = Pconverter.AccountToViewModel(account); return(View(vm)); }
public Account ViewModelToAccount(ProfielViewModel vm) { Account a = new Account(vm.Id, vm.Gebruikersnaam, vm.Rol, new Persoon(vm.Voornaam, vm.Achternaam, vm.Email), true); if (vm.NieuwWachtwoord != null) { a.SetPassword(vm.NieuwWachtwoord); } return(a); }
public async Task <IActionResult> Profiel(ProfielViewModel vm) { Account account = Pconverter.ViewModelToAccount(vm); var result = await _userManager.UpdateAsync(account); if (ModelState.IsValid) { return(View()); } else { return(View(vm)); } }
public async void TestOpslaan_EmailNietGewijzigd_RedirectsToIndex() { _jobcoachRepository.Setup(j => j.GetById(It.IsAny <int>())).Returns(_dbContext.Thomas); ProfielViewModel model = new ProfielViewModel(_dbContext.Thomas); model.Email = null; // null omdat we HttpContext.User.Identity.Name niet kunnen instellen var result = await _controller.Opslaan(model) as RedirectToActionResult; Assert.Equal("Index", result?.ActionName); _jobcoachRepository.Verify(j => j.GetById(_dbContext.Thomas.PersoonId), Times.Once); _jobcoachRepository.Verify(j => j.Save(), Times.Once); }
public ProfielViewModel AccountToViewModel(Account a) { ProfielViewModel vm = new ProfielViewModel() { Id = a.Id, Gebruikersnaam = a.Gebruikersnaam, Voornaam = a.Persoon.Voornaam, Achternaam = a.Persoon.Achternaam, Email = a.Persoon.Email, Rol = a.Rol, Wachtwoord = a.Wachtwoord, }; return(vm); }
public override void wijzigGegevens(ProfielViewModel input) { Achternaam = input.Achternaam; Voornaam = input.Voornaam; Geboortedatum = input.Geboortedatum; Gsm = input.Gsm; Geslacht = input.Geslacht; Nationaliteit = input.Nationaliteit; Gemeente = input.Gemeente; Postcode = input.Postcode; Straat = input.Straat; Huisnummer = input.Huisnummer; this.Email = input.Email; this.UserName = input.Email; OrganisatieNaam = input.OrganisatieNaam; BtwNummer = input.Btwnummer; }
public IActionResult Gegevens(ProfielViewModel viewmodel) { if (ModelState.IsValid) { try { ApplicationUser user = _userManager.FindByEmailAsync(User.Identity.Name).Result; user.wijzigGegevens(viewmodel); _userManager.UpdateAsync(user); TempData["message"] = $"De gegevens zijn succesvol aangepast."; } catch (Exception ex) { ModelState.AddModelError("", ex.Message); } } return(View(viewmodel)); }
public abstract void wijzigGegevens(ProfielViewModel viewmodel);
public async Task <IActionResult> Opslaan(ProfielViewModel model) { if (ModelState.IsValid) { try { Jobcoach jobcoach = _gebruikerRepository.GetById(model.GebruikerId); jobcoach.Voornaam = model.Voornaam; jobcoach.Naam = model.Naam; jobcoach.Emailadres = model.Email; Organisatie organisatie = _organisatieRepository.GetById(model.OrganisatieId); Organisatie nieuwe = new Organisatie(model.OrganisatieNaam, model.StraatOrganisatie, model.NrOrganisatie ?? 0, model.BusOrganisatie, model.Postcode, model.Gemeente); if (organisatie != null && !organisatie.Equals(nieuwe)) { // ze zijn niet meer gelijk, dus de jobcoach heeft mogelijk iets gewijzigd dat bij de andere // niet mag wijzigen // of de jobcoach is van organisatie veranderd jobcoach.Organisatie = nieuwe; } else { jobcoach.Organisatie.Naam = model.OrganisatieNaam; jobcoach.Organisatie.Gemeente = model.Gemeente; if (model.NrOrganisatie != null) { jobcoach.Organisatie.Nummer = (int)model.NrOrganisatie; } jobcoach.Organisatie.Postcode = model.Postcode; jobcoach.Organisatie.Straat = model.StraatOrganisatie; jobcoach.Organisatie.Bus = model.BusOrganisatie; } if (model.Email != null && !model.Email.Equals(HttpContext.User.Identity.Name)) {// email is gewijzigd var user = await _userManager.GetUserAsync(User); string token = await _userManager.GenerateChangeEmailTokenAsync(user, model.Email); await _userManager.ChangeEmailAsync(user, model.Email, token); user.UserName = model.Email; await _userManager.UpdateAsync(user); // Dus opnieuw inloggen await _signInManager.SignOutAsync(); TempData["message"] = "Je hebt je e-mailadres gewijzigd. Gelieve opnieuw in te loggen met dit e-mailadres, " + "zo is alles correct gewijzigd."; } _gebruikerRepository.Save(); TempData["message"] = "Uw profiel is succesvol gewijzigd."; return(RedirectToAction(nameof(Index))); } catch (Exception e) { _exceptionLogRepository.Add(new ExceptionLog(e, "Profiel", "Opslaan")); _exceptionLogRepository.Save(); TempData["error"] = "Er ging onverwachts iets mis, probeer later opnieuw"; } } return(RedirectToAction("Index")); }