예제 #1
0
        public ActionResult Index()
        {
            try
            {
                LoadSession();
                // But if the identity is not authenticated then the user didn't even log in.
                var appState = Session[Trips4.DRCOGApp.SessionIdentifier] as ApplicationState;
                bool noUser = (
                    (appState == null) ||
                    (appState.CurrentUser == null) ||
                    (appState.CurrentUser.profile == null) ||
                    (appState.CurrentUser.profile.PersonGUID == Guid.Empty));
                string timeoutMessage = string.Empty;
                if (noUser && User.Identity.IsAuthenticated)
                {
                    timeoutMessage = "Your session has timed out. Please log in again to proceed.";
                }
                Logger.Debug("Clearing user information - logging out.");
                FormsAuthentication.SignOut();
                Session.Abandon();

                // Clear invalid login text
                var viewModel = new LoginViewModel
                {
                    Message = Request["message"] ?? TempData["message"] as String ?? timeoutMessage,
                    ReturnUrl = Request["ReturnUrl"] ?? String.Empty
                };
                viewModel.RefreshAssemblyVersion();

                // N.B. Adding a header requires Integrated Pipeline mode, so either IIS or IIS Express is
                // required to run this (Cassini won't do it).
                // Adding this header allows the global ajax handler to detect the login page without
                // examining the HTML.
                Response.Headers.Add("LoginPage", "This is it.");
                return View(viewModel);
            }
            catch (Exception ex)
            {
                Logger.ErrorException("failure during login", ex);
                var viewModel = new ErrorViewModel("DRCOG TIP Application is unable to handle your request at this time.", "This error has been logged.", ex, this.ControllerName, "Index - Get");
                return View("CustomError", viewModel);
            }
        }
예제 #2
0
        public ActionResult Index(LoginViewModel viewModel, string returnUrl)
        {
            LogOnModel model = viewModel.LogOnModel;
            try
            {
                LoadSession();

                if (GuestUser(model))
                {
                    return base.SetAuthCookie(model, returnUrl);
                }

                viewModel.RefreshAssemblyVersion();
                if (ModelState.IsValid)
                {
                    this.LoadSession();

                    Person person = new Person(model.UserName);

                    // First try to authenicate through service
                    if (Membership.ValidateUser(model.UserName, model.Password))
                    {
                        return base.SetAuthCookie(model, returnUrl);
                    }
                    else
                    {
                        ModelState.AddModelError("", "The user name or password provided is incorrect.");

                        string exceptionMessage;
                        bool isApproved = UserService.GetUserApproval(model.UserName);
                        if (isApproved)
                            exceptionMessage = "The user name or password provided is incorrect.";
                        else
                            exceptionMessage = "Your account has not been activated. Please click on the link in your verification email or use the link above to resend the verification email to this email address.";
                        //ModelState.AddModelError("", exceptionMessage);
                        viewModel.Message = exceptionMessage;
                    }
                }
                else
                {
                    //pass back the Error
                    viewModel.Message = "User name and password must be entered.";
                }

                return View(viewModel);
            }
            catch (SqlException sqlex)
            {
                //Send to Error Message on Login view
                viewModel.Message = "A database has occurred while attempting to log you into the system.";
                return View(viewModel);
            }
            catch (Exception ex)
            {
                ErrorViewModel error = new ErrorViewModel(ex + "An unexpected error has occurred while attempting to log you into the system.", "This error has been logged.", ex, this.ControllerName, "Index - Post");
                return View("CustomError", error);
            }
        }