示例#1
0
        public async Task <IActionResult> ForgotPassword([FromBody] ForgotPasswordDto forgotPasswordDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var user = await _userManager.FindByEmailAsync(forgotPasswordDto.Email);

            if (user == null)
            {
                return(BadRequest("Invalid Request"));
            }

            var token = await _userManager.GeneratePasswordResetTokenAsync(user);

            var param = new Dictionary <string, string> {
                { "token", token }, { "email", forgotPasswordDto.Email }
            };

            var callback = QueryHelpers.AddQueryString("https://localhost:4200/reset-password", param);

            SendMail(forgotPasswordDto.Email, forgotPasswordDto.Email, "Reset Password", $"<a href=`{callback}`>Click to reset Password</a>");

            return(Ok());
        }
        public async Task <IActionResult> ResendConfirmation(ForgotPasswordDto resendEmailDto)
        {
            var user = await _userManager.FindByEmailAsync(resendEmailDto.Email);

            if (user == null)
            {
                return(BadRequest("Invalid Email: User does not exist"));
            }

            // send an email confirmation message
            var emailToken = await _userManager.GenerateEmailConfirmationTokenAsync(user);

            var param = new Dictionary <string, string>
            {
                { "token", emailToken },
                { "email", user.Email }
            };

            var callback = QueryHelpers.AddQueryString(resendEmailDto.ClientURI, param);

            var message = new EmailMessage(new string[] { user.Email }, "Confirm Your Email", callback, null);
            await _emailSender.SendEmailAsync(message);

            return(Ok());
        }
        public async Task <IActionResult> ForgotPassword(ForgotPasswordDto forgotPasswordDto)
        {
            var user = await _userManager.FindByEmailAsync(forgotPasswordDto.Email);

            if (user == null)
            {
                return(BadRequest("Kullanıcı Bulunamadı."));
            }

            if (!await _userManager.IsEmailConfirmedAsync(user))
            {
                return(BadRequest("Lütfen Mail Adresinizi Doğrulayınız."));
            }


            string passwordResetToken = HttpUtility.UrlEncode(await _userManager.GeneratePasswordResetTokenAsync(user));
            string callbackUrl        = UrlBuilder.GenerateResetPasswordLink(user.Id, passwordResetToken);

            var emailResult = _emailService.SendPasswordResetEmail(user.Email, callbackUrl);

            if (emailResult.ResultType == ResultType.Success)
            {
                return(Ok("Email Adresinize Gönderilen Linkten Şifrenizi Sıfırlayabilirsiniz."));
            }

            return(BadRequest("Email Gönderilirken Bir Hata Oluştu."));
        }
        public async Task <IActionResult> ForgotPassword(ForgotPasswordDto forgotPasswordDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var user = await _userManager.FindByEmailAsync(forgotPasswordDto.Email);

            if (user == null)
            {
                return(BadRequest("User does not exist"));
            }

            var token = await _userManager.GeneratePasswordResetTokenAsync(user);

            var param = new Dictionary <string, string>
            {
                { "token", token },
                { "email", forgotPasswordDto.Email }
            };

            var callback = QueryHelpers.AddQueryString(forgotPasswordDto.ClientURI, param);

            var message = new EmailMessage(new string[] { user.Email }, "Reset Password", callback, null);
            await _emailSender.SendEmailAsync(message);

            return(Ok());
        }
        public async Task <ActionResult <string> > ForgotPassword([FromBody] ForgotPasswordDto forgotPasswordDto)
        {
            var result = await _loginService.CheckIfUserExists(forgotPasswordDto.companyEmail);

            if (result == null)
            {
                return(BadRequest("Given email address doesn't exists."));
            }

            var token = await _loginService.GeneratePasswordResetToken();

            //var token = _loginService.SendEmailToUser(forgotPasswordDto);

            if (token != null)
            {
                var emailSentToUser = await _loginService.SendEmailToUser(result, token);

                if (emailSentToUser)
                {
                    return(Ok("Password Reset Link has been sent to your email address."));
                }
            }

            return(BadRequest("Some error occured !"));
        }
        public async Task <IActionResult> ForgotPassword([FromBody] ForgotPasswordDto model)
        {
            var account = await _authRepo.GetAccountByEmail(model.Email);

            if (account == null)
            {
                return(NotFound($"そのEメールアドレス({model.Email})は登録されていません"));
            }
            if (account.UserName != model.UserId)
            {
                return(BadRequest("ユーザーIDとメールアドレスが一致しません"));
            }
            if (!account.EmailConfirmed)
            {
                return(BadRequest("ユーザー認証がされていません。"));
            }

            string code = await _userManager.GeneratePasswordResetTokenAsync(account);

            var request     = Url.ActionContext.HttpContext.Request;
            var callbackUrl = request.Scheme + "://" + request.Host.Value + "/account/password/reset/" + account.Id + "/" + WebUtility.UrlEncode(code);
            await _emailSender.SendEmailAsync(model.Email, "パスワードのリセット", BuildResetPasswordContent(account.UserName, callbackUrl));

            return(Ok());
        }
