示例#1
0
        // Create User + send varification email
        public async Task <IdentityResult> CreateUserAsync(InValidUser invalidUser)
        {
            var user = new IdentityUser()
            {
                Email    = invalidUser.Email,
                UserName = invalidUser.Email
            };
            // pass userModel + password => save in DB
            var result = await _userManager.CreateAsync(user, invalidUser.Password);

            // If Succeed, send client email ask for varificaiton email address
            if (result.Succeeded)
            {
                var token = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                if (!string.IsNullOrEmpty(token))
                {
                    // replace actual token and username with placeholders
                    UserEmailOption userEmailOption = CompleteReturnString(user, token);
                    //send Verification Email
                    await _emailService.SendConsumerAccountVerification(userEmailOption);
                }
            }
            return(result);
        }
示例#2
0
        public async Task <IActionResult> ConsumerSignUp(InValidUser invalidUser)
        {
            if (ModelState.IsValid)
            {
                var result = await _accountRepo.CreateUserAsync(invalidUser);

                if (!result.Succeeded)
                {
                    foreach (var errorMessage in result.Errors)
                    {
                        ModelState.AddModelError("", errorMessage.Description);
                    }
                    return(View(invalidUser));
                }

                ModelState.Clear();
            }
            return(View());
        }