Exemplo n.º 1
0
        protected void LoginControll_LoggedIn(object sender, EventArgs e)
        {
            var targetUrl = GetPostLoginUrl();
            var userName  = ((Login)sender).UserName;

            if (this._ssoEnabled)
            {
                this.GetCookie().Value = CryptoApi.Crypt(userName, "sensenet60beta1", "SenseNetContentRepository");
            }

            if (OnUserLoggedIn != null)
            {
                OnUserLoggedIn(sender, e);
            }

            Logger.WriteAudit(AuditEvent.LoginSuccessful, new Dictionary <string, object> {
                { "UserName", userName }, { "ClientAddress", Request.ServerVariables["REMOTE_ADDR"] }
            });

            LoginExtender.OnLoggedIn(new LoginInfo {
                UserName = userName
            });

            HttpContext.Current.Response.Redirect(targetUrl);
        }
Exemplo n.º 2
0
        public static object Login(Content content, string username, string password)
        {
            if (string.IsNullOrEmpty(username))
            {
                Logout();
                throw new OData.ODataException(OData.ODataExceptionCode.Forbidden);
            }

            if (Membership.ValidateUser(username, password))
            {
                // we need to work with the full username that contains the domain: SetAuthCookie expects that
                if (!username.Contains("\\"))
                {
                    username = IdentityManagement.DefaultDomain + "\\" + username;
                }

                if (User.Current.IsAuthenticated)
                {
                    // if this is the user that is already logged in, return with a success code
                    if (string.CompareOrdinal(User.Current.Username, username) == 0)
                    {
                        using (new SystemAccount())
                        {
                            FormsAuthentication.SetAuthCookie(username, true);
                            return(Content.Create(User.Load(username) as User));
                        }
                    }

                    // logged in as a different user: we have to log out first
                    Logout();
                }

                var info = new CancellableLoginInfo {
                    UserName = username
                };
                LoginExtender.OnLoggingIn(info);
                if (info.Cancel)
                {
                    throw new OData.ODataException(OData.ODataExceptionCode.Forbidden);
                }

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

                LoginExtender.OnLoggedIn(new LoginInfo {
                    UserName = username
                });


                using (new SystemAccount())
                {
                    FormsAuthentication.SetAuthCookie(username, true);
                    return(Content.Create(User.Load(username) as User));
                }
            }

            throw new OData.ODataException(OData.ODataExceptionCode.Forbidden);
        }