Ejemplo n.º 1
0
        public IActionResult SendEmailConfirmLink()
        {
            // if (User.Identity.Name != null)
            // {
            //     return Redirect("/");
            // }

            SendEmailConfirmLinkViewModel model = new SendEmailConfirmLinkViewModel();

            model.IsSuccess = false;
            ModelState.AddModelError(string.Empty, $"Your email address not confirmed yet!");

            return(View(model));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> SendEmailConfirmLink(SendEmailConfirmLinkViewModel model)
        {
            if (ModelState.IsValid)
            {
                var findByEmail = await _userManager.FindByEmailAsync(model.Value);

                if (findByEmail != null)
                {
                    if (findByEmail.EmailConfirmed)
                    {
                        model.IsSuccess = true;
                        ModelState.AddModelError(string.Empty, $"Email already confirmed");
                        return(View(model));
                    }

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(findByEmail);

                    code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));

                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { area = "Identity", userId = findByEmail.Id, code = code },
                        protocol: Request.Scheme);

                    //MailContent mail = new MailContent("Samyra Global", "Please confirm your Email address", HtmlEncoder.Default.Encode(callbackUrl), "Click here");

                    _emailSender.SendEmail(Mail.DNR, findByEmail.Email, findByEmail.FullName, "Confirm your email",
                                           $"<a href='{HtmlEncoder.Default.Encode(callbackUrl)}' target='_blank'>Click here</a>");

                    //var result = await _repository.GenerateLogTokenAsync(TokenType.EMAIL, findByEmail.Id, findByEmail.Email, code);

                    model.Value     = "";
                    model.IsSuccess = true;
                    ModelState.AddModelError(string.Empty, $"Confirmation link has been sent, please check your mailbox.");
                    return(View(model));
                }
                else
                {
                    model.IsSuccess = false;
                    ModelState.AddModelError(string.Empty, $"The '{model.Value}' not found in database, please enter valid email address.");
                    return(View(model));
                }
            }

            model.IsSuccess = false;
            ModelState.AddModelError(string.Empty, $"Your email address not confirmed yet!");
            return(View(model));
        }