/// <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 updateUserLastActivityMsg = new UpdateUserLastActivity.Message
                    {
                        UserId           = CurrentUser.Id,
                        LastActivityDate = RockDateTime.Now,
                        IsOnline         = false
                    };
                    updateUserLastActivityMsg.Send();

                    Authorization.SignOut();
                }

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

                pnlDeleted.Visible = true;
            }
            else
            {
                ShowCode();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Returns the <see cref="Rock.Model.UserLogin"/> of the user who is currently logged in, and updates their last activity date if userIsOnline=true
        /// </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.PersonTokenService personTokenService = new Model.PersonTokenService(rockContext);
                    Rock.Model.PersonToken        personToken        = personTokenService.GetByImpersonationToken(userName.Substring(8));
                    if (personToken?.PersonAlias?.Person != null)
                    {
                        return(personToken.PersonAlias.Person.GetImpersonatedUser());
                    }
                }
                else
                {
                    var       userLoginService = new UserLoginService(rockContext);
                    UserLogin user             = userLoginService.GetByUserName(userName);

                    if (user != null && userIsOnline)
                    {
                        // Save last activity date
                        var message = new UpdateUserLastActivity.Message
                        {
                            UserId           = user.Id,
                            LastActivityDate = RockDateTime.Now,
                        };

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

                            message.Send();
                        }
                        else
                        {
                            message.IsOnline = false;
                            message.Send();

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

                    return(user);
                }
            }

            return(null);
        }
Beispiel #3
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
            {
                if (CurrentUser != null)
                {
                    var updateUserLastActivityMsg = new UpdateUserLastActivity.Message
                    {
                        UserId           = CurrentUser.Id,
                        LastActivityDate = RockDateTime.Now,
                        IsOnline         = false
                    };
                    updateUserLastActivityMsg.Send();
                }

                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();
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Logs out the person.
        /// </summary>
        private void LogoutPerson()
        {
            var currentPerson = CurrentPerson;

            if (currentPerson != null)
            {
                if (CurrentUser != null)
                {
                    var updateUserLastActivityMsg = new UpdateUserLastActivity.Message
                    {
                        UserId           = CurrentUser.Id,
                        LastActivityDate = RockDateTime.Now,
                        IsOnline         = false
                    };
                    updateUserLastActivityMsg.Send();
                }

                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;
        }
Beispiel #5
0
        /// <summary>
        /// NOTE: This does much more then is sounds like! It returns the <see cref="Rock.Model.UserLogin"/> of the user who is currently logged in,
        /// but it also updates their last activity date, and will sign them out if they are not confirmed or are locked out.
        /// </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.IsNullOrWhiteSpace())
            {
                return(null);
            }

            if (userName.StartsWith("rckipid="))
            {
                Rock.Model.PersonTokenService personTokenService = new Model.PersonTokenService(rockContext);
                Rock.Model.PersonToken        personToken        = personTokenService.GetByImpersonationToken(userName.Substring(8));
                if (personToken?.PersonAlias?.Person != null)
                {
                    return(personToken.PersonAlias.Person.GetImpersonatedUser());
                }
            }
            else
            {
                var       userLoginService = new UserLoginService(rockContext);
                UserLogin user             = userLoginService.GetByUserName(userName);

                if (user != null && userIsOnline)
                {
                    // Save last activity date
                    var message = new UpdateUserLastActivity.Message
                    {
                        UserId           = user.Id,
                        LastActivityDate = RockDateTime.Now,
                    };

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

                        message.SendIfNeeded();
                    }
                    else
                    {
                        // Even though we are in the userIsOnline == true condition,
                        // The user is either not confirmed or is locked out, so we'll mark them
                        // as offline and sign them out.

                        message.IsOnline = false;
                        message.SendIfNeeded();

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

                return(user);
            }

            return(null);
        }