Esempio n. 1
0
        /// <summary>
        /// Logouts the person.
        /// </summary>
        private void LogoutPerson()
        {
            var currentPerson = CurrentPerson;

            if (currentPerson != null)
            {
                if (CurrentUser != null)
                {
                    var transaction = new Rock.Transactions.UserLastActivityTransaction();
                    transaction.UserId           = CurrentUser.Id;
                    transaction.LastActivityDate = RockDateTime.Now;
                    transaction.IsOnLine         = false;
                    Rock.Transactions.RockQueue.TransactionQueue.Enqueue(transaction);
                }

                Authorization.SignOut();

                if (!string.IsNullOrWhiteSpace(GetAttributeValue("RedirectPage")))
                {
                    NavigateToLinkedPage("RedirectPage");
                }
                else
                {
                    // display message
                    var message = GetAttributeValue("Message");

                    var mergeFields = new Dictionary <string, object>();
                    mergeFields.Add("CurrentPerson", currentPerson);

                    lOutput.Text = message.ResolveMergeFields(mergeFields);
                }
            }

            lbAdminLogout.Visible = false;
        }
        /// <summary>
        /// Shows the deleted.
        /// </summary>
        private void ShowDeleted()
        {
            RockContext      rockContext      = new RockContext();
            UserLoginService userLoginService = new UserLoginService(rockContext);
            UserLogin        user             = userLoginService.GetByConfirmationCode(this.ConfirmationCode);

            if (user != null)
            {
                if (CurrentUser != null && CurrentUser.UserName == user.UserName)
                {
                    var transaction = new Rock.Transactions.UserLastActivityTransaction();
                    transaction.UserId           = CurrentUser.Id;
                    transaction.LastActivityDate = RockDateTime.Now;
                    transaction.IsOnLine         = false;
                    Rock.Transactions.RockQueue.TransactionQueue.Enqueue(transaction);

                    Authorization.SignOut();
                }

                userLoginService.Delete(user);
                rockContext.SaveChanges();

                pnlDeleted.Visible = true;
            }
            else
            {
                ShowCode();
            }
        }
        /// <summary>
        /// Returns the <see cref="Rock.Model.UserLogin"/>
        /// </summary>
        /// <param name="userIsOnline">A <see cref="System.Boolean"/> value that returns the logged in user if <c>true</c>; otherwise can return the impersonated user</param>
        /// <returns>The current <see cref="Rock.Model.UserLogin"/></returns>
        public static UserLogin GetCurrentUser(bool userIsOnline)
        {
            string userName = UserLogin.GetCurrentUserName();

            if (userName != string.Empty)
            {
                if (userName.StartsWith("rckipid="))
                {
                    Rock.Model.PersonService personService      = new Model.PersonService();
                    Rock.Model.Person        impersonatedPerson = personService.GetByEncryptedKey(userName.Substring(8));
                    if (impersonatedPerson != null)
                    {
                        return(impersonatedPerson.ImpersonatedUser);
                    }
                }
                else
                {
                    var       userLoginService = new UserLoginService();
                    UserLogin user             = userLoginService.GetByUserName(userName);

                    if (user != null && userIsOnline)
                    {
                        // Save last activity date
                        var transaction = new Rock.Transactions.UserLastActivityTransaction();
                        transaction.UserId           = user.Id;
                        transaction.LastActivityDate = DateTime.Now;
                        Rock.Transactions.RockQueue.TransactionQueue.Enqueue(transaction);
                    }

                    return(user);
                }
            }

            return(null);
        }
