示例#1
0
        public ResponseMessageForgotPassword ForgotPassword(string emailId)
        {
            ResponseMessageForgotPassword responseMessage = new ResponseMessageForgotPassword();

            try {
                Users user = _context.Users.Where(x => x.Email.ToLower() == emailId.ToLower() && x.IsDelete == false).FirstOrDefault();
                if (user == null)
                {
                    throw new ValueNotFoundException("EmailId doesn't exist");
                }

                return(responseMessage = new ResponseMessageForgotPassword()
                {
                    Message = "Password sent via the email. Kindly check email.",
                    IsValid = true,
                    EmailId = user.Email,
                    FirstName = user.FirstName,
                    LastName = user.LastName,
                    Password = user.Password,
                    UserId = user.Id
                });
            } catch (Exception ex) {
                throw ex;
            }
        }
        public ResponseMessage ForgotPassword(string emailId)
        {
            ResponseMessage responseMessage = new ResponseMessage();

            try {
                ResponseMessageForgotPassword responseMessageForgotPassword = new ResponseMessageForgotPassword();
                responseMessageForgotPassword = _authRepository.ForgotPassword(emailId);
                if (!string.IsNullOrEmpty(responseMessageForgotPassword.Password))
                {
                    string newPass = Util.CreateRandomPassword(10);
                    // responseMessageForgotPassword.Password = Cryptography.Encrypt(_appSettings.SecretKeyPwd,Util.CreateRandomPassword(10));
                    ChangePassword chngePwd = new ChangePassword {
                        currentPassword = responseMessageForgotPassword.Password,
                        newPassword     = Cryptography.Encrypt(_appSettings.SecretKeyPwd, newPass),
                        userId          = responseMessageForgotPassword.UserId
                    };
                    _userRepository.ChangePassword(chngePwd);
                    Util.SendMail("Reset Password for L & T project", "<h1>New Password for the user : "******" " + responseMessageForgotPassword.LastName + " </h1><br /><p>Your Password is " + newPass + "</p>", responseMessageForgotPassword.EmailId, _appSettings.FromEmail, _appSettings.Password, _appSettings.Server, _appSettings.Port, _appSettings.Username);
                }
                responseMessage = new ResponseMessage()
                {
                    Message = "Password sent to the corresponding emailId"
                };
            } catch (Exception ex) {
                throw ex;
            }
            return(responseMessage);
        }