Example #1
0
        public virtual ActionResult Login(LogonModel model)
        {
            Contract.Requires(model != null, "The passed model should never be null");

            // If both user name empty, redirect to home page. Supports mobile behavior
            if (string.IsNullOrWhiteSpace(model.UserName) || string.IsNullOrWhiteSpace(model.Password))
            {
                this.AddStatusMessage("Login cancelled");
                return(RedirectToAction(MVC_DcmsMobile.Home.Index()));
            }

            try
            {
                bool b = MembershipService.ValidateUser(model.UserName, model.Password);
                if (b)
                {
                    FormsService.SignIn(model.UserName, false);
                    AddStatusMessage(string.Format("Logged in as {0}", model.UserName));
                    if (string.IsNullOrEmpty(model.ReturnUrl))
                    {
                        return(RedirectToAction(MVC_DcmsMobile.Home.Index()));
                    }
                    else
                    {
                        return(Redirect(model.ReturnUrl));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Invalid username/password. Please try again.");
                    // Empty model forces restart of login
                    return(View(this.Views.Index, new LogonModel()));
                }
            }
            catch (MembershipPasswordException)
            {
                var cpmodel = new ChangeExpiredPasswordModel
                {
                    UserName  = model.UserName,
                    ReturnUrl = model.ReturnUrl,
                    //Password = model.Password
                };
                this.TempData[OLD_PASSWORD] = model.Password;
                ModelState.AddModelError("", "Your password has expired. Please change it now.");
                return(View(this.Views.ChangeExpiredPassword, cpmodel));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(View(this.Views.Index, model));
            }
        }
Example #2
0
        public virtual ActionResult ChangeExpiredPassword(ChangeExpiredPasswordModel model)
        {
            if (string.IsNullOrWhiteSpace(model.NewPassword) && string.IsNullOrWhiteSpace(model.ConfirmPassword))
            {
                // Password not entered. Just navigate to home page.
                return RedirectToAction(MVC_DcmsMobile.Home.Index());
            }
            if (!ModelState.IsValid)
            {
                // The passwords do not match. Ask for new password again.
                return View(this.Views.ChangeExpiredPassword, model);
            }

            try
            {
                var oldPassword = this.TempData[OLD_PASSWORD] as string;
                if (!string.IsNullOrWhiteSpace(oldPassword) && MembershipService.ChangePassword(model.UserName,
                    oldPassword, model.NewPassword))
                {
                    // Password has successfully change. Authenticate the user.
                    FormsService.SignIn(model.UserName, false);
                    this.AddStatusMessage(string.Format("Password for {0} successfully changed", model.UserName));
                    if (string.IsNullOrEmpty(model.ReturnUrl))
                    {
                        return RedirectToAction(MVC_DcmsMobile.Home.Index());
                    }
                    else
                    {
                        return Redirect(model.ReturnUrl);
                    }
                }
                else
                {
                    // The only possible reason is that the old password did not match. Apologize and request login again.
                    this.ModelState.AddModelError("", "Old password was not correct. Please try logging in again.");
                    //return RedirectToAction("Index", new
                    //{
                    //    ReturnUrl = model.ReturnUrl
                    //});
                    return RedirectToAction(MVC_DcmsMobile.Logon.Index(model.ReturnUrl));
                }
            }
            catch (Exception ex)
            {
                // We will need the old password after next post
                this.TempData.Keep(OLD_PASSWORD);
                this.ModelState.AddModelError("", ex.Message);
                return View(this.Views.ChangeExpiredPassword, model);
            }
        }
Example #3
0
        public virtual ActionResult ChangeExpiredPassword(ChangeExpiredPasswordModel model)
        {
            if (string.IsNullOrWhiteSpace(model.NewPassword) && string.IsNullOrWhiteSpace(model.ConfirmPassword))
            {
                // Password not entered. Just navigate to home page.
                return(RedirectToAction(MVC_DcmsMobile.Home.Index()));
            }
            if (!ModelState.IsValid)
            {
                // The passwords do not match. Ask for new password again.
                return(View(this.Views.ChangeExpiredPassword, model));
            }

            try
            {
                var oldPassword = this.TempData[OLD_PASSWORD] as string;
                if (!string.IsNullOrWhiteSpace(oldPassword) && MembershipService.ChangePassword(model.UserName,
                                                                                                oldPassword, model.NewPassword))
                {
                    // Password has successfully change. Authenticate the user.
                    FormsService.SignIn(model.UserName, false);
                    this.AddStatusMessage(string.Format("Password for {0} successfully changed", model.UserName));
                    if (string.IsNullOrEmpty(model.ReturnUrl))
                    {
                        return(RedirectToAction(MVC_DcmsMobile.Home.Index()));
                    }
                    else
                    {
                        return(Redirect(model.ReturnUrl));
                    }
                }
                else
                {
                    // The only possible reason is that the old password did not match. Apologize and request login again.
                    this.ModelState.AddModelError("", "Old password was not correct. Please try logging in again.");
                    //return RedirectToAction("Index", new
                    //{
                    //    ReturnUrl = model.ReturnUrl
                    //});
                    return(RedirectToAction(MVC_DcmsMobile.Logon.Index(model.ReturnUrl)));
                }
            }
            catch (Exception ex)
            {
                // We will need the old password after next post
                this.TempData.Keep(OLD_PASSWORD);
                this.ModelState.AddModelError("", ex.Message);
                return(View(this.Views.ChangeExpiredPassword, model));
            }
        }
Example #4
0
        public virtual ActionResult Login(LogonModel model)
        {
            Contract.Requires(model != null, "The passed model should never be null");

            // If both user name empty, redirect to home page. Supports mobile behavior
            if (string.IsNullOrWhiteSpace(model.UserName) || string.IsNullOrWhiteSpace(model.Password))
            {
                this.AddStatusMessage("Login cancelled");
                return RedirectToAction(MVC_DcmsMobile.Home.Index());
            }

            try
            {
                bool b = MembershipService.ValidateUser(model.UserName, model.Password);
                if (b)
                {
                    FormsService.SignIn(model.UserName, false);
                    AddStatusMessage(string.Format("Logged in as {0}", model.UserName));
                    if (string.IsNullOrEmpty(model.ReturnUrl))
                    {
                        return RedirectToAction(MVC_DcmsMobile.Home.Index());
                    }
                    else
                    {
                        return Redirect(model.ReturnUrl);
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Invalid username/password. Please try again.");
                    // Empty model forces restart of login
                    return View(this.Views.Index, new LogonModel());
                }
            }
            catch (MembershipPasswordException)
            {
                var cpmodel = new ChangeExpiredPasswordModel
                {
                    UserName = model.UserName,
                    ReturnUrl = model.ReturnUrl,
                    //Password = model.Password
                };
                this.TempData[OLD_PASSWORD] = model.Password;
                ModelState.AddModelError("", "Your password has expired. Please change it now.");
                return View(this.Views.ChangeExpiredPassword, cpmodel);
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                return View(this.Views.Index, model);
            }
        }