Esempio n. 4
0
        /// <summary>
        /// Handles the Click event of the lbLoginLogout control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void lbLoginLogout_Click(object sender, EventArgs e)
        {
            string action = hfActionType.Value;

            if (action == LOG_IN)
            {
                var site = RockPage.Layout.Site;
                if (site.LoginPageId.HasValue)
                {
                    site.RedirectToLoginPage(true);
                }
                else
                {
                    FormsAuthentication.RedirectToLoginPage();
                }
            }
            else
            {
                var logoutPage = GetAttributeValue("LogoutPage");
                if (logoutPage.IsNotNullOrWhiteSpace())
                {
                    NavigateToLinkedPage("LogoutPage");
                    return;
                }


                if (CurrentUser != null)
                {
                    var transaction = new Rock.Transactions.UserLastActivityTransaction();
                    transaction.UserId           = CurrentUser.Id;
                    transaction.LastActivityDate = RockDateTime.Now;
                    transaction.IsOnLine         = false;
                    Rock.Transactions.RockQueue.TransactionQueue.Enqueue(transaction);
                }

                Authorization.SignOut();

                // After logging out check to see if an anonymous user is allowed to view the current page.  If so
                // redirect back to the current page, otherwise redirect to the site's default page
                var currentPage = Rock.Web.Cache.PageCache.Get(RockPage.PageId);
                if (currentPage != null && currentPage.IsAuthorized(Authorization.VIEW, null))
                {
                    string url = CurrentPageReference.BuildUrl(true);
                    Response.Redirect(url);
                    Context.ApplicationInstance.CompleteRequest();
                }
                else
                {
                    RockPage.Layout.Site.RedirectToDefaultPage();
                }
            }
        }
        /// <summary>
        /// Handles the Click event of the lbLoginLogout control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void lbLoginLogout_Click( object sender, EventArgs e )
        {
            string action = hfActionType.Value;
            if ( action == "Login" )
            {
                var site = RockPage.Layout.Site;
                if ( site.LoginPageId.HasValue )
                {
                    site.RedirectToLoginPage( true );
                }
                else
                {
                    FormsAuthentication.RedirectToLoginPage();
                }
            }
            else
            {
                if ( CurrentUser != null )
                {
                    var transaction = new Rock.Transactions.UserLastActivityTransaction();
                    transaction.UserId = CurrentUser.Id;
                    transaction.LastActivityDate = RockDateTime.Now;
                    transaction.IsOnLine = false;
                    Rock.Transactions.RockQueue.TransactionQueue.Enqueue( transaction );
                }

                FormsAuthentication.SignOut();

                // After logging out check to see if an anonymous user is allowed to view the current page.  If so
                // redirect back to the current page, otherwise redirect to the site's default page
                var currentPage = Rock.Web.Cache.PageCache.Read( RockPage.PageId );
                if ( currentPage != null && currentPage.IsAuthorized(Authorization.VIEW, null))
                {
                    Response.Redirect( CurrentPageReference.BuildUrl() );
                    Context.ApplicationInstance.CompleteRequest();
                }
                else
                {
                    RockPage.Layout.Site.RedirectToDefaultPage();
                }
            }
        }
        /// <summary>
        /// Handles the Click event of the lbLoginLogout control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void lbLoginLogout_Click( object sender, EventArgs e )
        {
            string action = LoginLogout.Text;
            if ( action == LOGIN_TEXT )
            {
                var site = RockPage.Layout.Site;
                if ( site.LoginPageId.HasValue )
                {
                    site.RedirectToLoginPage( true );
                }
                else
                {
                    FormsAuthentication.RedirectToLoginPage();
                }
            }
            else
            {
                if ( CurrentUser != null )
                {
                    var transaction = new Rock.Transactions.UserLastActivityTransaction();
                    transaction.UserId = CurrentUser.Id;
                    transaction.LastActivityDate = RockDateTime.Now;
                    transaction.IsOnLine = false;
                    Rock.Transactions.RockQueue.TransactionQueue.Enqueue( transaction );
                }

                FormsAuthentication.SignOut();

                // After logging out check to see if an anonymous user is allowed to view the current page.  If so
                // redirect back to the current page, otherwise redirect to the site's default page
                var currentPage = Rock.Web.Cache.PageCache.Read( RockPage.PageId );
                if ( currentPage != null && currentPage.IsAuthorized(Authorization.VIEW, null))
                {
                    Response.Redirect( CurrentPageReference.BuildUrl() );
                    Context.ApplicationInstance.CompleteRequest();
                }
                else
                {
                    RockPage.Layout.Site.RedirectToDefaultPage();
                }
            }
        }
        /// <summary>
        /// Returns the <see cref="Rock.Model.UserLogin"/>
        /// </summary>
        /// <param name="userIsOnline">A <see cref="System.Boolean"/> value that returns the logged in user if <c>true</c>; otherwise can return the impersonated user</param>
        /// <returns>The current <see cref="Rock.Model.UserLogin"/></returns>
        public static UserLogin GetCurrentUser(bool userIsOnline)
        {
            var rockContext = new RockContext();

            string userName = UserLogin.GetCurrentUserName();

            if (userName != string.Empty)
            {
                if (userName.StartsWith("rckipid="))
                {
                    Rock.Model.PersonService personService      = new Model.PersonService(rockContext);
                    Rock.Model.Person        impersonatedPerson = personService.GetByEncryptedKey(userName.Substring(8));
                    if (impersonatedPerson != null)
                    {
                        return(impersonatedPerson.GetImpersonatedUser());
                    }
                }
                else
                {
                    var       userLoginService = new UserLoginService(rockContext);
                    UserLogin user             = userLoginService.GetByUserName(userName);

                    if (user != null && userIsOnline)
                    {
                        // Save last activity date
                        var transaction = new Rock.Transactions.UserLastActivityTransaction();
                        transaction.UserId           = user.Id;
                        transaction.LastActivityDate = RockDateTime.Now;

                        if ((user.IsConfirmed ?? true) && !(user.IsLockedOut ?? false))
                        {
                            if (HttpContext.Current != null && HttpContext.Current.Session != null)
                            {
                                HttpContext.Current.Session["RockUserId"] = user.Id;
                            }

                            // see if there is already a LastActivitytransaction queued for this user, and just update its LastActivityDate instead of adding another to the queue
                            var userLastActivity = Rock.Transactions.RockQueue.TransactionQueue.ToArray().OfType <Rock.Transactions.UserLastActivityTransaction>()
                                                   .Where(a => a.UserId == transaction.UserId).FirstOrDefault();

                            if (userLastActivity != null)
                            {
                                userLastActivity.LastActivityDate = transaction.LastActivityDate;
                            }
                            else
                            {
                                Rock.Transactions.RockQueue.TransactionQueue.Enqueue(transaction);
                            }
                        }
                        else
                        {
                            transaction.IsOnLine = false;
                            Rock.Transactions.RockQueue.TransactionQueue.Enqueue(transaction);

                            FormsAuthentication.SignOut();
                            return(null);
                        }
                    }

                    return(user);
                }
            }

            return(null);
        }
        /// <summary>
        /// Shows the deleted.
        /// </summary>
        private void ShowDeleted()
        {
            RockContext rockContext = new RockContext();
            UserLoginService userLoginService = new UserLoginService( rockContext );
            UserLogin user = userLoginService.GetByConfirmationCode( this.ConfirmationCode );

            if ( user != null )
            {
                if ( CurrentUser != null && CurrentUser.UserName == user.UserName )
                {
                    var transaction = new Rock.Transactions.UserLastActivityTransaction();
                    transaction.UserId = CurrentUser.Id;
                    transaction.LastActivityDate = RockDateTime.Now;
                    transaction.IsOnLine = false;
                    Rock.Transactions.RockQueue.TransactionQueue.Enqueue( transaction );

                    FormsAuthentication.SignOut();
                }

                userLoginService.Delete( user );
                rockContext.SaveChanges();

                pnlDeleted.Visible = true;
            }
            else
            {
                ShowCode();
            }
        }
        /// <summary>
        /// Returns the <see cref="Rock.Model.UserLogin"/>
        /// </summary>
        /// <param name="userIsOnline">A <see cref="System.Boolean"/> value that returns the logged in user if <c>true</c>; otherwise can return the impersonated user</param>
        /// <returns>The current <see cref="Rock.Model.UserLogin"/></returns>
        public static UserLogin GetCurrentUser( bool userIsOnline )
        {
            var rockContext = new RockContext();

            string userName = UserLogin.GetCurrentUserName();
            if ( userName != string.Empty )
            {
                if ( userName.StartsWith( "rckipid=" ) )
                {
                    Rock.Model.PersonService personService = new Model.PersonService( rockContext );
                    Rock.Model.Person impersonatedPerson = personService.GetByEncryptedKey( userName.Substring( 8 ) );
                    if ( impersonatedPerson != null )
                        return impersonatedPerson.GetImpersonatedUser();
                }
                else
                {
                    var userLoginService = new UserLoginService( rockContext );
                    UserLogin user = userLoginService.GetByUserName( userName );

                    if ( user != null && userIsOnline )
                    {
                        // Save last activity date
                        var transaction = new Rock.Transactions.UserLastActivityTransaction();
                        transaction.UserId = user.Id;
                        transaction.LastActivityDate = RockDateTime.Now;

                        if ( ( user.IsConfirmed ?? true ) && !( user.IsLockedOut ?? false ) )
                        {
                            if ( HttpContext.Current != null && HttpContext.Current.Session != null )
                            {
                                if ( HttpContext.Current.Session["RockUserId"] != null )
                                {
                                    transaction.SessionUserId = (int)HttpContext.Current.Session["RockUserId"];
                                }
                                HttpContext.Current.Session["RockUserId"] = user.Id;
                            }

                            // see if there is already a LastActivitytransaction queued for this user, and just update its LastActivityDate instead of adding another to the queue
                            var userLastActivity = Rock.Transactions.RockQueue.TransactionQueue.ToArray().OfType<Rock.Transactions.UserLastActivityTransaction>()
                                .Where( a => a.UserId == transaction.UserId && a.SessionUserId == transaction.SessionUserId ).FirstOrDefault();

                            if ( userLastActivity != null )
                            {
                                userLastActivity.LastActivityDate = transaction.LastActivityDate;
                            }
                            else
                            {
                                Rock.Transactions.RockQueue.TransactionQueue.Enqueue( transaction );
                            }
                        }
                        else
                        {
                            transaction.IsOnLine = false;
                            Rock.Transactions.RockQueue.TransactionQueue.Enqueue( transaction );

                            FormsAuthentication.SignOut();
                            return null;
                        }
                    }

                    return user;
                }
            }

            return null;
        }
