GetCurrentUser() public static method

Gets the current user, if any.
public static GetCurrentUser ( ) : UserInfo
return UserInfo
Ejemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Page.Title = Properties.Messages.ProfileTitle + " - " + Settings.WikiTitle;

            if (SessionFacade.LoginKey == null)
            {
                UrlTools.Redirect(UrlTools.BuildUrl("Login.aspx?Redirect=Profile.aspx"));
            }

            currentUser   = SessionFacade.GetCurrentUser();
            currentGroups = SessionFacade.GetCurrentGroupNames();

            if (currentUser.Username == "admin")
            {
                // Admin only has language preferences, stored in a cookie
                UrlTools.Redirect("Language.aspx");
                return;
            }

            if (!Page.IsPostBack)
            {
                bool usersDataSupported      = !currentUser.Provider.UsersDataReadOnly;
                bool accountDetailsSupported = !currentUser.Provider.UserAccountsReadOnly;

                pnlUserData.Visible  = usersDataSupported;
                pnlAccount.Visible   = accountDetailsSupported;
                pnlNoChanges.Visible = !usersDataSupported && !accountDetailsSupported;

                languageSelector.LoadLanguages();

                string name = string.IsNullOrEmpty(currentUser.DisplayName) ? currentUser.Username : currentUser.DisplayName;
                lblUsername.Text    = name;
                txtDisplayName.Text = currentUser.DisplayName;
                txtEmail1.Text      = currentUser.Email;
                var groups = SessionFacade.GetCurrentGroups().ToList();
                lblGroupsList.Text = string.Join(", ", groups.Select(g => g.Name));

                //if (groups.Count == 1 && groups[0].Name == "Anonymous")
                {
                    // bug groupes
                    var user       = SessionFacade.GetCurrentUser();
                    var userName   = SessionFacade.GetCurrentUsername();
                    var firstGroup = user?.Groups?.FirstOrDefault();
                    var findUser   = Users.FindUser(userName);

                    lblGroupsList.Text += " - DEBUG - " +
                                          $"Session ID : {Session.SessionID} - userName = {userName} - user.Username = {user.Username} - " +
                                          $"user.Groups.Count = {user.Groups?.Count()} - user.Groups[0] = {firstGroup} - " +
                                          $"findUser.Groups.Count = {findUser?.Groups?.Count()} - findUser.Groups[0] = {findUser?.Groups?.FirstOrDefault()} - ";
                }


                LoadNotificationsStatus();
                LoadLanguageAndTimezoneSettings();

                rxvDisplayName.ValidationExpression = Settings.DisplayNameRegex;
                rxvEmail1.ValidationExpression      = Settings.EmailRegex;
                rxvPassword1.ValidationExpression   = Settings.PasswordRegex;
            }
        }
