public async Task <ActionResult> GetZipCodeInformation(string zipCode) { //get zipcode information var response = await _zipCodeService.GetZipCodeInformation(zipCode); if (response == null) { return(NotFound()); } return(Ok(new ZipCodeResponse() { Latitude = response.Latitude, Longitude = response.Longitude, ZipCode = zipCode })); }
public async Task <IActionResult> ChangePersonalInformation() { var user = await _userManager.GetUserAsync(User); if (user == null) { return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.")); } //get zipcode information var zipCodeInformation = await _zipCodeService.GetZipCodeInformation(Input.Zipcode); //check zipcode is valid if (zipCodeInformation == null) { ModelState.AddModelError("Input.Zipcode", "Deze postcode is ongeldig, probeer een andere!"); } if (ModelState.ContainsKey("Input.NewEmail")) { ModelState.Remove("Input.NewEmail"); } if (ModelState.IsValid) { user.FirstName = Input.FirstName; user.LastName = Input.LastName; user.ZipCode = Input.Zipcode; user.Location = new Point(zipCodeInformation.Latitude, zipCodeInformation.Longitude); await _signInManager.RefreshSignInAsync(user); // _context.Add(user); _context.SaveChanges(); StatusMessage = "Uw profiel is aangepast."; return(RedirectToPage()); } await LoadAsync(user); return(Page()); }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { if (!await _roleManager.RoleExistsAsync("Admin")) { await _roleManager.CreateAsync(new IdentityRole("Admin")); } if (!await _roleManager.RoleExistsAsync("Customer")) { await _roleManager.CreateAsync(new IdentityRole("Customer")); } returnUrl = returnUrl ?? Url.Content("~/Identity/Account/RegisterConfirmation"); ReturnUrl = Url.Content("~/Identity/Account/RegisterConfirmation"); ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList(); if (!await _zipCodeService.CheckPostCodeIsValid(Input.PostCode)) { ModelState.AddModelError("Input.PostCode", "Deze postcode is ongeldig, probeer een andere!"); } if (ModelState.IsValid) { var zipCodeInformation = await _zipCodeService.GetZipCodeInformation(Input.PostCode); var user = new User { UserName = Input.Email, Email = Input.Email, FirstName = Input.Voornaam, LastName = Input.Achternaam, ZipCode = Input.PostCode, Location = new Point(zipCodeInformation.Latitude, zipCodeInformation.Longitude) }; var emailExist = _context.User.Any(p => p.Email == Input.Email); if (emailExist) { ModelState.AddModelError("EmailError", "Het e-mailadres is al in gebruik"); } else { var result = await _userManager.CreateAsync(user, Input.Password); if (_userManager.Users.Count() == 1) { await _userManager.AddToRoleAsync(user, "Admin"); } else { await _userManager.AddToRoleAsync(user, "Customer"); } if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); var callbackUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { area = "Identity", userId = user.Id, code = code, returnUrl = returnUrl }, protocol: Request.Scheme); using (MailMessage message = new MailMessage("*****@*****.**", Input.Email)) { message.Subject = "Account verificatie"; message.Body = "\nHey " + Input.Voornaam + " " + Input.Achternaam + ",\n\n Je kunt je account bijna gebruiken! Klik alleen nog even op de onderstaande link" + "om je email te bevesitgen!\n\n" + callbackUrl + "Groetjes,\n\n\nHet hele Plantjesbuurt Team!"; message.IsBodyHtml = false; using (SmtpClient smtp = new SmtpClient()) { smtp.Host = "smtp.gmail.com"; smtp.EnableSsl = true; NetworkCredential cred = new NetworkCredential("*****@*****.**", "#1Geheim"); smtp.UseDefaultCredentials = true; smtp.Credentials = cred; smtp.Port = 587; smtp.Send(message); } return(LocalRedirect(ReturnUrl)); } } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(Page()); } return(LocalRedirect(ReturnUrl)); }