Esempio n. 10
0
        /// <summary>
        /// Logouts the person.
        /// </summary>
        private void LogoutPerson()
        {
            var currentPerson = CurrentPerson;

            if ( currentPerson != null )
            {
                if ( CurrentUser != null )
                {
                    var transaction = new Rock.Transactions.UserLastActivityTransaction();
                    transaction.UserId = CurrentUser.Id;
                    transaction.LastActivityDate = RockDateTime.Now;
                    transaction.IsOnLine = false;
                    Rock.Transactions.RockQueue.TransactionQueue.Enqueue( transaction );
                }

                FormsAuthentication.SignOut();

                if ( !string.IsNullOrWhiteSpace( GetAttributeValue( "RedirectPage" ) ) )
                {
                    NavigateToLinkedPage( "RedirectPage" );
                }
                else
                {
                    // display message
                    var message = GetAttributeValue( "Message" );

                    var mergeFields = new Dictionary<string, object>();
                    mergeFields.Add( "CurrentPerson", currentPerson );

                    lOutput.Text = message.ResolveMergeFields( mergeFields );
                }
            }

            lbAdminLogout.Visible = false;
        }
Esempio n. 11
0
        /// <summary>
        /// Returns the <see cref="Rock.Model.UserLogin"/>
        /// </summary>
        /// <param name="userIsOnline">A <see cref="System.Boolean"/> value that returns the logged in user if <c>true</c>; otherwise can return the impersonated user</param>
        /// <returns>The current <see cref="Rock.Model.UserLogin"/></returns>
        public static UserLogin GetCurrentUser( bool userIsOnline )
        {
            string userName = UserLogin.GetCurrentUserName();
            if ( userName != string.Empty )
            {
                if ( userName.StartsWith( "rckipid=" ) )
                {
                    Rock.Model.PersonService personService = new Model.PersonService();
                    Rock.Model.Person impersonatedPerson = personService.GetByEncryptedKey( userName.Substring( 8 ) );
                    if ( impersonatedPerson != null )
                        return impersonatedPerson.ImpersonatedUser;
                }
                else
                {
                    var userLoginService = new UserLoginService();
                    UserLogin user = userLoginService.GetByUserName( userName );

                    if ( user != null && userIsOnline )
                    {
                        // Save last activity date
                        var transaction = new Rock.Transactions.UserLastActivityTransaction();
                        transaction.UserId = user.Id;
                        transaction.LastActivityDate = DateTime.Now;
                        Rock.Transactions.RockQueue.TransactionQueue.Enqueue( transaction );
                    }

                    return user;
                }
            }

            return null;
        }