示例#7
0
        public async Task ForgotPassword(ForgotPasswordDto input)
        {
            var user = await _userManager.FindByEmailAsync(input.Email);

            if (user == null || !(await _userManager.IsEmailConfirmedAsync(user)))
            {
                throw new Abp.UI.UserFriendlyException(L("EmailIsNotValidMessage"));
            }

            var clientAddress = SettingManager.GetSettingValue(Configuration.AppSettingNames.ClientRootAddress);

            var resetCode = await _userManager.GeneratePasswordResetTokenAsync(user);

            var callbackUrl = string.Format("{0}account/resetpassword?userId={1}&resetCode={2}", clientAddress, user.Id, System.Web.HttpUtility.UrlEncode(resetCode));

            var filePath = WebContentDirectoryFinder.CalculateContentRootFolder() + "\\Content\\Templates\\forgot-password.html";
            var template = Helpers.FluentTemplate.CultureTemplateFromFile(
                filePath,
                new
            {
                UrlReset = callbackUrl,
                Name     = user.FullName,
                user.UserName
            },
                CultureInfo.CurrentCulture);

            _smtpEmailSender.Send(
                to: user.EmailAddress,
                subject: string.Format("{0}{1}", L("AppName"), L("ResetPassword")),
                body: template,
                isBodyHtml: true);
        }
        public async Task <bool> ForgotPassword(ForgotPasswordDto input)
        {
            //Disabling MayHaveTenant filter, so we can reach to all users
            using (CurrentUnitOfWork.DisableFilter(AbpDataFilters.MayHaveTenant))
            {
                //Now, we can search for a user name in all tenants
                User userFromInput = await _userManager.Users.FirstOrDefaultAsync(u => u.EmailAddress == input.Email);

                if (userFromInput == null)
                {
                    throw new UserFriendlyException($"{input.Email} did not match any one in our records. Please try again or contact an administrator for assistance in resetting your password.");
                }

                userFromInput.SetNewPasswordResetCode();

                var callbackUrl = $"{GetHostName()}/?r=reset-password&i={userFromInput.Id}&t={userFromInput.PasswordResetCode}&n={userFromInput.EmailAddress}";
                //Send a notification email

                _emailSender.Send(
                    to: userFromInput.EmailAddress,
                    subject: "Social Uplift - Reset Password",
                    body: $"Please reset your password by clicking <a href=\"{callbackUrl}\">here</a>.",
                    isBodyHtml: true
                    );

                return(true);
            }
        }
 public async Task <IActionResult> ChangePasswordByCode([FromBody] ForgotPasswordDto model)
 {
     if (await _accountManager.CheckActiveCodeAsync(model.Email, model.Code, model.Password))
     {
         return(Ok("Success"));
     }
     return(Conflict("Invalid Code or Expired Time!!"));
 }
