public ActionResult ChangePassword([Bind(Include = "RID,AuthorityCode,RefugeeFName,RefugeeLName,Password,OldConfirmPassword,ConfirmNewPassword,NewPassword,Postcode,Email,Street,Suburb,State,Phone,Family_Description,Icon")] Refugee refugee) { newleavesdatabaseEntities1 db = new newleavesdatabaseEntities1(); if (refugee.OldConfirmPassword != null && refugee.NewPassword != null && refugee.NewPassword != null) { if (string.Compare(Crypto.Hash(refugee.OldConfirmPassword), refugee.Password) == 0) { if (ModelState.IsValid) { refugee.Password = refugee.NewPassword; refugee.Password = Crypto.Hash(refugee.Password); db.Entry(refugee).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("RefugeeDetailsAfter", new { code = User.Identity.Name })); } } else { ViewData["Non"] = "The old password didn't match"; return(View("ChangePassword", refugee)); } } else { ViewData["Non"] = "Please fill all the boxes before submit."; return(View("ChangePassword", refugee)); } return(View()); }
public bool IsEmailExist(string emailID) { using (newleavesdatabaseEntities1 dc = new newleavesdatabaseEntities1()) { var v = dc.Donor.Where(a => a.Email == emailID).FirstOrDefault(); return(v != null); } }
public ActionResult Registration([Bind(Exclude = "IsEmailVerified,ActivationCode")] Donor donor) { bool Status = false; string message = ""; // // Model Validation if (ModelState.IsValid) { #region //Email is already Exist var isExist = IsEmailExist(donor.Email); if (isExist) { ModelState.AddModelError("EmailExist", "Email already exists"); return(View(donor)); } #endregion #region Generate Activation Code donor.ActivationCode = Guid.NewGuid(); #endregion donor.Password = Crypto.Hash(donor.Password); donor.ConfirmPassword = Crypto.Hash(donor.ConfirmPassword); donor.IsEmailVerified = false; #region Save to Database using (newleavesdatabaseEntities1 dc = new newleavesdatabaseEntities1()) { dc.Donor.Add(donor); dc.SaveChanges(); //Send Email to User SendVerificationLinkEmail(donor.Email, donor.ActivationCode.ToString()); message = "Registration successfully done. Account activation link " + " has been sent to your email id:" + donor.Email; Status = true; } #endregion } else { message = "Invalid Request"; } ViewBag.Message = message; ViewBag.Status = Status; return(View(donor)); }
public ActionResult Login(RefugeeLogin login, string ReturnUrl = "") { string message = ""; using (newleavesdatabaseEntities1 dc = new newleavesdatabaseEntities1()) { var v = dc.Refugee.Where(a => a.AuthorityCode == login.AuthorityCode).FirstOrDefault(); if (v != null) { if (string.Compare(Crypto.Hash(login.Password), v.Password) == 0) { int timeout = login.RememberMe ? 525600 : 20; var ticket = new FormsAuthenticationTicket(login.AuthorityCode, login.RememberMe, timeout); string encrypted = FormsAuthentication.Encrypt(ticket); var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted); cookie.Expires = DateTime.Now.AddMinutes(timeout); cookie.HttpOnly = true; Response.Cookies.Add(cookie); if (Url.IsLocalUrl(ReturnUrl)) { return(Redirect(ReturnUrl)); } else { return(RedirectToAction("RefugeeIndex", "Home")); } } else { message = "Invalid credential provided"; } } else { message = "Invalid credential provided"; } } ViewBag.Message = message; return(View()); }
public ActionResult VerifyAccount(string id) { bool Status = false; using (newleavesdatabaseEntities1 dc = new newleavesdatabaseEntities1()) { dc.Configuration.ValidateOnSaveEnabled = false; // This line I have added here to avoid // Confirm password does not match issue on save changes var v = dc.Donor.Where(a => a.ActivationCode == new Guid(id)).FirstOrDefault(); if (v != null) { v.IsEmailVerified = true; dc.SaveChanges(); Status = true; } else { ViewBag.Message = "Invalid Request"; } } ViewBag.Status = Status; return(View()); }