Ejemplo n.º 1
0
        public async Task <ReturnStatus> SendVerificationEmailAsync(string emailAddress, string emailView)
        {
            ReturnStatus retVal = new ReturnStatus()
            {
                IsSuccessful  = true,
                ErrorMessages = new List <string>(),
            };

            IdentityUser user = await UserManager.FindByEmailAsync(emailAddress);

            if (user == null)
            {
                retVal.IsSuccessful = false;
                retVal.ErrorMessages.Add(ErrorCodeConstants.ERROR_USER_DOES_NOT_EXIST);
            }
            else
            {
                SendGrid.Response response = await EmailSender.SendEmailAsync(emailAddress, "Hello from ShimMath.com", html : emailView);

                if (response.StatusCode != System.Net.HttpStatusCode.Accepted)
                {
                    retVal.IsSuccessful = false;
                    retVal.ErrorMessages.Add(ErrorCodeConstants.ERROR_VERIFICATION_EMAIL_SEND_FAILED);
                }
            }
            return(retVal);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Register(RegisterModel registerModel)
        {
            var user = new ApplicationUser {
                UserName = registerModel.Email, Email = registerModel.Email
            };

            var result = await _userManager.CreateAsync(user, registerModel.Password);

            if (result.Succeeded)
            {
                var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

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

                var callbackUrl = $"https://localhost:5005/#/confirm-email?userId={user.Id}&code={code}";

                await _emailSenderService.SendEmailAsync(registerModel.Email, "Подтвердите аккаунт",
                                                         $"<div>Подтвердите регистрацию, перейдя по ссылке: <a href='{callbackUrl}'>Подтверждение регистрации</a></div>");

                await _userManager.AddToRoleAsync(user, RolesEnum.User.ToString());

                await _signInManager.SignInAsync(user, false);

                return(Ok(
                           "Для завершения регистрации проверьте электронную почту и перейдите по ссылке, указанной в письме"));
            }


            return(BadRequest(result.Errors));
        }
        public async Task SendConfirmEmailAsync(RegistrationModel registerUserData)
        {
            var userForConfirmation = userManager.FindByEmailAsync(registerUserData.Email).Result;
            var confirmationToken   = await userManager.GenerateEmailConfirmationTokenAsync(userForConfirmation);

            var callbackUrl = Url.Action(
                "ConfirmEmail",
                "EmailConfirmation",
                new { userId = userForConfirmation.Id, code = confirmationToken },
                protocol: HttpContext.Request.Scheme);

            await emailService.SendEmailAsync(userForConfirmation.Email, "Confirm your account",
                                              $"Confirm registration by clicking on the link: <a href='{callbackUrl}'>{callbackUrl}</a>");
        }
Ejemplo n.º 4
0
        private async Task <bool> TrySendVerification(User user)
        {
            var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

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

            await _sender.SendEmailAsync(user.Email, "Confirm your account",
                                         $"Verify your email on click by <a href='{callbackUrl}'>link</a>");

            return(true);
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Register(RegistrationViewModel model)
        {
            if (ModelState.IsValid)
            {
                User user = new User
                {
                    Name     = model.Name,
                    Email    = model.Email,
                    UserName = model.Email
                };

                var result = await userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await userManager.AddToRoleAsync(user, "User");

                    var code = await userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.Action(
                        "ConfirmEmail",
                        "Account",
                        new { userId = user.Id, code = code },
                        protocol: HttpContext.Request.Scheme);
                    EmailSenderService emailService = new EmailSenderService();
                    await emailService.SendEmailAsync(model.Email, "Confirm your account",
                                                      $"Confirm registration by following the link: <a href='{callbackUrl}'>link</a>", options);

                    return(View("SuccessRegistration"));
                }
                else
                {
                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError(string.Empty, error.Description);
                    }
                }
            }
            return(View(model));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> ForgotPassword(ForgotPasswordViewModel model)
        {
            // If we got this far, something failed, redisplay form
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var user = await _userManager.FindByEmailAsync(model.Email);

            // Don't reveal that the user does not exist
            if (user == null)
            {
                ModelState.AddModelError(string.Empty, "The user does not exist");
                return(View(model));
            }

            var code = await _userManager.GeneratePasswordResetTokenAsync(user);

            var callbackUrl = Url.ResetPasswordCallbackLink(user.Id, code, Request.Scheme);
            await _emailSender.SendEmailAsync(model.Email, "QFLOW Reset Password",
                                              $"<p>Hi {model.Email}<p><p>You requested a password reset. Please reset your password by clicking here: <a href='{callbackUrl}'>link</a></p>");

            return(RedirectToAction(nameof(ForgotPasswordConfirmation)));
        }
Ejemplo n.º 7
0
        public async Task <Unit> Handle(SendEmailCommand request, CancellationToken cancellationToken)
        {
            await _emailSenderService.SendEmailAsync(request.ReceiverEmail, request.Subject, request.Message);

            return(new Unit());
        }