Example #1
0
        public async Task <IActionResult> Register(RegisterViewModel model)
        {
            var passwordValidationResult = this.userManager.ValidatePassword(model.Password);

            if (!passwordValidationResult.Success)
            {
                this.ShowNotification(passwordValidationResult.ResponseMessage);
                return(View());
            }

            var passwordHash = this.userManager.GetPasswordHash(model.Password);
            var user         = new OnlineStore.Models.User(
                model.Email, passwordHash, model.FirstName, model.LastName);
            var registrationResult = await this.userManager.CreateAsync(user);

            if (!registrationResult.Success)
            {
                this.ShowNotification(registrationResult.ResponseMessage);
                return(View());
            }

            if (!this.signInManager.RequireConfirmedEmail)
            {
                return(RedirectToLogin());
            }

            await this.SendVerificationEmailAsync(user);

            this.ShowNotification(SuccessfullRegistrationEmailTitle, NotificationType.Success);
            return(RedirectToLogin());
        }
Example #2
0
        private async Task SendVerificationEmailAsync(OnlineStore.Models.User user)
        {
            /// Send confirmation email:
            var code = await userManager.GenerateEmailConfirmationTokenAsync(user);

            var callbackUrl = this.Url.Action(
                "ConfirmEmail", "Manage",
                new { userId = user.Id, code = code },
                protocol: Request.Scheme);

            await this.emailSender
            .SendEmailAsync(
                AdministratorEmail,
                AdministratorName,
                user.Email,
                user.FullName,
                "Confirm your email",
                $"Please confirm your account by " +
                $"<a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");
        }