Example #1
0
 protected void OnUserSignIn(UserSignInEventArgs e)
 {
     if (UserSignIn != null)
     {
         UserSignIn(this, e);
     }
 }
Example #2
0
        //private void HookupSignInEventHandlers()
        //{
        //    // this is a hook so that custom code can be fired when pages are created
        //    // implement a PageCreatedEventHandlerPovider and put a config file for it in
        //    // /Setup/ProviderConfig/pagecreatedeventhandlers
        //    try
        //    {
        //        foreach (UserSignInHandlerProvider handler in UserSignInHandlerProviderManager.Providers)
        //        {
        //            this.UserSignIn += handler.UserSignInEventHandler;
        //        }
        //    }
        //    catch (TypeInitializationException ex)
        //    {
        //        log.Error(ex);
        //    }

        //}

        //public event UserSignInEventHandler UserSignIn;

        protected void OnUserSignIn(UserSignInEventArgs e)
        {
            foreach (UserSignInHandlerProvider handler in UserSignInHandlerProviderManager.Providers)
            {
                handler.UserSignInEventHandler(null, e);
            }

            //if (UserSignIn != null)
            //{
            //    UserSignIn(this, e);
            //}
        }
Example #3
0
        protected void SiteLogin_LoggedIn(object sender, EventArgs e)
        {
            if (siteSettings == null)
            {
                return;
            }

            SiteUser siteUser = new SiteUser(siteSettings, this.UserName);

            if (WebConfigSettings.UseFoldersInsteadOfHostnamesForMultipleSites)
            {
                string cookieName = "siteguid" + siteSettings.SiteGuid;
                CookieHelper.SetCookie(cookieName, siteUser.UserGuid.ToString(), this.RememberMeSet);
            }

            if (siteUser.UserId > -1 && siteSettings.AllowUserSkins && siteUser.Skin.Length > 0)
            {
                SiteUtils.SetSkinCookie(siteUser);
            }

            if (siteUser.UserGuid == Guid.Empty)
            {
                return;
            }

            // track user ip address
            try
            {
                UserLocation userLocation = new UserLocation(siteUser.UserGuid, SiteUtils.GetIP4Address());
                userLocation.SiteGuid = siteSettings.SiteGuid;
                userLocation.Hostname = Page.Request.UserHostName;
                userLocation.Save();
            }
            catch (Exception ex)
            {
                log.Error(SiteUtils.GetIP4Address(), ex);
            }


            UserSignInEventArgs u = new UserSignInEventArgs(siteUser);

            OnUserSignIn(u);
        }
