public ActionResult ForgotPassword(string Email)
        {
            bool status = false;

            using (ParentsRegsEntities parentsReg = new ParentsRegsEntities())
            {
                var account = parentsReg.ParentsLogins.Where(a => a.Email == Email).FirstOrDefault();
                if (account != null)
                {
                    //Send email for reset password
                    string resetCode = Guid.NewGuid().ToString();
                    SendVerificationLinkEmail(account.Email, resetCode, "ResetPassword");
                    account.ResetPasswordCode = resetCode;

                    //Avoid confirm password not match issue, as we had added a confirm password property
                    parentsReg.Configuration.ValidateOnSaveEnabled = false;
                    parentsReg.SaveChanges();
                    ViewBag.Message = "Reset password link has been sent to your email id";
                    ModelState.Clear();
                }
                else
                {
                    ViewBag.ErrorMessage = "Sorry! account not found";
                }
            }
            return(View());
        }
        public ActionResult Register([Bind(Exclude = "IsEmailVerified,ActivationCode")] ParentsLogin parentsLogin)
        {
            bool   Status  = false;
            string message = "";

            if (ModelState.IsValid)
            {
                // Email is already Exist
                var isExist = IsEmailExist(parentsLogin.Email);
                if (isExist)
                {
                    ModelState.AddModelError("EmailExist", "Email already exist");
                    return(View(parentsLogin));
                }

                // Generate Activation Code
                parentsLogin.ActivationCode = Guid.NewGuid();

                // Password Hashing
                parentsLogin.Password        = Crypto.Hash(parentsLogin.Password);
                parentsLogin.ConfirmPassword = Crypto.Hash(parentsLogin.ConfirmPassword);

                parentsLogin.IsEmailVerified = false;

                // Save to Database
                using (ParentsRegsEntities parentsReg = new ParentsRegsEntities())
                {
                    Parents parents = new Parents();
                    parents.Id = parentsLogin.Id;
                    if (parents.checkId())
                    {
                        parentsReg.ParentsLogins.Add(parentsLogin);
                        parentsReg.SaveChanges();

                        // Send Email to User
                        SendVerificationLinkEmail(parentsLogin.Email, parentsLogin.ActivationCode.ToString());
                        message = "Registration successfully done. Account activation link " +
                                  " has been sent to your email id:" + parentsLogin.Email;
                        Status = true;
                    }
                    else
                    {
                        message = "Invalid id";
                    }
                }
            }
            else
            {
                message = "Invalid Request";
            }

            ViewBag.Message = message;
            ViewBag.Status  = Status;
            return(View());
        }
        public ActionResult VerifyAccount(string id)
        {
            bool Status = false;

            using (ParentsRegsEntities parentsReg = new ParentsRegsEntities())
            {
                parentsReg.Configuration.ValidateOnSaveEnabled = false; // This line I have added here to avoid
                                                                        // Confirm password does not match issue on save changes
                var v = parentsReg.ParentsLogins.Where(a => a.ActivationCode == new Guid(id)).FirstOrDefault();
                if (v != null)
                {
                    v.IsEmailVerified = true;
                    parentsReg.SaveChanges();
                    Status = true;
                }
                else
                {
                    ViewBag.Message = "Invalid Request";
                }
            }
            ViewBag.Status = Status;
            return(View());
        }
 public ActionResult ResetPassword(ResetPassword reset)
 {
     if (ModelState.IsValid)
     {
         using (ParentsRegsEntities parentsReg = new ParentsRegsEntities())
         {
             var user = parentsReg.ParentsLogins.Where(a => a.ResetPasswordCode == reset.ResetCode).FirstOrDefault();
             if (user != null)
             {
                 user.Password          = Crypto.Hash(reset.NewPassword);
                 user.ResetPasswordCode = "";
                 parentsReg.Configuration.ValidateOnSaveEnabled = false;
                 parentsReg.SaveChanges();
                 ViewBag.message = "New password updated successfully";
             }
         }
         ModelState.Clear();
     }
     else
     {
         ViewBag.Errormessage = "Something invalid!";
     }
     return(View(reset));
 }