Example #1
0
        public ActionResult ResetPassword(UserProfile lc)
        {
            try
            {
                ForgotPassword fg = new ForgotPassword();
                fg.LoadByUserId(lc.User.Id);

                if (fg != null)
                {
                    if (DateTime.Now > fg.ExpirationDate)
                    {
                        ViewBag.Message = "Reset Link has Expired";
                        fg.Delete();
                        return(View(lc));
                    }
                    else
                    {
                        if (lc.User.Password == null)
                        {
                            ModelState.AddModelError(string.Empty, "Password is required");
                        }

                        if (lc.User.Password == null)
                        {
                            ModelState.AddModelError(string.Empty, "Password is required");
                        }

                        else if (lc.User.Password.Length < 6)
                        {
                            ModelState.AddModelError(string.Empty, "Password needs to be at least 6 characters");
                        }

                        else if (lc.User.Password.Length > 16)
                        {
                            ModelState.AddModelError(string.Empty, "Password needs to be less than 16 characters");
                        }

                        else if (lc.ConfirmPassword != lc.User.Password)
                        {
                            ModelState.AddModelError(string.Empty, "Passwords did not match");
                        }

                        if (!ModelState.IsValid)
                        {
                            return(View(lc));
                        }
                        else
                        {
                            if (lc.ConfirmPassword == lc.User.Password)
                            {
                                lc.User.ChangeForgottenPassword(lc.User.Password);

                                //DELETE ON SUCCESSFUL USE
                                fg.Delete();

                                return(RedirectToAction("ResetPasswordSuccess", "Login"));
                            }
                            else
                            {
                                ViewBag.Message = "Passwords need to match";
                                return(View(lc));
                            }
                        }
                    }
                }
                else
                {
                    ViewBag.Message = "Reset Link Doesn't Exist";
                    return(View(lc));
                }
            }
            catch
            {
                ViewBag.Message = "Error Occured While Attempted to Reset Password";
                return(View(lc));
            }
        }