コード例 #1
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            if (ModelState.IsValid)
            {
                var user = new User {
                    UserName = Input.Email, Email = Input.Email
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    var addToRole = await _userManager.AddToRoleAsync(user, Roles.Customer);

                    if (addToRole.Succeeded)
                    {
                        _logger.LogInformation($"User {0} added to role {1}.", user.Id, Roles.Customer);
                    }

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { userId = user.Id, code = code },
                        protocol: Request.Scheme);

                    /*await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                     *  $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");*/

                    var model = new EmailConfirmationDto(user.Name ?? user.UserName, callbackUrl);

                    const string view = "/Views/Emails/ConfirmAccountEmail";
                    var          body = await _render.RenderViewToStringAsync($"{view}Html.cshtml", model);

                    QueueEmailMessage queueEmail = new QueueEmailMessage(Input.Email, "", body, "Reset Password");
                    await _cloudStorageService.SendMessage(queueEmail);

                    //await _emailSender.SendEmailAsync(Input.Email, "Confirm your email", body);


                    await _signInManager.SignInAsync(user, isPersistent : false);

                    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());
        }
コード例 #2
0
        public async Task <IActionResult> OnPostSendVerificationEmailAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(NotFound(_localizer["USER_NOTFOUND", _userManager.GetUserId(User)]));
                //return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
            }


            var userId = await _userManager.GetUserIdAsync(user);

            var email = await _userManager.GetEmailAsync(user);

            var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

            var callbackUrl = Url.Page(
                "/Account/ConfirmEmail",
                pageHandler: null,
                values: new { userId = userId, code = code },
                protocol: Request.Scheme);

            /*await _emailSender.SendEmailAsync(email, "Confirm your email",
             *  $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");*/

            var model = new EmailConfirmationDto(user.Name ?? user.UserName, callbackUrl);

            const string view = "/Views/Emails/ConfirmAccountEmail";
            var          body = await _render.RenderViewToStringAsync($"{view}Html.cshtml", model);

            QueueEmailMessage queueEmail = new QueueEmailMessage(Input.Email, "", body, "Reset Password");
            await _cloudStorageService.SendMessage(queueEmail);

            //await _emailSender.SendEmailAsync(Input.Email, "Reset Password", body);

            //StatusMessage = "Verification email sent. Please check your email.";
            StatusMessage = _localizer["STATUS_UPDATE_PROFILE_EMAIL_SEND"];
            return(RedirectToPage());
        }
コード例 #3
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(Input.Email);

                if (user == null || !(await _userManager.IsEmailConfirmedAsync(user)))
                {
                    // Don't reveal that the user does not exist or is not confirmed
                    return(RedirectToPage("./ForgotPasswordConfirmation"));
                }

                // For more information on how to enable account confirmation and password reset please
                // visit https://go.microsoft.com/fwlink/?LinkID=532713
                var code = await _userManager.GeneratePasswordResetTokenAsync(user);

                var callbackUrl = Url.Page(
                    "/Account/ResetPassword",
                    pageHandler: null,
                    values: new { code },
                    protocol: Request.Scheme);

                /*await _emailSender.SendEmailAsync(Input.Email, "Reset Password",
                 *  $"Please reset your password by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");*/

                var model = new EmailConfirmationDto(user.Name ?? user.UserName, HtmlEncoder.Default.Encode(callbackUrl));

                const string view = "/Views/Emails/ForgotPasswordEmail";
                var          body = await _render.RenderViewToStringAsync($"{view}Html.cshtml", model);

                QueueEmailMessage queueEmail = new QueueEmailMessage(Input.Email, "", body, "Reset Password");
                await _cloudStorageService.SendMessage(queueEmail);

                //await _emailSender.SendEmailAsync(Input.Email, "Reset Password", body);

                return(RedirectToPage("./ForgotPasswordConfirmation"));
            }

            return(Page());
        }
