Пример #1
0
        public async Task <IActionResult> ForgotPassword(string email)
        {
            var user = await userManager.FindByEmailAsync(email);

            if (user == null)
            {
                return(Content("Check your email for a password reset link"));
            }

            var passwordResetToken = await userManager.GeneratePasswordResetTokenAsync(user);

            var passwordResetUrl = Url.Action("ResetPassword", "Account", new { id = user.Id, token = passwordResetToken }, Request.Scheme);

            LocalEmailClient.SendEmail("reset password", "Account", "ResetPassword", passwordResetUrl);
            //await _messageService.Send(email, "Password reset", $"Click <a href=\"" + passwordResetUrl + "\">here</a> to reset your password");

            //return Content("Check your email for a password reset link");

            return(RedirectToAction(actionName: "Login", controllerName: "Account"));
        }
Пример #2
0
        public async Task <IActionResult> Register(Registration registrationParams)
        {
            if (registrationParams.Password != registrationParams.RetypedPassword)
            {
                ModelState.AddModelError(string.Empty, "Passwords don't match");
                return(View("Register", registrationParams));
            }

            User newUser = new User
            {
                UserName = registrationParams.Email,
                Email    = registrationParams.Email
            };

            var userCreationResult = await userManager.CreateAsync(newUser, registrationParams.Password);

            if (!userCreationResult.Succeeded)
            {
                foreach (var error in userCreationResult.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
                return(View("Register", registrationParams));
            }

            await userManager.AddClaimAsync(newUser, new Claim(ClaimTypes.Role, "ApplicationUser"));

            string emailConfirmationToken = await userManager.GenerateEmailConfirmationTokenAsync(newUser);

            string tokenVerificationUrl = Url.Action("VerifyEmail", "Registrations", new { id = newUser.Id, token = emailConfirmationToken }, Request.Scheme);

            LocalEmailClient.SendEmail("email confirmation", "Account", "VerifyEmail", tokenVerificationUrl);
            //await _messageService.Send(email, "Verify your email", $"Click <a href=\"{tokenVerificationUrl}\">here</a> to verify your email");

            //return Content("Check your email for a verification link");

            return(RedirectToAction(actionName: "Index", controllerName: "Users"));
        }