コード例 #1
0
        private async Task LoadAsync(CognitoUser user)
        {
            var userName = await _userManager.GetUserNameAsync(user);

            var address     = user.Attributes[CognitoAttribute.Address.AttributeName];
            var birthDate   = user.Attributes[CognitoAttribute.BirthDate.AttributeName];
            var gender      = user.Attributes[CognitoAttribute.Gender.AttributeName];
            var nickName    = user.Attributes[CognitoAttribute.NickName.AttributeName];
            var phoneNumber = user.Attributes[CognitoAttribute.PhoneNumber.AttributeName];
            var familyName  = user.Attributes[CognitoAttribute.FamilyName.AttributeName];
            var givenName   = user.Attributes[CognitoAttribute.GivenName.AttributeName];


            Username = userName;
            Input    = new AccountModel()
            {
                Address     = address,
                BirthDate   = birthDate,
                GivenName   = givenName,
                Gender      = gender,
                NickName    = nickName,
                PhoneNumber = phoneNumber,
                FamilyName  = familyName
            };
        }
コード例 #2
0
        private async Task LoadAsync(CognitoUser user)
        {
            var userName = await _userManager.GetUserNameAsync(user);

            var addressLine1 = user.Attributes["custom:AddressLine1"];
            var addressLine2 = user.Attributes["custom:AddressLine2"];
            var city         = user.Attributes["custom:City"];
            var state        = user.Attributes["custom:State"];
            var Country      = user.Attributes["custom:Country"];
            var zipCode      = user.Attributes["custom:ZipCode"];


            Username = userName;

            Input = new AccountModel()
            {
                AddressLine1 = addressLine1,
                AddressLine2 = addressLine2,
                City         = city,
                State        = state,
                Country      = Country,
                ZipCode      = zipCode
            };


            if (Input.AddressLine1 == "default")
            {
                Input.AddressLine1 = "";
            }
            if (Input.AddressLine2 == "default")
            {
                Input.AddressLine2 = "";
            }
            if (Input.City == "default")
            {
                Input.City = "";
            }
            if (Input.State == "default")
            {
                Input.State = "";
            }
            if (Input.Country == "default")
            {
                Input.Country = "";
            }
            if (Input.ZipCode == "default")
            {
                Input.ZipCode = "";
            }
        }
コード例 #3
0
        private async Task LoadAsync(CognitoUser user)
        {
            var userName = await _userManager.GetUserNameAsync(user);

            var address      = user.Attributes[CognitoAttribute.Address.AttributeName];
            var birthDate    = user.Attributes[CognitoAttribute.BirthDate.AttributeName];
            var gender       = user.Attributes[CognitoAttribute.Gender.AttributeName];
            var nickName     = user.Attributes[CognitoAttribute.NickName.AttributeName];
            var phoneNumber  = user.Attributes[CognitoAttribute.PhoneNumber.AttributeName];
            var familyName   = user.Attributes[CognitoAttribute.FamilyName.AttributeName];
            var givenName    = user.Attributes[CognitoAttribute.GivenName.AttributeName];
            var addressLine1 = user.Attributes["custom:AddressLine1"];
            var addressLine2 = user.Attributes["custom:AddressLine2"];
            var city         = user.Attributes["custom:City"];
            var state        = user.Attributes["custom:State"];
            var Country      = user.Attributes["custom:Country"];
            var zipCode      = user.Attributes["custom:ZipCode"];


            Username = userName;

            Input = new AccountModel()
            {
                Address      = address,
                BirthDate    = birthDate,
                GivenName    = givenName,
                Gender       = gender,
                NickName     = nickName,
                PhoneNumber  = phoneNumber,
                FamilyName   = familyName,
                AddressLine1 = addressLine1,
                AddressLine2 = addressLine2,
                City         = city,
                State        = state,
                Country      = Country,
                ZipCode      = zipCode
            };
            if (Input.FamilyName == "default")
            {
                Input.FamilyName = "";
            }

            if (Input.Address == "default")
            {
                Input.Address = "";
            }
            if (Input.Gender == "default")
            {
                Input.Gender = string.Empty;
            }
            if (Input.NickName == "default")
            {
                Input.NickName = string.Empty;
            }
            if (Input.GivenName == "default")
            {
                Input.GivenName = "";
            }
            if (Input.BirthDate == "0000-00-00")
            {
                Input.BirthDate = "";
            }
            if (Input.PhoneNumber == "+01234567890")
            {
                Input.PhoneNumber = "";
            }

            if (Input.AddressLine1 == "default")
            {
                Input.AddressLine1 = "";
            }
            if (Input.AddressLine2 == "default")
            {
                Input.AddressLine2 = "";
            }
            if (Input.City == "default")
            {
                Input.City = "";
            }
            if (Input.State == "default")
            {
                Input.State = "";
            }
            if (Input.Country == "default")
            {
                Input.Country = "";
            }
            if (Input.ZipCode == "default")
            {
                Input.ZipCode = "";
            }
        }
コード例 #4
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            if (ModelState.IsValid)
            {
                //get user id
                var userId = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Name).Value;

                var user = await _userManager.FindByIdAsync(userId);

                if (user == null)
                {
                    return(NotFound($"Unable to load user with ID '{userId}'."));
                }

                var result = await _userManager.ConfirmSignUpAsync(user, Input.Code, true);

                if (!result.Succeeded)
                {
                    throw new InvalidOperationException($"Error confirming account for user with ID '{userId}':");
                }
                else
                {
                    //this part is to add customer information into the DB
                    var userName = await _userManager.GetUserNameAsync(user);

                    var firstName   = user.Attributes[CognitoAttribute.GivenName.AttributeName];
                    var lastName    = user.Attributes[CognitoAttribute.FamilyName.AttributeName];
                    var email       = user.Attributes[CognitoAttribute.Email.AttributeName];
                    var dateOfBirth = user.Attributes[CognitoAttribute.BirthDate.AttributeName];
                    var phone       = user.Attributes[CognitoAttribute.PhoneNumber.AttributeName];
                    var customer_ID = user.Attributes[CognitoAttribute.Sub.AttributeName];
                    var customer    = new Customer()
                    {
                        Customer_Id = customer_ID,
                        //Customer_Id = 1111,
                        Username  = userName,
                        FirstName = firstName,
                        LastName  = lastName,
                        Email     = email,
                        Phone     = phone
                    };
                    _context.Add(customer);
                    _context.SaveChanges();

                    var currentCustomerID = _context.Customer.Find(user.Attributes[CognitoAttribute.Sub.AttributeName]);

                    //get cardid
                    var cartId     = HttpContext.Request.Cookies["CartId"];
                    var recentCart = await _context.Cart.FindAsync(Convert.ToString(cartId));

                    recentCart.Customer = currentCustomerID;
                    _context.Update(recentCart);
                    await _context.SaveChangesAsync();


                    return(returnUrl != null?LocalRedirect(returnUrl) : Page() as IActionResult);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }