Пример #1
0
        public async Task <IActionResult> SignUp(SignUpViewModel model, string image)
        {
            // Returning the SignUp view if the SignUpViewModel is not valid.
            if (!ModelState.IsValid)
            {
                return(View());
            }

            //Error Messages
            _signUpService.ProcessForm(model);
            //If the register goes through
            //make the username the same as the password.
            // If the register goes through, a new instance application user is made
            var user = new ApplicationUser
            {
                UserName      = model.UserName,
                Email         = model.Email,
                ActiveAccount = true,
                FirstName     = model.FirstName,
                LastName      = model.LastName,
                Address       = model.Address,
                City          = model.City,
                Country       = model.Country,
                Image         = image
            };
            // Creating the user with _userManager.
            var result = await _userManager.CreateAsync(user, model.Password);

            if (result.Succeeded)
            {
                // The user is now registered succesfully.
                // Add the concatenated first name and last name as fullName in claims.
                await _userManager.AddClaimAsync(user, new Claim("Name", $"{model.FirstName} {model.LastName}"));

                // Signing in the user
                await _signInManager.SignInAsync(user, false);

                // Returning the user back to the homepage - now signed in
                return(RedirectToAction("Index", "Home"));
            }
            // If the upper didn't succeed, return the view
            return(View());
        }