Ejemplo n.º 2
0
        protected void btnSend_Click(object sender, EventArgs e)
        {
            lblSendResult.Text     = "";
            lblSendResult.CssClass = "";

            Page.Validate();
            if (!Page.IsValid)
            {
                return;
            }

            UserInfo loggedUser = SessionFacade.GetCurrentUser();

            Log.LogEntry("Sending Email to " + currentUser.Username, EntryType.General, loggedUser.Username);
            EmailTools.AsyncSendEmail(currentUser.Email,
                                      "\"" + Users.GetDisplayName(loggedUser) + "\" <" + Settings.SenderEmail + ">",
                                      txtSubject.Text,
                                      Users.GetDisplayName(loggedUser) + " sent you this message from " + Settings.WikiTitle + ". To reply, please go to " + Settings.MainUrl + "User.aspx?Username="******"&Subject=" + Tools.UrlEncode("Re: " + txtSubject.Text) + "\nPlease do not reply to this Email.\n\n------------\n\n" + txtBody.Text,
                                      false);
            lblSendResult.Text     = Properties.Messages.MessageSent;
            lblSendResult.CssClass = "resultok";

            txtSubject.Text = "";
            txtBody.Text    = "";
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Loads the language from the current user's data.
        /// </summary>
        /// <returns>The language, or <c>null</c>.</returns>
        public static string LoadLanguageFromUserData( )
        {
            UserInfo currentUser = SessionFacade.GetCurrentUser( );

            if (currentUser != null)
            {
                string culture = Users.GetUserData(currentUser, "Culture");
                return(culture);
            }
            return(null);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Loads the timezone from the current user's data.
        /// </summary>
        /// <param name="wiki">The wiki.</param>
        /// <returns>The timezone, or <c>null</c>.</returns>
        public static string LoadTimezoneFromUserData(string wiki)
        {
            UserInfo currentUser = SessionFacade.GetCurrentUser(wiki);

            if (currentUser != null)
            {
                return(Users.GetUserData(currentUser, "Timezone"));
            }

            return(null);
        }
Ejemplo n.º 5
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            // Sueetie Modified - Relogin
            if (Page.User.Identity.IsAuthenticated && SessionFacade.GetCurrentUser() == null)
            {
                MembershipUser _user = Membership.GetUser();

                var user = Users.FindUser(_user.UserName);

                // Sueetie Modified 01/03/2010 - Not creating users unless explicitly added in Control Panel
                if (user != null)
                {
                    string loginKey = ConfigurationManager.AppSettings["SUEETIE.WikiLoginKey"].ToString();
                    SetLoginCookie(user.Username, loginKey, DateTime.Now.AddYears(1));
                    //if (!IsInUsersGroup(user.Username))
                    //	Users.SetUserMembership(user, new string[] { "Users" });
                    SetupSession(user);
                    Log.LogEntry("User " + user.Username + " auto-logged in through Sueetie entry", EntryType.General, "SUEETIE");
                }
            }

            // Bypass compression if the current request was made by Anthem.NET
            if (HttpContext.Current.Request["Anthem_CallBack"] != null)
            {
                return;
            }

            // Request might not be initialized -> use HttpContext
            string ua = HttpContext.Current.Request.UserAgent != null?HttpContext.Current.Request.UserAgent.ToLowerInvariant() : "";

            if (Settings.EnableHttpCompression && !ua.Contains("konqueror") && !ua.Contains("safari"))
            {
                if (Request.Headers["Accept-encoding"] != null && Request.Headers["Accept-encoding"].Contains("gzip"))
                {
                    Response.Filter = new GZipStream(Response.Filter, CompressionMode.Compress, true);
                    Response.AppendHeader("Content-encoding", "gzip");
                    Response.AppendHeader("Vary", "Content-encoding");
                    //Response.Write("HTTP Compression Enabled (GZip)");
                }
                else if (Request.Headers["Accept-encoding"] != null && Request.Headers["Accept-encoding"].Contains("deflate"))
                {
                    Response.Filter = new DeflateStream(Response.Filter, CompressionMode.Compress, true);
                    Response.AppendHeader("Content-encoding", "deflate");
                    Response.AppendHeader("Vary", "Content-encoding");
                    //Response.Write("HTTP Compression Enabled (Deflate)");
                }
            }
        }
Ejemplo n.º 6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            currentWiki = DetectWiki();

            Page.Title = Properties.Messages.ProfileTitle + " - " + Settings.GetWikiTitle(currentWiki);

            if (SessionFacade.LoginKey == null)
            {
                UrlTools.Redirect(UrlTools.BuildUrl(currentWiki, "Login.aspx?Redirect=Profile.aspx"));
            }

            currentUser   = SessionFacade.GetCurrentUser(currentWiki);
            currentGroups = SessionFacade.GetCurrentGroupNames(currentWiki);

            if (currentUser.Username == "admin")
            {
                // Admin only has language preferences, stored in a cookie
                UrlTools.Redirect("Language.aspx");
                return;
            }

            if (!Page.IsPostBack)
            {
                bool usersDataSupported      = !currentUser.Provider.UsersDataReadOnly;
                bool accountDetailsSupported = !currentUser.Provider.UserAccountsReadOnly;

                pnlUserData.Visible  = usersDataSupported;
                pnlAccount.Visible   = accountDetailsSupported;
                pnlNoChanges.Visible = !usersDataSupported && !accountDetailsSupported;

                languageSelector.LoadLanguages();
                languageSelector.LoadTimezones();

                string name = string.IsNullOrEmpty(currentUser.DisplayName) ? currentUser.Username : currentUser.DisplayName;
                lblUsername.Text    = name;
                txtDisplayName.Text = currentUser.DisplayName;
                txtEmail1.Text      = currentUser.Email;
                lblGroupsList.Text  = string.Join(", ", Array.ConvertAll(SessionFacade.GetCurrentGroups(currentWiki), delegate(UserGroup g) { return(g.Name); }));

                LoadNotificationsStatus();
                LoadLanguageAndTimezoneSettings();

                rxvDisplayName.ValidationExpression = GlobalSettings.DisplayNameRegex;
                rxvEmail1.ValidationExpression      = GlobalSettings.EmailRegex;
                rxvPassword1.ValidationExpression   = GlobalSettings.PasswordRegex;
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Saves language and timezone preferences into the current user's data.
        /// </summary>
        /// <param name="culture">The culture.</param>
        /// <param name="timezone">The timezone.</param>
        /// <returns><c>true</c> if the data is stored, <c>false</c> otherwise.</returns>
        public static bool SavePreferencesInUserData(string culture, int timezone)
        {
            UserInfo user = SessionFacade.GetCurrentUser( );

            if (user != null && !user.Provider.UsersDataReadOnly)
            {
                Users.SetUserData(user, "Culture", culture);
                Users.SetUserData(user, "Timezone", timezone.ToString(CultureInfo.InvariantCulture));

                return(true);
            }
            if (user == null)
            {
                Log.LogEntry("Attempt to save user data when no user has logged in", EntryType.Warning, Log.SystemUsername);
            }
            return(false);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Sets the email notification button.
        /// </summary>
        private void SetupEmailNotification()
        {
            if (SessionFacade.LoginKey != null && SessionFacade.CurrentUsername != "admin")
            {
                bool pageChanges        = false;
                bool discussionMessages = false;

                UserInfo user = SessionFacade.GetCurrentUser();
                if (user != null && user.Provider.UsersDataReadOnly)
                {
                    btnEmailNotification.Visible = false;
                    return;
                }

                if (user != null)
                {
                    Users.GetEmailNotification(user, currentPage, out pageChanges, out discussionMessages);
                }

                bool active = false;
                if (discussMode)
                {
                    active = discussionMessages;
                }
                else
                {
                    active = pageChanges;
                }

                if (active)
                {
                    btnEmailNotification.CssClass = "activenotification" + (discussMode ? " discuss" : "");
                    btnEmailNotification.ToolTip  = Properties.Messages.EmailNotificationsAreActive;
                }
                else
                {
                    btnEmailNotification.CssClass = "inactivenotification" + (discussMode ? " discuss" : "");
                    btnEmailNotification.ToolTip  = Properties.Messages.ClickToEnableEmailNotifications;
                }
            }
            else
            {
                btnEmailNotification.Visible = false;
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Loads the timezone from the current user's data.
        /// </summary>
        /// <returns>The timezone, or <c>null</c>.</returns>
        public static int?LoadTimezoneFromUserData( )
        {
            UserInfo currentUser = SessionFacade.GetCurrentUser( );

            if (currentUser != null)
            {
                string timezone = Users.GetUserData(currentUser, "Timezone");
                if (timezone != null)
                {
                    int res = 0;
                    if (int.TryParse(timezone, NumberStyles.Any, CultureInfo.InvariantCulture, out res))
                    {
                        return(res);
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 10
0
        protected void btnEmailNotification_Click(object sender, EventArgs e)
        {
            bool pageChanges        = false;
            bool discussionMessages = false;

            UserInfo user = SessionFacade.GetCurrentUser();

            if (user != null)
            {
                Users.GetEmailNotification(user, currentPage, out pageChanges, out discussionMessages);
            }

            if (discussMode)
            {
                Users.SetEmailNotification(user, currentPage, pageChanges, !discussionMessages);
            }
            else
            {
                Users.SetEmailNotification(user, currentPage, !pageChanges, discussionMessages);
            }

            SetupEmailNotification();
        }
Ejemplo n.º 11
0
        protected void cvOldPassword_ServerValidate(object source, ServerValidateEventArgs args)
        {
            UserInfo user = SessionFacade.GetCurrentUser(currentWiki);

            args.IsValid = user.Provider.TestAccount(user, txtOldPassword.Text);
        }