public IBLMessage ResetPassword(string resetGuid, string newPassword)
        {
            /*
             * Password reset steps:
             * 1- Get reset request via reset guid.
             * 2- Get Membershipuser via email from reset request.
             * 3- Update user password
             * 4- Delete reset request from db.
             */

            try
            {
                IResetRequest resetRequest = UserManagementDAL.GetResetRequestByResetGuid(resetGuid);
                if (resetRequest != null)
                {
                    MembershipUser user = Membership.GetUser(resetRequest.UserEmail);
                    if (user != null)
                    {
                        //var oldPAssword = user.GetPassword();
                        var changeResult = user.ChangePassword(user.ResetPassword(), newPassword);
                        if (changeResult)
                        {
                            return(UserManagementDAL.DeleteResetRequest(resetGuid));
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                // log exception...
                Logger.Write(exception.Message, "UserManagementBusiness");
            }
            return(new BLMessage {
                Message = "An error occured during reseting password. Please try again later.", Result = SaveAttempts.Failure
            });
        }
        public IBLMessage SendResetLink(string userEmail, string title, string content)
        {
            /*
             * Send reset link steps:
             * 1- Save reset request via user email and generated guid.
             * 2- Send reset link via user email.
             */

            var appResult = UserManagementDAL.SaveResetRequest(userEmail);

            try
            {
                IResetRequest resetRequest = UserManagementDAL.GetResetRequestByEmail(userEmail);
                if (resetRequest != null)
                {
                    EmailHelper.Send("*****@*****.**", "p@ssw0rd", userEmail, title, String.Format(content, "website url", resetRequest.ResetGuid));
                }
                else
                {
                    return(new BLMessage {
                        Message = "Reset request could not be found.", Result = SaveAttempts.Failure
                    });
                }
            }
            catch (Exception exception)
            {
                // delete entry...
                UserManagementDAL.DeleteApplication(userEmail);
                // log exception...
                Logger.Write(exception.Message, "UserManagementBusiness");
                return(new BLMessage {
                    Message = "An error occured during sending reset request. Please try again later.", Result = SaveAttempts.Failure
                });
            }
            return(appResult);
        }
Exemplo n.º 3
0
 public Task AddAsync(IResetRequest request) => _repository.AddAsync(request as ResetRequest);
        public bool CheckResetPasswordGuid(string resetGuid)
        {
            IResetRequest resetRequest = UserManagementDAL.GetResetRequestByResetGuid(resetGuid);

            return(resetRequest == null);
        }