I have NullReferenceException error in forgotten password section. Where is my mistake and how can I fix it? Here are my codes:
my controller :
public ActionResult ForGotPasswordSent(ForGotModel forgetModel)
{
User user = _userService.GetUserByEmail(forgetModel.Email);
if (user.IsActive)
{
var objEmail = new EmailHelper();
Message msg = new Message();
msg.SuccessMessage = "You have sent the mail,Please verify that";
msg.IsSuccess = true;
string strBody = "Thanks for using the forgot password function.You need to set new password to your account, please click here to proceed";
bool result = objEmail.SendMail("noreply@xx.com", "xxtest@gmail.com", "", "Activate Your Account", strBody, true);
if (result)
return View("Activation", msg);
else
return View("Activation");
}
else
{
this.ModelState.AddModelError("", "You have to activate your account");
return View("Activation");
}
}
my User class:
public class User : IPrincipal
{
public int Id { get; set; }
[Required(ErrorMessage = "Kullanıcı adı girilmesi zorunludur.")]
[Display(Name = "Kullanıcı Adı")]
public string Username { get; set; }
[Required]
[DataType(DataType.EmailAddress)]
[Display(Name = "Email address")]
public string Email { get; set; }
[Required(ErrorMessage = "Password Required")]
public string Password { get; set; }
[DataType(DataType.Password)]
[Display(Name = "Confirm password")]
[Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
public string ConfirmPassword { get; set; }
public bool IsActive { get; set; }
public bool IsAdmin { get; set; }
public bool IsDeleted { get; set; }
public DateTime? CreatedDate { get; set; }
public DateTime? ModifiedDate { get; set; }
my ForgotModel
public class ForGotModel
{
[Required]
[Display(Name = "Email")]
public string Email { get; set; }
}
_userService.GetUserByEmail method:
public User GetUserByEmail(string email)
{
var user = _userRepository.Get(x => x.Email == email);
return user;
}