示例#10
0
 public async Task <IActionResult> ForgotPassword(ForgotPasswordDto forgotPassword)
 {
     return((await _accountService.ForgotPassword(forgotPassword.Email))
            .Match <IActionResult>(
                Ok,
                BadRequest
                ));
 }
        public async Task SendForgotPassword([FromBody] ForgotPasswordDto forgotPasswordDto)
        {
            if (!ModelState.IsValid)
            {
                Forbid();
            }

            await _forgotPasswordService.SendForgotPasswordAsync(forgotPasswordDto);
        }
示例#12
0
        public async Task <ActionResult <ForgotPasswordResult> > ForgotPassword([FromBody, Required] ForgotPasswordDto forgotPasswordRequest)
        {
            var isLocal = HttpContext.IsLocal() ||
                          _networkManager.IsInLocalNetwork(HttpContext.GetNormalizedRemoteIp());

            var result = await _userManager.StartForgotPasswordProcess(forgotPasswordRequest.EnteredUsername, isLocal).ConfigureAwait(false);

            return(result);
        }
        public async Task <IActionResult> forgotPassword([FromBody] ForgotPasswordDto forgotPasswordDto)
        {
            if (!ModelState.IsValid)
            {
                return(Ok(0));
            }

            return(Ok(await _auth.forgotPassword(forgotPasswordDto)));
        }
示例#14
0
        private ForgotPasswordDto GetTestForgotPasswordDto()
        {
            var forgotpasswordDto = new ForgotPasswordDto
            {
                Email = "*****@*****.**"
            };

            return(forgotpasswordDto);
        }
示例#15
0
        public async Task <IActionResult> ForgotPassword([FromBody] ForgotPasswordDto model)
        {
            var result = await _authService.ForgotPassword(model.Email, Url, Request.Scheme);

            if (result.Success)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }
        /// <inheritdoc />
        public async Task SendEmailResetingAsync(string confirmationLink, ForgotPasswordDto forgotPasswordDto)
        {
            var user = await _userManager.FindByEmailAsync(forgotPasswordDto.Email);

            user.EmailSendedOnForgotPassword = DateTime.Now;
            await _userManager.UpdateAsync(user);

            var emailContent = _emailContentService.GetAuthResetPasswordEmail(confirmationLink);
            await _emailSendingService.SendEmailAsync(forgotPasswordDto.Email, emailContent.Subject, emailContent.Message, emailContent.Title);
        }
示例#17
0
        ///<inheritdoc/>
        public async Task SendEmailReseting(string confirmationLink, ForgotPasswordDto forgotPasswordDto)
        {
            var user = await _userManager.FindByEmailAsync(forgotPasswordDto.Email);

            user.EmailSendedOnForgotPassword = DateTime.Now;
            await _userManager.UpdateAsync(user);

            await _emailConfirmation.SendEmailAsync(forgotPasswordDto.Email, "Скидування пароля",
                                                    $"Для скидування пароля перейдіть за : <a href='{confirmationLink}'>посиланням</a>", "Адміністрація сайту EPlast");
        }
示例#18
0
        public async Task <IActionResult> ForgotPassword(ForgotPasswordDto request)
        {
            ServiceResponse <string> response = await authRepo.ForgotPassword(request.Email);

            if (!response.Success)
            {
                return(BadRequest(response));
            }
            return(Ok(response));
        }
示例#19
0
        public async Task <IActionResult> ForgotPassword([FromBody] ForgotPasswordDto userForgotPasswordDto)
        {
            var userFromDb = await _loginRepository.ForgotPassword(userForgotPasswordDto);

            if (userFromDb == null)
            {
                return(StatusCode(400));
            }
            return(StatusCode(200));
        }
示例#20
0
        public async Task <IActionResult> ForgotPassword([FromBody] ForgotPasswordDto forgotPassword)
        {
            var result = await _userService.ForgotPassword(forgotPassword);

            if (!result.IsSuccess)
            {
                return(BadRequest(result));
            }

            return(Ok(forgotPassword));
        }
