예제 #1
0
        public static void LogoutDo()
        {
            var httpContext = System.Web.HttpContext.Current;

            if (UserLoggingOut != null)
            {
                UserLoggingOut();
            }

            UserTicketClient.RemoveCookie();

            httpContext.Session.Abandon();
        }
예제 #2
0
        public ActionResult Login(string username, string password, bool?rememberMe, string referrer)
        {
            // Basic parameter validation
            if (!username.HasText())
            {
                return(LoginError("username", AuthMessage.UserNameMustHaveAValue.NiceToString()));
            }

            if (string.IsNullOrEmpty(password))
            {
                return(LoginError("password", AuthMessage.PasswordMustHaveAValue.NiceToString()));
            }

            if (UserEntity.Current != null)
            {
                if (UserLoggingOut != null)
                {
                    UserLoggingOut();
                }
            }

            // Attempt to login
            UserEntity user = null;

            try
            {
                user = AuthLogic.Login(username, Security.EncodePassword(password));
            }
            catch (PasswordExpiredException)
            {
                TempData["message"]  = AuthMessage.ExpiredPasswordMessage.NiceToString();
                TempData["username"] = username;
                return(RedirectToAction("ChangePassword"));
            }
            catch (IncorrectUsernameException)
            {
                return(LoginError("username", MergeInvalidUsernameAndPasswordMessages ?
                                  AuthMessage.InvalidUsernameOrPassword.NiceToString() :
                                  AuthMessage.InvalidUsername.NiceToString()));
            }
            catch (IncorrectPasswordException)
            {
                return(LoginError("password", MergeInvalidUsernameAndPasswordMessages ?
                                  AuthMessage.InvalidUsernameOrPassword.NiceToString() :
                                  AuthMessage.InvalidPassword.NiceToString()));
            }

            if (user == null)
            {
                throw new Exception(AuthMessage.ExpectedUserLogged.NiceToString());
            }

            OnUserPreLogin(this, user);

            AddUserSession(user);

            if (rememberMe == true)
            {
                UserTicketClient.SaveCookie();
            }


            TempData["Message"] = AuthLogic.OnLoginMessage();


            return(this.RedirectHttpOrAjax(UserLoggedRedirect(this)));
        }