public async Task <bool> EmailRegistered(UserRequestPin user) { var dbUser = await _context.User.FirstOrDefaultAsync(u => u.BookerId == user.BookerId); var returnBool = (!String.IsNullOrEmpty(dbUser.Email) && user.Email == dbUser.Email); return(returnBool); }
public async Task <IActionResult> NewPin(UserRequestPin userRequestPin) { if (userRequestPin == null) { return(View("Error")); } if (!ModelState.IsValid) { userRequestPin.ErrorMessage = "There was something wrong with your input"; return(View("RequestNewPin", userRequestPin)); } if (!await _repository.CheckBookerId(userRequestPin)) { userRequestPin.ErrorMessage = "User not found"; return(View("RequestNewPin", userRequestPin)); } var dbUser = await _repository.GetUserAsync(userRequestPin.BookerId); if (!dbUser.EmailConfirmed) { userRequestPin.ErrorMessage = "You have to register and confirm your Email-address"; return(View("RequestNewPin", userRequestPin)); } if (await _repository.EmailRegistered(userRequestPin)) { var apiKey = _appSettings.ApiKey; var newPin = await _repository.CreateAndSaveNewPin(dbUser); var client = new SendGridClient(apiKey); var msg = new SendGridMessage() { From = new EmailAddress("*****@*****.**", "Bokatvattstugan.online"), Subject = "Din nya pin-kod", HtmlContent = "<strong> Din nya pin-kod är: " + newPin, PlainTextContent = "Din nya pin-kod är: " + newPin }; msg.AddTo(new EmailAddress(dbUser.Email)); var response = await client.SendEmailAsync(msg); if (response.StatusCode == System.Net.HttpStatusCode.Accepted) { return(RedirectToAction("NewPincodeDelivered")); } userRequestPin.ErrorMessage = "Email couldn't be delivered"; return(View("RequestNewPin", userRequestPin)); } userRequestPin.ErrorMessage = "You have to register and confirm your Email-address"; return(View("RequestNewPin", userRequestPin)); }
public async Task <bool> CheckBookerId(UserRequestPin user) { return(await _context.User.AnyAsync(u => u.BookerId == user.BookerId)); }