示例#21
0
        public async Task <IActionResult> ForgotPassword(ForgotPasswordDto model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _response = await _repo.ForgotPassword(model);

            return(Ok(_response));
        }
        public ActionResult PasswordReset(ForgotPasswordDto model)
        {
            var result = _passwordService.PasswordResetMail(model);

            if (result.Success)
            {
                return(Ok(result.Message));
            }

            return(BadRequest(result.Message));
        }
        public IActionResult ForgotPassword(ForgotPasswordDto forgotPasswordDto)
        {
            var result = _authService.ForgotPassword(forgotPasswordDto);

            if (result.Success)
            {
                return(Ok(result));
            }

            return(BadRequest(result));
        }
示例#24
0
        public async Task <IActionResult> ForgetPassword([FromBody] ForgotPasswordDto forgotPasswordDto)
        {
            var response = await _authService.ForgotPassword(forgotPasswordDto);

            if (!response.Succeeded)
            {
                return(BadRequest(response));
            }

            return(Ok(response));
        }
示例#25
0
        public void InitRecoveryPasswordWrongEmailTest()
        {
            _factoryRepositoryMock.Setup(x => x.Accounts.GetByEmail(It.IsAny <string>())).Returns((AccountDbModel)null);
            var model = new ForgotPasswordDto()
            {
                Email  = "test",
                Origin = "test"
            };

            Assert.Throws <NotFoundUserException>(() => _accountService.InitRecoveryPassword(model));
        }
示例#26
0
 // POST api/<controller>
 public HttpResponseMessage Post([FromBody] ForgotPasswordDto value)
 {
     try
     {
         _service.SendPassword(value.Email);
     }
     catch (UserException ex)
     {
         return(Request.CreateResponse(HttpStatusCode.OK));
     }
     return(Request.CreateResponse(HttpStatusCode.OK));
 }
示例#27
0
        public async Task <int> forgotPassword(ForgotPasswordDto forgotPasswordDto)
        {
            User user = await _ctx.User.Where(m => m.UserName == forgotPasswordDto.UserName &&
                                              m.UserMail == forgotPasswordDto.UserMail &&
                                              m.DeletedDate == null).FirstOrDefaultAsync();

            if (user != null)
            {
                return(user.UserId);
            }
            return(0);
        }
 public void Initialize()
 {
     _mockLogger = new Mock <ILogger <ForgotPasswordService> >();
     _sendForgotPasswordEmailProcess = new Mock <ISendForgotPasswordEmailProcess>();
     _forgotPasswordService          = new ForgotPasswordService(_mockLogger.Object, _sendForgotPasswordEmailProcess.Object);
     _forgotPasswordDto = new ForgotPasswordDto()
     {
         EmailAddress = It.IsAny <string>(),
         CallBackUrl  = It.IsAny <string>(),
         UserId       = It.IsAny <string>(),
         LowellRef    = It.IsAny <string>()
     };
 }
示例#29
0
        public async Task SetResetPasswordActiveCodeAndSendEmail(ForgotPasswordDto dto)
        {
            var user = await GetLoginByEmailAsync(dto.Email);

            if (user == null)
            {
                throw new BusinessException("Địa chỉ email không tồn tại trong hệ thống.");
            }

            var token = await _dataProtectorUserTokenService.GenerateResetPasswordTokenAsync(user.Id);

            BackgroundJob.Enqueue(() => _messageService.SendMailResetPasswordUserAsync(user, token));
        }
示例#30
0
        public async Task <IActionResult> ForgotPassword([FromBody] ForgotPasswordDto forgotPasswordDto)
        {
            var user = await userManager.FindByEmailAsync(forgotPasswordDto.Email);

            if (user == null || !(await userManager.IsEmailConfirmedAsync(user)))
            {
                return(Forbid());
            }
            var code = await userManager.GeneratePasswordResetTokenAsync(user);

            await emailSender.SendResetPasswordEmail(user.Email, code);

            return(NoContent());
        }