コード例 #1
0
 void Validate()
 {
     if (string.IsNullOrWhiteSpace(FirstName))
     {
         throw new BookingException("First name must be set.");
     }
     if (string.IsNullOrWhiteSpace(LastName))
     {
         throw new BookingException("Last name must be set.");
     }
     if (string.IsNullOrWhiteSpace(Email))
     {
         throw new BookingException("E-mail must be set.");
     }
     if (string.IsNullOrWhiteSpace(PhoneNo))
     {
         throw new BookingException("Phone number must be set.");
     }
     if (!DateOfBirth.IsValid(Dob))
     {
         throw new BookingException("Date of birth must be set and a valid date.");
     }
     if (String.IsNullOrEmpty(Food))
     {
         throw new BookingException("Food must be set.");
     }
 }
コード例 #2
0
        public async Task <IActionResult> OnPostAsync(string creyTicket, string returnUrl = null)
        {
            ReturnUrl  = returnUrl;
            CreyTicket = creyTicket;

            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            _registrationHandler.Value.BeforeRegistration(CreyTicket);

            if (ModelState.IsValid)
            {
                DateOfBirthValidationResult dateOfBirthValidationResult = DateOfBirth.IsValid(Input.Year.Value, Input.Month.Value, Input.Day.Value);
                if (!dateOfBirthValidationResult.IsValid)
                {
                    BirthDateErrorMessage = dateOfBirthValidationResult.ErrorMessage;
                    return(Page());
                }

                bool isReCaptchaValid = await _reCaptcha.IsResponseValid(Request.Form["g-recaptcha-response"]);

                if (!isReCaptchaValid)
                {
                    ModelState.AddModelError(string.Empty, "Captcha validation unsuccessful.");
                    return(Page());
                }

                var user = new ApplicationUser
                {
                    UserName             = Input.UserName,
                    Email                = Input.Email,
                    EmailConfirmed       = false,
                    NewsletterSubscribed = Input.NewsletterSubscribed,
                };
                var utcDateOfBirth = new DateTime(Input.Year.Value, Input.Month.Value, Input.Day.Value);

                var result = await _registrationHandler.Value.RegisterUserAsync(user, Input.Password, utcDateOfBirth);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");
                    await _signInManager.SignInAsync(user, isPersistent : true, CredentialType.LoginPage.ToString());

                    await _accountMessageBroker.SendMessage(new RegisteredServiceBusMessage { AccountId = user.AccountId, CreyTicket = CreyTicket });

                    await _registrationHandler.Value.AfterRegistrationAsync(user, utcDateOfBirth, Url, CreyTicket, Input.AvatarId);

                    return(RedirectToPage("./Redirect", new { redirectUrl = returnUrl }));
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(error.Code.TranslateModelErrorCode(), error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
コード例 #3
0
        public async Task <IActionResult> ExternalRegisterUser([FromBody] RegisterExternalUserInputModel inputModel)
        {
            var info = await _signInManager.GetExternalLoginInfoAsync();

            if (info == null)
            {
                return(Unauthorized("Error loading external login information."));
            }

            var inputUser = inputModel.User;

            DateOfBirthValidationResult dateOfBirthValidationResult = DateOfBirth.IsValid(
                inputUser.Year.Value,
                inputUser.Month.Value,
                inputUser.Day.Value);

            if (!dateOfBirthValidationResult.IsValid)
            {
                return(BadRequest(dateOfBirthValidationResult.ErrorMessage));
            }

            var user = new ApplicationUser
            {
                UserName             = inputUser.UserName,
                Email                = info.Principal.FindFirstValue(ClaimTypes.Email),
                EmailConfirmed       = false,
                NewsletterSubscribed = inputUser.NewsletterSubscribed
            };

            var utcDateOfBirth = new DateTime(inputUser.Year.Value, inputUser.Month.Value, inputUser.Day.Value);

            var result = await _registrationHandler.Value.RegisterUserAsync(user, null, utcDateOfBirth);

            if (!result.Succeeded)
            {
                var errors = result.Errors.ToDictionary(x => x.Code, x => x.Description);
                return(NotFound(errors));
            }

            result = await _userManager.AddLoginAsync(user, info);

            if (!result.Succeeded)
            {
                var errors = result.Errors.ToDictionary(x => x.Code, x => x.Description);
                return(NotFound(errors));
            }

            _logger.LogInformation("User created an account using {Name} provider.", info.LoginProvider);
            await _signInManager.SignInAsync(user, isPersistent : true, info.LoginProvider);

            await _accountMessageBroker.SendMessage(new RegisteredServiceBusMessage { AccountId = user.AccountId, CreyTicket = inputModel.CreyTicket });

            await _registrationHandler.Value.AfterRegistrationAsync(user, utcDateOfBirth, Url, inputModel.CreyTicket, inputUser.AvatarId);

            return(Ok());
        }
コード例 #4
0
            internal static void ValidateAndSetDefaults(List <Pax> paxList, bool isFirstCabin, ref string defaultGroup)
            {
                bool isFirstPax = isFirstCabin;

                foreach (Pax pax in paxList)
                {
                    if (isFirstPax)
                    {
                        if (string.IsNullOrWhiteSpace(pax.Group))
                        {
                            throw new BookingException("Group must be set for the first pax.");
                        }
                        defaultGroup = pax.Group;
                    }
                    else if (string.IsNullOrWhiteSpace(pax.Group))
                    {
                        pax.Group = defaultGroup;
                    }

                    isFirstPax = false;

                    if (string.IsNullOrWhiteSpace(pax.FirstName))
                    {
                        throw new BookingException("First name must be set.");
                    }
                    if (string.IsNullOrWhiteSpace(pax.LastName))
                    {
                        throw new BookingException("Last name must be set.");
                    }
                    if (!DateOfBirth.IsValid(pax.Dob))
                    {
                        throw new BookingException("Date of birth must be set and a valid date.");
                    }
                    if (!IsoNationality.TryValidateOrSetDefault(pax.Nationality, out var nationality))
                    {
                        throw new BookingException("Nationality must be a 2-letter ISO country code.");
                    }
                    pax.Nationality = nationality;

                    if (pax.Years < 0)
                    {
                        throw new BookingException("Years must be greater than or equal to zero.");
                    }
                }
            }
コード例 #5
0
 internal void ValidateDetailsAndSetDefaults()
 {
     if (String.IsNullOrWhiteSpace(FirstName))
     {
         throw new BookingException("First name must be set.");
     }
     if (String.IsNullOrWhiteSpace(LastName))
     {
         throw new BookingException("Last name must be set.");
     }
     if (!DateOfBirth.IsValid(Dob))
     {
         throw new BookingException("Date of birth must be set and a valid date.");
     }
     if (String.IsNullOrEmpty(Food))
     {
         throw new BookingException("Food must be set.");
     }
 }
コード例 #6
0
        public async Task <IActionResult> RegisterUser([FromBody] RegisterUserInputModel inputModel)
        {
            _registrationHandler.Value.BeforeRegistration(inputModel.CreyTicket);
            var inputUser = inputModel.User;

            DateOfBirthValidationResult dateOfBirthValidationResult = DateOfBirth.IsValid(
                inputUser.Year.Value,
                inputUser.Month.Value,
                inputUser.Day.Value);

            if (!dateOfBirthValidationResult.IsValid)
            {
                return(BadRequest(dateOfBirthValidationResult.ErrorMessage));
            }

            var user = new ApplicationUser
            {
                UserName             = inputUser.UserName,
                Email                = inputUser.Email,
                EmailConfirmed       = false,
                NewsletterSubscribed = inputUser.NewsletterSubscribed,
            };

            var utcDateOfBirth = new DateTime(inputUser.Year.Value, inputUser.Month.Value, inputUser.Day.Value);

            var result = await _registrationHandler.Value.RegisterUserAsync(user, inputUser.Password, utcDateOfBirth);

            if (!result.Succeeded)
            {
                return(BadRequest(result.Errors));
            }

            _logger.LogInformation("User created a new account with password.");
            await _signInManager.SignInAsync(user, isPersistent : true, CredentialType.LoginPage.ToString());

            await _accountMessageBroker.SendMessage(new RegisteredServiceBusMessage { AccountId = user.AccountId, CreyTicket = inputModel.CreyTicket });

            await _registrationHandler.Value.AfterRegistrationAsync(user, utcDateOfBirth, Url, inputModel.CreyTicket, inputUser.AvatarId);

            return(Ok());
        }
コード例 #7
0
        public async Task <IActionResult> OnPostAsync(string provider, string creyTicket, string returnUrl = null)
        {
            ReturnUrl  = returnUrl;
            CreyTicket = creyTicket;

            var info = await _signInManager.GetExternalLoginInfoAsync();

            if (info == null)
            {
                ErrorMessage = "Error loading external login information.";
                return(RedirectToPage("./Login", new { ReturnUrl = returnUrl }));
            }

            LoginProvider = info.LoginProvider;
            Email         = info.Principal.FindFirstValue(ClaimTypes.Email);
            ReturnUrl     = returnUrl;

            if (ModelState.IsValid)
            {
                DateOfBirthValidationResult dateOfBirthValidationResult = DateOfBirth.IsValid(Input.Year.Value, Input.Month.Value, Input.Day.Value);
                if (!dateOfBirthValidationResult.IsValid)
                {
                    BirthDateErrorMessage = dateOfBirthValidationResult.ErrorMessage;
                    return(Page());
                }

                var user = new ApplicationUser
                {
                    UserName             = Input.UserName,
                    Email                = Email,
                    EmailConfirmed       = false,
                    NewsletterSubscribed = Input.NewsletterSubscribed,
                };
                var utcDateOfBirth = new DateTime(Input.Year.Value, Input.Month.Value, Input.Day.Value);

                var result = await _registrationHandler.Value.RegisterUserAsync(user, null, utcDateOfBirth);

                if (result.Succeeded)
                {
                    result = await _userManager.AddLoginAsync(user, info);

                    if (result.Succeeded)
                    {
                        _logger.LogInformation("User created an account using {Name} provider.", info.LoginProvider);
                        await _signInManager.SignInAsync(user, isPersistent : true, info.LoginProvider);

                        await _accountMessageBroker.SendMessage(new RegisteredServiceBusMessage { AccountId = user.AccountId, CreyTicket = CreyTicket });

                        await _registrationHandler.Value.AfterRegistrationAsync(user, utcDateOfBirth, Url, CreyTicket, Input.AvatarId);

                        return(RedirectToPage("./Redirect", new { redirectUrl = returnUrl }));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(error.Code.TranslateModelErrorCode(), error.Description);
                }
            }

            return(Page());
        }