示例#1
0
    protected void Login()
    {
        this.IsAuthorized = true;
        LogUtility.LogInfo("checking if membership user is logged in and authenticated");
        MembershipUser u = Membership.GetUser();

        if (u != null)
        {
            this.IsAuthorized = u.IsApproved;
            _loggedInProfile  = new WTS_User(u.ProviderUserKey.ToString());
            _loggedInProfile.Load_GUID();

            //Always include the default theme
            UserManagement.AddDefaultTheme(Page, _loggedInProfile);

            //11626 - 2:
            LoadUserPrefs();

            //SetAnimations
            _useAnimations = _loggedInProfile.EnableAnimations.ToString();

            #region Debug Logging
            if (WTSConfiguration.DebugMode)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine();
                sb.AppendLine("ALL available roles: ");
                string[] availRoles = Roles.GetAllRoles();
                if (availRoles.Length > 0)
                {
                    foreach (string r in availRoles)
                    {
                        sb.AppendLine("    " + r);
                    }
                }

                sb.AppendLine();
                sb.AppendLine();

                sb.AppendFormat("User {0} is logged in and is {1}approved.", u.UserName, u.IsApproved ? "" : "NOT ");
                sb.AppendLine();
                sb.AppendLine(string.Format("Organization = {0}", _loggedInProfile.Organization));
                sb.AppendLine();
                string[] roles = Roles.GetRolesForUser();
                if (roles.Length > 0)
                {
                    sb.AppendLine("User is in roles:  ");
                    foreach (string r in roles)
                    {
                        sb.AppendLine("    " + r);
                    }
                }
                else
                {
                    sb.AppendLine("User has no roles assigned.");
                }
                LogUtility.LogInfo(sb.ToString());
            }
            #endregion
        }
        else
        {
            if (WTSConfiguration.DebugMode)
            {
                LogUtility.LogInfo("User was not found or is not logged in.");
            }
        }

        this.UserName    = HttpContext.Current.User.Identity.Name;
        this.UserId      = _loggedInProfile.ID;
        this.IsUserAdmin = UserManagement.UserIsUserAdmin(username: UserName);
        this.SessionID   = HttpContext.Current.Session.SessionID;

        lblUser.Text = "Welcome to WTS -";

        //Load Filters
        LoadFilters();

        //11626 - 2:
        LoadUserPrefs();

        //Load menu and module options for the logged in user
        LoadAvailableOptions(u);
        LoadCustomUserFilters();
    }