Exemplo n.º 1
0
        public async Task <object> ForgotPasswordLink(string email)
        {
            var user = await unitOfWork.UserRepository.Find(u => u.UserEmail == email);

            var temporaryPassword = WordPressPasswordUtil.GetUniqID();
            var randomPassword    = Crypter.Phpass.Crypt(temporaryPassword);


            if (user.ToList().Count == 0)
            {
                //User Not found
                return(new
                {
                    Status = false,
                    Message = "User not exists for the given email address"
                });
            }
            else
            {
                var userDetails = await unitOfWork.UserRepository.Single(u => u.Id == user.Single().Id);

                userDetails.UserPass = randomPassword;
                unitOfWork.UserRepository.Update(userDetails);
                await unitOfWork.SaveChangesAsync();

                var ActivationLink = WordPressPasswordUtil.GetForgotPasswordLink(Convert.ToString(user.Single().Id), email, temporaryPassword);

                EmailHelper emailHelper = new EmailHelper("*****@*****.**", email, "[Grocedy] Password Reset Request for Grocedy", $"Someone has requested a new password for the following account on Grocedy:. {ActivationLink}");
                if (emailHelper.SendElastic())
                {
                    return(new
                    {
                        Status = true,
                        Message = $"Please check your inbox ,we have sent randomly generated password  to your email address {email}."
                    });
                }
                else
                {
                    return(new
                    {
                        Status = true,
                        Message = "Success , but Failed to sent reset password Link ."
                    });
                }
            }
        }