Example #4
0
        private void SignInUser(SiteUser user, bool isNewUser)
        {
            if (
                (siteSettings.UseSecureRegistration) &&
                (user.RegisterConfirmGuid != Guid.Empty)
                )
            {
                Notification.SendRegistrationConfirmationLink(
                    SiteUtils.GetSmtpSettings(),
                    ResourceHelper.GetMessageTemplate("RegisterConfirmEmailMessage.config"),
                    siteSettings.DefaultEmailFromAddress,
                    siteSettings.DefaultFromEmailAlias,
                    user.Email,
                    siteSettings.SiteName,
                    SiteRoot + "/ConfirmRegistration.aspx?ticket=" +
                    user.RegisterConfirmGuid.ToString());


                log.Info("User " + user.Name + " tried to login but email address is not confirmed.");

                lblError.Text = Resource.RegistrationRequiresEmailConfirmationMessage;
                litInfoNeededMessage.Visible         = false;
                pnlRequiredProfileProperties.Visible = false;
                btnCreateUser.Visible = false;

                return;
            }

            if (user.IsLockedOut)
            {
                log.Info("User " + user.Name + " tried to login but account is locked.");

                lblError.Text = Resource.LoginAccountLockedMessage;

                return;
            }

            if ((siteSettings.RequireApprovalBeforeLogin) && (!user.ApprovedForLogin))
            {
                log.Info("User " + user.Name + " tried to login but account is not approved yet.");

                lblError.Text = Resource.LoginNotApprovedMessage;

                return;
            }


            if (siteSettings.UseEmailForLogin)
            {
                FormsAuthentication.SetAuthCookie(user.Email, true);
            }
            else
            {
                FormsAuthentication.SetAuthCookie(user.LoginName, true);
            }

            if (WebConfigSettings.UseFolderBasedMultiTenants)
            {
                string cookieName = "siteguid" + siteSettings.SiteGuid;
                CookieHelper.SetCookie(cookieName, user.UserGuid.ToString(), true);
            }

            if (user.UserId > -1 && siteSettings.AllowUserSkins && user.Skin.Length > 0)
            {
                SiteUtils.SetSkinCookie(user);
            }

            user.UpdateLastLoginTime();

            // track user ip address
            UserLocation userLocation = new UserLocation(user.UserGuid, SiteUtils.GetIP4Address());

            userLocation.SiteGuid = siteSettings.SiteGuid;
            userLocation.Hostname = Request.UserHostName;
            userLocation.Save();

            UserSignInEventArgs u = new UserSignInEventArgs(user);

            OnUserSignIn(u);

            if (CookieHelper.CookieExists(returnUrlCookieName))
            {
                returnUrl = CookieHelper.GetCookieValue(returnUrlCookieName);
                CookieHelper.ExpireCookie(returnUrlCookieName);
            }
            string requestedReturnUrl = SiteUtils.GetReturnUrlParam(Page, SiteRoot);

            returnUrl = requestedReturnUrl;

            if (isNewUser)
            {
                if (WebConfigSettings.PageToRedirectToAfterRegistration.Length > 0)
                {
                    returnUrl = SiteRoot + WebConfigSettings.PageToRedirectToAfterRegistration;
                }
            }

            if (String.IsNullOrEmpty(returnUrl) ||
                returnUrl.Contains("AccessDenied") ||
                returnUrl.Contains("Login") ||
                returnUrl.Contains("SignIn") ||
                returnUrl.Contains("ConfirmRegistration.aspx") ||
                returnUrl.Contains("OpenIdRpxHandler.aspx") ||
                returnUrl.Contains("RecoverPassword.aspx") ||
                returnUrl.Contains("Register")
                )
            {
                returnUrl = SiteRoot;
            }

            if (returnUrl.Length > 0)
            {
                if (SiteUtils.IsSecureRequest())
                {
                    if (returnUrl.StartsWith("http:"))
                    {
                        returnUrl = returnUrl.Replace("http:", "https:");
                    }
                }

                WebUtils.SetupRedirect(this, returnUrl);
                return;
            }

            if (SiteUtils.IsSecureRequest())
            {
                if (SiteRoot.StartsWith("http:"))
                {
                    WebUtils.SetupRedirect(this, SiteRoot.Replace("http:", "https:"));
                    return;
                }
            }


            WebUtils.SetupRedirect(this, SiteRoot);
            return;
        }
        private void DoExistingUserLogic(Guid userGuid)
        {
            // user found so login if allowed
            SiteUser user = new SiteUser(siteSettings, userGuid);

            bool canLogin = true;

            if (
                (siteSettings.UseSecureRegistration) &&
                (user.RegisterConfirmGuid != Guid.Empty)
                )
            {
                Notification.SendRegistrationConfirmationLink(
                    SiteUtils.GetSmtpSettings(),
                    ResourceHelper.GetMessageTemplate("RegisterConfirmEmailMessage.config"),
                    siteSettings.DefaultEmailFromAddress,
                    siteSettings.DefaultFromEmailAlias,
                    user.Email,
                    siteSettings.SiteName,
                    WebUtils.GetSiteRoot() + "/ConfirmRegistration.aspx?ticket=" +
                    user.RegisterConfirmGuid.ToString());


                log.Info("User " + user.Name + " tried to login but email address is not confirmed.");

                canLogin = false;
            }

            if (user.IsLockedOut)
            {
                log.Info("User " + user.Name + " tried to login but account is locked.");

                canLogin = false;
            }

            if ((siteSettings.RequireApprovalBeforeLogin) && (!user.ApprovedForLogin))
            {
                log.Info("User " + user.Name + " tried to login but account is not approved yet.");
                canLogin = false;
            }

            if (canLogin)
            {
                if (siteSettings.UseEmailForLogin)
                {
                    FormsAuthentication.SetAuthCookie(
                        user.Email, persistCookie);
                }
                else
                {
                    FormsAuthentication.SetAuthCookie(
                        user.LoginName, persistCookie);
                }

                if (user.LiveMessengerDelegationToken.Length > 0)
                {
                    WindowsLiveMessenger m     = new WindowsLiveMessenger(windowsLive);
                    ConsentToken         token = m.DecodeToken(user.LiveMessengerDelegationToken);
                    token = m.RefreshConsent(token);
                    if (token != null)
                    {
                        CookieHelper.SetCookie(consentTokenCookie, token.Token);
                        CookieHelper.SetCookie(delegationTokenCookie, token.DelegationToken);
                    }
                }

                if (WebConfigSettings.UseFolderBasedMultiTenants)
                {
                    string cookieName = "siteguid" + siteSettings.SiteGuid;
                    CookieHelper.SetCookie(cookieName, user.UserGuid.ToString(), persistCookie);
                }

                if (user.UserId > -1 && siteSettings.AllowUserSkins && user.Skin.Length > 0)
                {
                    SiteUtils.SetSkinCookie(user);
                }


                user.UpdateLastLoginTime();

                // track user ip address
                UserLocation userLocation = new UserLocation(user.UserGuid, SiteUtils.GetIP4Address());
                userLocation.SiteGuid = siteSettings.SiteGuid;
                userLocation.Hostname = Page.Request.UserHostName;
                userLocation.Save();

                string redirectUrl = GetRedirectPath();
                CookieHelper.ExpireCookie(returnUrlCookieName);

                UserSignInEventArgs u = new UserSignInEventArgs(user);
                OnUserSignIn(u);

                //WebUtils.SetupRedirect(this, redirectUrl);
                Response.Redirect(redirectUrl);
                return;
            }
            else
            {
                // redirect to login
                // need to make login page show
                // reason for failure
                //WebUtils.SetupRedirect(this, LoginPage);
                Response.Redirect(LoginPage);
            }
        }
        private void DoExistingUserLogic(Guid userGuid)
        {
            // user found so login if allowed
            SiteUser user = new SiteUser(siteSettings, userGuid);

            if (
                (siteSettings.UseSecureRegistration) &&
                (user.RegisterConfirmGuid != Guid.Empty)
                )
            {
                Notification.SendRegistrationConfirmationLink(
                    SiteUtils.GetSmtpSettings(),
                    ResourceHelper.GetMessageTemplate("RegisterConfirmEmailMessage.config"),
                    siteSettings.DefaultEmailFromAddress,
                    siteSettings.DefaultFromEmailAlias,
                    user.Email,
                    siteSettings.SiteName,
                    WebUtils.GetSiteRoot() + "/ConfirmRegistration.aspx?ticket=" +
                    user.RegisterConfirmGuid.ToString());

                lblError.Text = Resource.LoginUnconfirmedEmailMessage;
                log.Info("User " + user.Name + " tried to login but email address is not confirmed.");

                return;
            }

            if (user.IsLockedOut)
            {
                lblError.Text = Resource.LoginAccountLockedMessage;
                log.Info("User " + user.Name + " tried to login but account is locked.");

                return;
            }


            if (siteSettings.UseEmailForLogin)
            {
                FormsAuthentication.SetAuthCookie(
                    user.Email, true);
            }
            else
            {
                FormsAuthentication.SetAuthCookie(
                    user.LoginName, true);
            }

            if (WebConfigSettings.UseFoldersInsteadOfHostnamesForMultipleSites)
            {
                string cookieName = "siteguid" + siteSettings.SiteGuid;
                CookieHelper.SetCookie(cookieName, user.UserGuid.ToString(), true);
            }

            user.UpdateLastLoginTime();

            // track user ip address
            UserLocation userLocation = new UserLocation(user.UserGuid, SiteUtils.GetIP4Address());

            userLocation.SiteGuid = siteSettings.SiteGuid;
            userLocation.Hostname = Page.Request.UserHostName;
            userLocation.Save();

            string redirectUrl = GetRedirectPath();

            CookieHelper.ExpireCookie(returnUrlCookieName);

            UserSignInEventArgs u = new UserSignInEventArgs(user);

            OnUserSignIn(u);

            WebUtils.SetupRedirect(this, redirectUrl);
            return;
        }
