Пример #1
0
        public ActionResult Logout(string back)
        {
            var info = new CancellableLoginInfo {
                UserName = SNCR.User.Current.Username
            };

            LoginExtender.OnLoggingOut(info);

            FormsAuthentication.SignOut();

            if (!info.Cancel)
            {
                Logger.WriteAudit(AuditEvent.Logout, new Dictionary <string, object> {
                    { "UserName", SNCR.User.Current.Username }, { "ClientAddress", Request.ServerVariables["REMOTE_ADDR"] }
                });
                LoginExtender.OnLoggedOut(new LoginInfo {
                    UserName = SNCR.User.Current.Username
                });
            }

            Session.Clear();

            back = string.IsNullOrEmpty(back) ? "/" : HttpUtility.UrlDecode(back);

            return(this.Redirect(back));
        }
Пример #2
0
        /// <summary>
        /// Logs out the current user.
        /// </summary>
        /// <param name="ultimateLogout">Whether this should be an ultimate logout. If set to True, the user will be logged out from all clients.</param>
        public static void Logout(bool ultimateLogout = false)
        {
            var user = User.Current;
            var info = new CancellableLoginInfo {
                UserName = user.Username
            };

            LoginExtender.OnLoggingOut(info);

            if (info.Cancel)
            {
                return;
            }

            FormsAuthentication.SignOut();

            AccessTokenVault.DeleteTokensByUser(user.Id);

            SnLog.WriteAudit(AuditEvent.Logout,
                             new Dictionary <string, object>
            {
                { "UserName", user.Username },
                { "ClientAddress", RepositoryTools.GetClientIpAddress() }
            });

            LoginExtender.OnLoggedOut(new LoginInfo {
                UserName = user.Username
            });

            if (HttpContext.Current != null)
            {
                if (HttpContext.Current.Session != null)
                {
                    HttpContext.Current.Session.Abandon();
                }

                // remove session cookie
                var sessionCookie = new HttpCookie(GetSessionIdCookieName(), string.Empty)
                {
                    Expires = DateTime.UtcNow.AddDays(-1)
                };

                HttpContext.Current.Response.Cookies.Add(sessionCookie);

                // in case of ultimate logout saves the time on user
                if (ultimateLogout || Configuration.Security.DefaultUltimateLogout)
                {
                    using (new SystemAccount())
                    {
                        if (user is User userNode)
                        {
                            userNode.LastLoggedOut = DateTime.UtcNow;
                            userNode.Save(SavingMode.KeepVersion);
                        }
                    }
                }
            }
        }
Пример #3
0
        //protected void Login_Authenticate(object sender, AuthenticateEventArgs e)
        //{
        //    e.Authenticated = true;
        //}

        protected void LoginStatus_LoggingOut(object sender, LoginCancelEventArgs e)
        {
            var info = new CancellableLoginInfo {
                UserName = User.Current.Username
            };

            LoginExtender.OnLoggingOut(info);
            e.Cancel = info.Cancel;
            _message = info.Message;
        }
Пример #4
0
        public static void Logout()
        {
            var info = new CancellableLoginInfo {
                UserName = User.Current.Username
            };

            LoginExtender.OnLoggingOut(info);

            if (info.Cancel)
            {
                return;
            }

            FormsAuthentication.SignOut();

            SnLog.WriteAudit(AuditEvent.Logout,
                             new Dictionary <string, object>
            {
                { "UserName", User.Current.Username },
                { "ClientAddress", RepositoryTools.GetClientIpAddress() }
            });

            LoginExtender.OnLoggedOut(new LoginInfo {
                UserName = User.Current.Username
            });

            if (HttpContext.Current != null)
            {
                if (HttpContext.Current.Session != null)
                {
                    HttpContext.Current.Session.Abandon();
                }

                // remove session cookie
                var sessionCookie = new HttpCookie(GetSessionIdCookieName(), string.Empty)
                {
                    Expires = DateTime.UtcNow.AddDays(-1)
                };

                HttpContext.Current.Response.Cookies.Add(sessionCookie);
            }
        }