コード例 #4
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                var cars = await _carService.GetCars(Reservation.PickUpTime, Reservation.DropOffTime, Reservation.VehicleModelId);

                ViewData["CarId"] = new SelectList(cars, "Id", "PlateNumber");
                return(Page());
            }

            _logger.LogInformation(LoggingEvents.GetItem, "Get Car {ID}", Reservation.CarId);
            var car = await _carService.GetCar(Reservation.CarId);

            if (car == null)
            {
                _logger.LogInformation(LoggingEvents.GetItemNotFound, "Get Car {ID} NOT FOUND", Reservation.CarId);
                return(NotFound());
            }

            _logger.LogInformation(LoggingEvents.GetItem, "Get Reservation {ID}", Reservation.Id);
            Reservation = await _reservationService.GetReservation(Reservation.Id);

            if (Reservation == null)
            {
                _logger.LogInformation(LoggingEvents.GetItemNotFound, "Get Reservation {ID} NOT FOUND", Reservation.Id);
                return(NotFound());
            }

            try
            {
                _logger.LogInformation(LoggingEvents.UpdateItem, "Update Reservation {ID} with Car {ID}", Reservation.Id, Reservation.CarId);
                await _reservationService.EditReservation(Reservation.Id, car.Id);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!_reservationService.ReservationExists(Reservation.Id))
                {
                    _logger.LogInformation(LoggingEvents.UpdateItemNotFound, "Update Reservation {ID} NOT FOUND", Reservation.Id);
                    return(NotFound());
                }
                else
                {
                    return(StatusCode(409));
                }
            }

            const string view = "/Views/Emails/ReservationEmailAccepted";

            var user = await _userManager.Users
                       .Where(u => u.Id == Reservation.UserId)
                       .SingleOrDefaultAsync();

            var culture = Thread.CurrentThread.CurrentCulture.Name;

            if (!string.IsNullOrEmpty(user.Culture))
            {
                Thread.CurrentThread.CurrentCulture   = new CultureInfo(user.Culture);
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(user.Culture);
            }

            var model = new EmailReservationDto
            {
                UserName    = user.Name ?? user.Email,
                Email       = user.Email,
                VehicleType = Reservation.VehicleType,
                Address     = Reservation.Address,
                PickUpTime  = Reservation.PickUpTime,
                DropOffTime = Reservation.DropOffTime,
                Price       = Reservation.Price,
                State       = Dal.Entities.Reservation.ReservationStates.Accepted
            };

            try
            {
                var message = await _render.RenderViewToStringAsync($"{view}Html.cshtml", model);

                //await _emailSender.SendEmailAsync(user.Email, "Reservation", message);
                QueueEmailMessage queueEmail = new QueueEmailMessage(user.Email, "", message, "Reservation");
                await _cloudStorageService.SendMessage(queueEmail);
            }
            catch
            (InvalidOperationException)
            {
                return(RedirectToPage("./Index"));
            }

            if (!string.IsNullOrEmpty(culture))
            {
                Thread.CurrentThread.CurrentCulture   = new CultureInfo(culture);
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
            }

            return(RedirectToPage("./Index"));
        }
コード例 #5
0
        public async Task <IActionResult> OnPostAsync()
        {
            User user = await _userManager.GetUserAsync(HttpContext.User);

            var vehicle = await _vehicleModelService.GetVehicle(Input.VehicleModelId);

            var address = await _addressService.GetAddress(Input.AddressId);

            int days = (Input.DropOffTime.Date - Input.PickUpTime.Date).Days;

            if (user == null || vehicle == null || address == null)
            {
                return(NotFound());
            }

            if (days < 1)
            {
                return(RedirectToPage("./List"));
            }

            if (days > 100)
            {
                return(RedirectToPage("./List"));
            }

            if (Input.PickUpTime.Date < DateTime.Now.Date.AddDays(1))
            {
                return(RedirectToPage("./List"));
            }

            var cars = await _carService.GetCars(Input.PickUpTime, Input.DropOffTime, Input.VehicleModelId);

            CarFound = cars.Count();

            if (CarFound <= 0)
            {
                return(RedirectToPage("./List"));
            }

            ReservationDto reservationDto = new ReservationDto
            {
                User           = user.UserName,
                UserId         = user.Id,
                Address        = address.ZipCode + " " + address.City + " " + address.StreetAddress,
                AddressId      = address.Id,
                PickUpTime     = Input.PickUpTime,
                DropOffTime    = Input.DropOffTime,
                VehicleModelId = vehicle.Id,
                VehicleType    = vehicle.VehicleType,
                Price          = days * vehicle.PricePerDay
            };

            Reservation = reservationDto;

            _logger.LogInformation(LoggingEvents.InsertItem, "Create Reservation");
            await _reservationService.CreateReservation(reservationDto);

            var model = new EmailReservationDto
            {
                UserName    = user.Name ?? user.Email,
                Email       = user.Email,
                VehicleType = reservationDto.VehicleType,
                Address     = reservationDto.Address,
                PickUpTime  = reservationDto.PickUpTime,
                DropOffTime = reservationDto.DropOffTime,
                Price       = reservationDto.Price,
                State       = ReservationStates.Undecieded
            };

            const string view    = "/Views/Emails/ReservationEmail";
            var          message = await _render.RenderViewToStringAsync($"{view}Html.cshtml", model);

            QueueEmailMessage queueEmail = new QueueEmailMessage(user.Email, "", message, "Reservation");
            await _cloudStorageService.SendMessage(queueEmail);

            //await _emailSender.SendEmailAsync(user.Email, "Reservation", message);

            return(RedirectToPage("./List"));
        }