示例#1
0
        public virtual async Task <IActionResult> SendEmailConfirmation([FromBody][Required] GetConfirmEmail getConfirmEmail, CancellationToken cancellationToken = default)
        {
            await this.SecurityManager
            .GetConfirmEmailAsync(getConfirmEmail, cancellationToken);

            // BUG: Email confirmation event.
            //var callbackUrl = Url.Page("/Account/ConfirmEmail", pageHandler: null, values: new { userId = user.Id, code = code }, protocol: Request.Scheme);
            //await _emailSender.SendEmailAsync(user.Email, "Confirm your email", $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

            return(this.Ok());
        }
示例#2
0
        /// <summary>
        /// Generates an email confirmation token for a user.
        /// </summary>
        /// <param name="getConfirmEmail">The <see cref="GetConfirmEmail"/>.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
        /// <returns>The <see cref="ConfirmEmail"/>.</returns>
        public virtual async Task <ConfirmEmail> GetConfirmEmailAsync(GetConfirmEmail getConfirmEmail, CancellationToken cancellationToken = default)
        {
            if (getConfirmEmail == null)
            {
                throw new ArgumentNullException(nameof(getConfirmEmail));
            }

            var user = await this.UserManager
                       .FindByIdAsync(getConfirmEmail.UserId);

            if (user == null)
            {
                throw new NullReferenceException(nameof(user));
            }

            var code = await this.UserManager
                       .GenerateEmailConfirmationTokenAsync(user);

            return(new ConfirmEmail
            {
                Code = code,
                UserId = user.Id
            });
        }