Example #7
0
 //private void HookupSignInEventHandlers()
 //{
 //    // this is a hook so that custom code can be fired when pages are created
 //    // implement a PageCreatedEventHandlerPovider and put a config file for it in
 //    // /Setup/ProviderConfig/pagecreatedeventhandlers
 //    try
 //    {
 //        foreach (UserSignInHandlerProvider handler in UserSignInHandlerProviderManager.Providers)
 //        {
 //            this.UserSignIn += handler.UserSignInEventHandler;
 //        }
 //    }
 //    catch (TypeInitializationException ex)
 //    {
 //        log.Error(ex);
 //    }
 //}
 //public event UserSignInEventHandler UserSignIn;
 protected void OnUserSignIn(UserSignInEventArgs e)
 {
     foreach (UserSignInHandlerProvider handler in UserSignInHandlerProviderManager.Providers)
     {
         handler.UserSignInEventHandler(null, e);
     }
     //if (UserSignIn != null)
     //{
     //    UserSignIn(this, e);
     //}
 }
Example #8
0
        protected void SiteLogin_LoggedIn(object sender, EventArgs e)
        {
            IUserBAL itemBAL = new UserBAL();
            User item = itemBAL.GetUserByLoginName(this.UserName.Trim());

            SiteUser siteUser = new SiteUser();
            siteUser.LoginName = item.UserID;
            siteUser.Name = item.UserName;
            siteUser.UserId = item.UserGuid;

            string cookieName = "siteguid" + SiteUtils.GetSiteId();
            CookieHelper.SetCookie(cookieName, siteUser.UserId.ToString(), this.RememberMeSet);

            if (siteUser.UserId == Guid.Empty)
                return;

            UserSignInEventArgs u = new UserSignInEventArgs(siteUser);
            OnUserSignIn(u);
        }