/// <summary> /// Logins the or create user. /// </summary> /// <param name="request"> /// The request. /// </param> /// <param name="parameters"> /// The parameters. /// </param> /// <param name="message"> /// The message. /// </param> /// <returns> /// Returns if Login was successful or not /// </returns> public bool LoginOrCreateUser(HttpRequest request, string parameters, out string message) { var oAuth = new OAuthTwitter { ConsumerKey = Config.TwitterConsumerKey, ConsumerSecret = Config.TwitterConsumerSecret }; // Get the access token and secret. oAuth.AccessTokenGet(request["oauth_token"], request["oauth_verifier"]); if (oAuth.TokenSecret.Length > 0) { var tweetAPI = new TweetAPI(oAuth); var twitterUser = tweetAPI.GetUser(); if (twitterUser.UserId > 0) { // Check if user exists var checkUser = BoardContext.Current.Get <MembershipProvider>().GetUser(twitterUser.UserName, false); // Login user if exists if (checkUser == null) { return(CreateTwitterUser(twitterUser, oAuth, out message)); } // LOGIN Existing User var yafUser = Utils.UserProfile.GetProfile(checkUser.UserName); var yafUserData = new CombinedUserDataHelper(checkUser); if (yafUser.Twitter.IsNotSet() && yafUser.TwitterId.IsNotSet()) { // user with the same name exists but account is not connected, exit! message = BoardContext.Current.Get <ILocalization>().GetText("LOGIN", "SSO_TWITTER_FAILED"); return(false); } if (yafUser.Twitter.Equals(twitterUser.UserName) && yafUser.TwitterId.Equals(twitterUser.UserId.ToString())) { LoginTwitterSuccess(false, oAuth, yafUserData.UserID, checkUser); message = string.Empty; return(true); } message = BoardContext.Current.Get <ILocalization>().GetText("LOGIN", "SSO_TWITTERID_NOTMATCH"); return(false); // User does not exist create new user } } message = BoardContext.Current.Get <ILocalization>().GetText("LOGIN", "SSO_TWITTER_FAILED"); return(false); }
/// <summary> /// Logins the or create user. /// </summary> /// <param name="request"> /// The request. /// </param> /// <param name="parameters"> /// The parameters. /// </param> /// <param name="message"> /// The message. /// </param> /// <returns> /// Returns if Login was successful or not /// </returns> public bool LoginOrCreateUser(HttpRequest request, string parameters, out string message) { var oAuth = new OAuthTwitter { ConsumerKey = Config.TwitterConsumerKey, ConsumerSecret = Config.TwitterConsumerSecret }; // Get the access token and secret. oAuth.AccessTokenGet(request["oauth_token"], request["oauth_verifier"]); if (oAuth.TokenSecret.Length > 0) { var tweetAPI = new TweetAPI(oAuth); var twitterUser = tweetAPI.GetUser(); if (twitterUser.UserId > 0) { // Check if user exists var checkUser = YafContext.Current.Get<MembershipProvider>().GetUser(twitterUser.UserName, false); // Login user if exists if (checkUser == null) { return CreateTwitterUser(twitterUser, oAuth, out message); } // LOGIN Existing User var yafUser = YafUserProfile.GetProfile(checkUser.UserName); var yafUserData = new CombinedUserDataHelper(checkUser); if (yafUser.Twitter.IsNotSet() && yafUser.TwitterId.IsNotSet()) { // user with the same name exists but account is not connected, exit! message = YafContext.Current.Get<ILocalization>().GetText("LOGIN", "SSO_TWITTER_FAILED"); return false; } if (yafUser.Twitter.Equals(twitterUser.UserName) && yafUser.TwitterId.Equals(twitterUser.UserId.ToString())) { LoginTwitterSuccess(false, oAuth, yafUserData.UserID, checkUser); message = string.Empty; return true; } message = YafContext.Current.Get<ILocalization>().GetText("LOGIN", "SSO_TWITTERID_NOTMATCH"); return false; // User does not exist create new user } } message = YafContext.Current.Get<ILocalization>().GetText("LOGIN", "SSO_TWITTER_FAILED"); return false; }
/// <summary> /// Logins the or create user. /// </summary> /// <param name="request">The request.</param> /// <param name="parameters">The access token.</param> /// <param name="message">The message.</param> /// <returns>Returns if Login was successful or not</returns> public bool LoginOrCreateUser(HttpRequest request, string parameters, out string message) { if (!YafContext.Current.Get<YafBoardSettings>().AllowSingleSignOn) { message = YafContext.Current.Get<ILocalization>().GetText("LOGIN", "SSO_DEACTIVATED"); return false; } var googleUser = this.GetGoogleUser(request, parameters); var userGender = 0; if (googleUser.Gender.IsSet()) { switch (googleUser.Gender) { case "male": userGender = 1; break; case "female": userGender = 2; break; } } // Check if user exists var userName = YafContext.Current.Get<MembershipProvider>().GetUserNameByEmail(googleUser.Email); if (userName.IsNotSet()) { // Create User if not exists?! return this.CreateGoogleUser(googleUser, userGender, out message); } var yafUser = YafUserProfile.GetProfile(userName); var yafUserData = new CombinedUserDataHelper(YafContext.Current.Get<MembershipProvider>().GetUser(userName, true)); if (!yafUser.GoogleId.Equals(googleUser.UserID)) { message = YafContext.Current.Get<ILocalization>().GetText("LOGIN", "SSO_GOOGLE_FAILED"); return false; } YafSingleSignOnUser.LoginSuccess(AuthService.google, userName, yafUserData.UserID, true); message = string.Empty; return true; }
/// <summary> /// The setup user profile info. /// </summary> /// <param name="userID"> /// The user id. /// </param> /// <param name="user"> /// The user. /// </param> /// <param name="userData"> /// The user data. /// </param> /// <param name="userDisplayName"> /// The user display name. /// </param> private void SetupUserProfileInfo( int userID, [NotNull] MembershipUser user, [NotNull] CombinedUserDataHelper userData, [NotNull] string userDisplayName) { this.UserLabel1.UserID = userData.UserID; if (this.PageContext.IsAdmin && userDisplayName != user.UserName) { this.Name.Text = this.HtmlEncode("{0} ({1})".FormatWith(userDisplayName, user.UserName)); } else { this.Name.Text = this.HtmlEncode(userDisplayName); } this.Joined.Text = "{0}".FormatWith(this.Get <YafDateTime>().FormatDateLong(Convert.ToDateTime(userData.Joined))); // vzrus: Show last visit only to admins if user is hidden if (!this.PageContext.IsAdmin && Convert.ToBoolean(userData.DBRow["IsActiveExcluded"])) { this.LastVisit.Text = this.GetText("COMMON", "HIDDEN"); this.LastVisit.Visible = true; } else { this.LastVisitDateTime.DateTime = userData.LastVisit; this.LastVisitDateTime.Visible = true; } if (this.User != null && !string.IsNullOrEmpty(userData.RankName)) { this.RankTR.Visible = true; this.Rank.Text = this.HtmlEncode(this.Get <YafBadWordReplace>().Replace(userData.RankName)); } if (this.User != null && !string.IsNullOrEmpty(userData.Profile.Location)) { this.LocationTR.Visible = true; this.Location.Text = this.HtmlEncode(this.Get <YafBadWordReplace>().Replace(userData.Profile.Location)); } if (this.User != null && !string.IsNullOrEmpty(userData.Profile.Location)) { this.LocationTR.Visible = true; this.Location.Text = this.HtmlEncode(this.Get <YafBadWordReplace>().Replace(userData.Profile.Location)); } if (this.User != null && !string.IsNullOrEmpty(userData.Profile.RealName)) { this.RealNameTR.Visible = true; this.RealName.InnerHtml = this.HtmlEncode(this.Get <YafBadWordReplace>().Replace(userData.Profile.RealName)); } if (this.User != null && !string.IsNullOrEmpty(userData.Profile.Interests)) { this.InterestsTR.Visible = true; this.Interests.InnerHtml = this.HtmlEncode(this.Get <YafBadWordReplace>().Replace(userData.Profile.Interests)); } if (this.User != null && !string.IsNullOrEmpty(userData.Profile.Occupation)) { this.OccupationTR.Visible = true; this.Occupation.InnerHtml = this.HtmlEncode(this.Get <YafBadWordReplace>().Replace(userData.Profile.Occupation)); } // Handled in localization. this.Gender.InnerText = this.GetText("GENDER" + userData.Profile.Gender); this.ThanksFrom.Text = DB.user_getthanks_from(userData.DBRow["userID"], this.PageContext.PageUserID).ToString(); int[] thanksToArray = DB.user_getthanks_to(userData.DBRow["userID"], this.PageContext.PageUserID); this.ThanksToTimes.Text = thanksToArray[0].ToString(); this.ThanksToPosts.Text = thanksToArray[1].ToString(); this.OnlineStatusImage1.UserID = userID; this.OnlineStatusImage1.Visible = this.PageContext.BoardSettings.ShowUserOnlineStatus; if (this.User != null && !string.IsNullOrEmpty(userData.Profile.XMPP)) { this.XmppTR.Visible = true; this.lblxmpp.Text = this.HtmlEncode(this.Get <YafBadWordReplace>().Replace(userData.Profile.XMPP)); } if (this.User != null && !string.IsNullOrEmpty(userData.Profile.AIM)) { this.AimTR.Visible = true; this.lblaim.Text = this.HtmlEncode(this.Get <YafBadWordReplace>().Replace(userData.Profile.AIM)); } if (this.User != null && !string.IsNullOrEmpty(userData.Profile.ICQ)) { this.IcqTR.Visible = true; this.lblicq.Text = this.HtmlEncode(this.Get <YafBadWordReplace>().Replace(userData.Profile.ICQ)); } if (this.User != null && !string.IsNullOrEmpty(userData.Profile.MSN)) { this.MsnTR.Visible = true; this.lblmsn.Text = this.HtmlEncode(this.Get <YafBadWordReplace>().Replace(userData.Profile.MSN)); } if (this.User != null && !string.IsNullOrEmpty(userData.Profile.Skype)) { this.SkypeTR.Visible = true; this.lblskype.Text = this.HtmlEncode(this.Get <YafBadWordReplace>().Replace(userData.Profile.Skype)); } if (this.User != null && !string.IsNullOrEmpty(userData.Profile.YIM)) { this.YimTR.Visible = true; this.lblyim.Text = this.HtmlEncode(this.Get <YafBadWordReplace>().Replace(userData.Profile.YIM)); } if (this.User != null && userData.Profile.Birthday != DateTime.MinValue) { this.BirthdayTR.Visible = true; this.Birthday.Text = this.Get <YafDateTime>().FormatDateLong( userData.Profile.Birthday.Date); // .Add(-this.Get<YafDateTime>().TimeOffset)); } else { this.BirthdayTR.Visible = false; } }
/// <summary> /// The save_ click. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> private void Save_Click([NotNull] object sender, [NotNull] EventArgs e) { var body = this._sig.Text; // find forbidden BBcodes in signature var detectedBbCode = this.Get <IFormatMessage>().BBCodeForbiddenDetector(body, this._allowedBbcodes, ','); if (this._allowedBbcodes.IndexOf("ALL") < 0) { if (detectedBbCode.IsSet() && detectedBbCode != "ALL") { this.PageContext.AddLoadMessage( this.GetTextFormatted("SIGNATURE_BBCODE_WRONG", detectedBbCode)); return; } if (detectedBbCode.IsSet() && detectedBbCode == "ALL") { this.PageContext.AddLoadMessage(this.GetText("BBCODE_FORBIDDEN")); return; } } // find forbidden HTMLTags in signature if (!this.PageContext.IsAdmin && this._allowedHtml.IndexOf("ALL") < 0) { var detectedHtmlTag = this.Get <IFormatMessage>().CheckHtmlTags(body, this._allowedHtml, ','); if (detectedHtmlTag.IsSet() && detectedHtmlTag != "ALL") { this.PageContext.AddLoadMessage(detectedHtmlTag); return; } if (detectedHtmlTag.IsSet() && detectedHtmlTag == "ALL") { this.PageContext.AddLoadMessage(this.GetText("HTML_FORBIDDEN")); return; } } // body = this.Get<IFormatMessage>().RepairHtml(this,body,false); if (this._sig.Text.Length > 0) { if (this._sig.Text.Length <= this._allowedNumberOfCharacters) { var userData = new CombinedUserDataHelper(this.CurrentUserID); if (userData.NumPosts < this.Get <YafBoardSettings>().IgnoreSpamWordCheckPostCount) { // Check for spam string result; if (this.Get <ISpamWordCheck>().CheckForSpamWord(body, out result)) { var user = UserMembershipHelper.GetMembershipUserById(this.CurrentUserID); var userId = this.CurrentUserID; // Log and Send Message to Admins if (this.Get <YafBoardSettings>().BotHandlingOnRegister.Equals(1)) { this.Logger.Log( null, "Bot Detected", "Internal Spam Word Check detected a SPAM BOT: (user name : '{0}', user id : '{1}') after the user included a spam word in his/her signature: {2}" .FormatWith(user.UserName, this.CurrentUserID, result), EventLogTypes.SpamBotDetected); } else if (this.Get <YafBoardSettings>().BotHandlingOnRegister.Equals(2)) { this.Logger.Log( null, "Bot Detected", "Internal Spam Word Check detected a SPAM BOT: (user name : '{0}', user id : '{1}') after the user included a spam word in his/her signature: {2}, user was deleted and the name, email and IP Address are banned." .FormatWith(user.UserName, this.CurrentUserID, result), EventLogTypes.SpamBotDetected); // Kill user if (!this.PageContext.CurrentForumPage.IsAdminPage) { var userIp = new CombinedUserDataHelper(user, userId).LastIP; UserMembershipHelper.DeleteAndBanUser(this.CurrentUserID, user, userIp); } } } } LegacyDb.user_savesignature(this.CurrentUserID, this.Get <IBadWordReplace>().Replace(body)); } else { this.PageContext.AddLoadMessage( this.GetTextFormatted("SIGNATURE_MAX", this._allowedNumberOfCharacters)); return; } } else { LegacyDb.user_savesignature(this.CurrentUserID, DBNull.Value); } // clear the cache for this user... this.Get <IRaiseEvent>().Raise(new UpdateUserEvent(this.CurrentUserID)); if (this.PageContext.CurrentForumPage.IsAdminPage) { this.BindData(); } else { this.DoRedirect(); } }
/// <summary> /// The current_ after init. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> private void Current_AfterInit([NotNull] object sender, [NotNull] EventArgs e) { YafContext.Current.Vars["IsMobile"] = false; // see if this is a mobile device... if (!UserAgentHelper.IsMobileDevice(this.HttpRequestBase.UserAgent) && !this.HttpRequestBase.Browser.IsMobileDevice) { // make sure to shut off mobile theme usage if the user agent is not mobile. if (this.YafSession.UseMobileTheme ?? false) { this.YafSession.UseMobileTheme = false; } return; } if (!YafContext.Current.IsGuest) { // return if the user has mobile themes shut off in their profile. var userData = new CombinedUserDataHelper(YafContext.Current.PageUserID); if (!userData.UseMobileTheme) { return; } } this.UpdateUseMobileThemeFromQueryString(); // use the mobile theme? var useMobileTheme = this.YafSession.UseMobileTheme ?? true; // get the current mobile theme... var mobileTheme = YafContext.Current.BoardSettings.MobileTheme; if (mobileTheme.IsSet()) { // create a new theme object... var theme = new YafTheme(mobileTheme); // make sure it's valid... if (YafTheme.IsValidTheme(theme.ThemeFile)) { YafContext.Current.Vars["IsMobile"] = true; // set new mobile theme... if (useMobileTheme) { YafContext.Current.Get <ThemeProvider>().Theme = theme; this.YafSession.UseMobileTheme = true; } return; } } // make sure to shut off mobile theme usage if there was no valid mobile theme found... if (this.YafSession.UseMobileTheme ?? false) { this.YafSession.UseMobileTheme = false; } }
/// <summary> /// Logins the or create user. /// </summary> /// <param name="request"> /// The request. /// </param> /// <param name="parameters"> /// The access token. /// </param> /// <param name="message"> /// The message. /// </param> /// <returns> /// Returns if Login was successful or not /// </returns> public bool LoginOrCreateUser(HttpRequest request, string parameters, out string message) { if (!YafContext.Current.Get<YafBoardSettings>().AllowSingleSignOn) { message = YafContext.Current.Get<ILocalization>().GetText("LOGIN", "SSO_DEACTIVATED"); return false; } var facebookUser = this.GetFacebookUser(request, parameters); // Check if user name is null if (facebookUser.UserName.IsNotSet()) { facebookUser.UserName = facebookUser.Name; } // Check if user exists var userName = YafContext.Current.Get<MembershipProvider>().GetUserNameByEmail(facebookUser.Email); if (userName.IsNotSet()) { var userGender = 0; if (!facebookUser.Gender.IsSet()) { return this.CreateFacebookUser(facebookUser, userGender, out message); } switch (facebookUser.Gender) { case "male": userGender = 1; break; case "female": userGender = 2; break; } // Create User if not exists?! return this.CreateFacebookUser(facebookUser, userGender, out message); } var yafUser = YafUserProfile.GetProfile(userName); var yafUserData = new CombinedUserDataHelper(YafContext.Current.Get<MembershipProvider>().GetUser(userName, true)); // Legacy Handling if (ValidationHelper.IsNumeric(yafUser.Facebook)) { if (!yafUser.Facebook.Equals(facebookUser.UserID)) { message = YafContext.Current.Get<ILocalization>().GetText("LOGIN", "SSO_FACEBOOK_FAILED2"); return false; } } if (!yafUser.FacebookId.Equals(facebookUser.UserID)) { message = YafContext.Current.Get<ILocalization>().GetText("LOGIN", "SSO_FACEBOOK_FAILED2"); return false; } YafSingleSignOnUser.LoginSuccess(AuthService.facebook, userName, yafUserData.UserID, true); message = string.Empty; return true; }
/// <summary> /// Logins/Registers the twitter user. /// </summary> /// <param name="request"> /// The page request. /// </param> /// <param name="message"> /// The message. /// </param> /// <returns> /// Returns if the login was successfully or not. /// </returns> public static bool LoginTwitterUser(HttpRequest request, ref string message) { var oAuth = new OAuthTwitter { ConsumerKey = Config.TwitterConsumerKey, ConsumerSecret = Config.TwitterConsumerSecret }; // Get the access token and secret. oAuth.AccessTokenGet(request["oauth_token"], request["oauth_verifier"]); if (oAuth.TokenSecret.Length > 0) { var tweetAPI = new TweetAPI(oAuth); var twitterUser = tweetAPI.GetUser(); if (twitterUser.UserId > 0) { // Check if user exists var checkUser = YafContext.Current.Get<MembershipProvider>().GetUser( twitterUser.UserName, false); // Login user if exists if (checkUser != null) { // LOGIN Existing User var yafUser = YafUserProfile.GetProfile(checkUser.UserName); var yafUserData = new CombinedUserDataHelper(checkUser); if (!yafUserData.UseSingleSignOn) { message = YafContext.Current.Get<ILocalization>().GetText( "LOGIN", "SSO_DEACTIVATED_BYUSER"); return false; } if (yafUser.Twitter.Equals(twitterUser.UserName) && yafUser.TwitterId.Equals(twitterUser.UserId.ToString())) { LoginTwitterSuccess(false, oAuth, yafUserData.UserID, checkUser); return true; } message = YafContext.Current.Get<ILocalization>().GetText("LOGIN", "SSO_TWITTERID_NOTMATCH"); return false; } // Create User if not exists?! Doesnt work because there is no Email var email = "{0}@twitter.com".FormatWith(twitterUser.UserName); // Create User if not exists?! if (YafContext.Current.Get<YafBoardSettings>().RegisterNewFacebookUser && !YafContext.Current.Get<YafBoardSettings>().DisableRegistrations) { MembershipCreateStatus status; var pass = Membership.GeneratePassword(32, 16); var securityAnswer = Membership.GeneratePassword(64, 30); MembershipUser user = YafContext.Current.Get<MembershipProvider>().CreateUser( twitterUser.UserName, pass, email, "Answer is a generated Pass", securityAnswer, true, null, out status); // setup inital roles (if any) for this user RoleMembershipHelper.SetupUserRoles(YafContext.Current.PageBoardID, twitterUser.UserName); // create the user in the YAF DB as well as sync roles... int? userID = RoleMembershipHelper.CreateForumUser(user, YafContext.Current.PageBoardID); // create empty profile just so they have one YafUserProfile userProfile = YafUserProfile.GetProfile(twitterUser.UserName); userProfile.TwitterId = twitterUser.UserId.ToString(); userProfile.Twitter = twitterUser.UserName; userProfile.Homepage = !string.IsNullOrEmpty(twitterUser.Url) ? twitterUser.Url : "http://twitter.com/{0}".FormatWith(twitterUser.UserName); userProfile.RealName = twitterUser.Name; userProfile.Interests = twitterUser.Description; userProfile.Location = twitterUser.Location; userProfile.Save(); // setup their inital profile information userProfile.Save(); if (userID == null) { // something is seriously wrong here -- redirect to failure... message = YafContext.Current.Get<ILocalization>().GetText("LOGIN", "SSO_TWITTER_FAILED"); return false; } if (YafContext.Current.Get<YafBoardSettings>().NotificationOnUserRegisterEmailList.IsSet()) { // send user register notification to the following admin users... SendRegistrationNotificationEmail(user); } // save the time zone... int userId = UserMembershipHelper.GetUserIDFromProviderUserKey(user.ProviderUserKey); // send user register notification to the following admin users... SendRegistrationMessageToUser(user, pass, securityAnswer, userId, oAuth); LegacyDb.user_save( userId, YafContext.Current.PageBoardID, twitterUser.UserName, null, email, 0, null, null, null, true, null, null, null, null, null, null, null, null); bool autoWatchTopicsEnabled = YafContext.Current.Get<YafBoardSettings>().DefaultNotificationSetting == UserNotificationSetting.TopicsIPostToOrSubscribeTo; // save the settings... LegacyDb.user_savenotification( userId, true, autoWatchTopicsEnabled, YafContext.Current.Get<YafBoardSettings>().DefaultNotificationSetting, YafContext.Current.Get<YafBoardSettings>().DefaultSendDigestEmail); // save avatar if (!string.IsNullOrEmpty(twitterUser.ProfileImageUrl)) { LegacyDb.user_saveavatar( userId, twitterUser.ProfileImageUrl, null, null); } LoginTwitterSuccess(true, oAuth, userId, user); message = YafContext.Current.Get<ILocalization>().GetText("LOGIN", "UPDATE_EMAIL"); return true; } message = YafContext.Current.Get<ILocalization>().GetText("LOGIN", "SSO_TWITTER_FAILED"); return false; } } message = YafContext.Current.Get<ILocalization>().GetText("LOGIN", "SSO_TWITTER_FAILED"); return false; }
/// <summary> /// The get avatar url for user. /// </summary> /// <param name="userId"> /// The user id. /// </param> /// <returns> /// Returns the Avatar Url /// </returns> public string GetAvatarUrlForUser(int userId) { var userData = new CombinedUserDataHelper(userId); return this.GetAvatarUrlForUser(userData); }
/// <summary> /// Gets the forum user info as JSON string for the hover cards /// </summary> /// <param name="context">The context.</param> public void GetUserInfo([NotNull] HttpContext context) { try { var userId = context.Request.QueryString.GetFirstOrDefaultAs <int>("userinfo"); var boardId = context.Request.QueryString.GetFirstOrDefaultAs <int>("boardId"); var user = UserMembershipHelper.GetMembershipUserById(userId, boardId); if (user == null || user.ProviderUserKey.ToString() == "0") { context.Response.Write( "Error: Resource has been moved or is unavailable. Please contact the forum admin."); return; } // Check if user has access if (!this.Get <IPermissions>().Check(this.Get <BoardSettings>().ProfileViewPermissions)) { context.Response.Write(string.Empty); return; } var userData = new CombinedUserDataHelper(user, userId); context.Response.Clear(); context.Response.ContentType = "application/json"; context.Response.ContentEncoding = Encoding.UTF8; context.Response.Cache.SetCacheability(HttpCacheability.Public); context.Response.Cache.SetExpires( System.DateTime.UtcNow.AddMilliseconds(BoardContext.Current.Get <BoardSettings>().OnlineStatusCacheTimeout)); context.Response.Cache.SetLastModified(System.DateTime.UtcNow); var avatarUrl = this.Get <IAvatars>().GetAvatarUrlForUser(userId); avatarUrl = avatarUrl.IsNotSet() ? $"{BoardInfo.ForumClientFileRoot}images/noavatar.svg" : avatarUrl; var activeUsers = this.Get <IDataCache>().GetOrSet( Constants.Cache.UsersOnlineStatus, () => this.Get <DataBroker>().GetActiveList( false, BoardContext.Current.Get <BoardSettings>().ShowCrawlersInActiveList), TimeSpan.FromMilliseconds(BoardContext.Current.Get <BoardSettings>().OnlineStatusCacheTimeout)); var userIsOnline = activeUsers.AsEnumerable().Any( x => x.Field <int>("UserId").Equals(userId) && !x.Field <bool>("IsHidden")); var userName = this.Get <BoardSettings>().EnableDisplayName ? userData.DisplayName : userData.UserName; userName = HttpUtility.HtmlEncode(userName); var location = userData.Profile.Country.IsSet() ? BoardContext.Current.Get <IHaveLocalization>().GetText( "COUNTRY", userData.Profile.Country.Trim()) : userData.Profile.Location; if (userData.Profile.Region.IsSet() && userData.Profile.Country.IsSet()) { var tag = $"RGN_{userData.Profile.Country.Trim()}_{userData.Profile.Region}"; location += $", {this.Get<IHaveLocalization>().GetText("REGION", tag)}"; } var userInfo = new ForumUserInfo { Name = userName, RealName = HttpUtility.HtmlEncode(userData.Profile.RealName), Avatar = avatarUrl, Interests = HttpUtility.HtmlEncode(userData.Profile.Interests), HomePage = userData.Profile.Homepage, Posts = $"{userData.NumPosts:N0}", Rank = userData.RankName, Location = location, Joined = $"{this.Get<IHaveLocalization>().GetText("PROFILE", "JOINED")} {this.Get<IDateTime>().FormatDateLong(userData.Joined)}", Online = userIsOnline/*, * ProfileLink = BuildLink.GetLink(ForumPages.Profile, true, "u={0}&name={1}", userId, userName)*/ }; if (BoardContext.Current.Get <BoardSettings>().EnableUserReputation) { userInfo.Points = (userData.Points.ToType <int>() > 0 ? "+" : string.Empty) + userData.Points; } context.Response.Write(userInfo.ToJson()); HttpContext.Current.ApplicationInstance.CompleteRequest(); } catch (Exception x) { this.Get <ILogger>().Log(BoardContext.Current.PageUserID, this, x, EventLogTypes.Information); context.Response.Write( "Error: Resource has been moved or is unavailable. Please contact the forum admin."); } }
/// <summary> /// Handles the PostReply click including: Replying, Editing and New post. /// </summary> /// <param name="sender"> /// The Sender Object. /// </param> /// <param name="e"> /// The Event Arguments. /// </param> protected void PostReply_Click([NotNull] object sender, [NotNull] EventArgs e) { if (!this.IsPostReplyVerified()) { return; } if (this.IsPostReplyDelay()) { return; } var isPossibleSpamMessage = false; // Check for SPAM if (!this.PageContext.IsAdmin && !this.PageContext.ForumModeratorAccess && !this.PageContext.BoardSettings.SpamServiceType.Equals(0)) { // Check content for spam if ( this.Get <ISpamCheck>().CheckPostForSpam( this.PageContext.IsGuest ? this.From.Text : this.PageContext.PageUserName, this.Get <HttpRequestBase>().GetUserRealIPAddress(), BBCodeHelper.StripBBCode( HtmlHelper.StripHtml(HtmlHelper.CleanHtmlString(this.forumEditor.Text))) .RemoveMultipleWhitespace(), this.PageContext.IsGuest ? null : this.PageContext.User.Email, out var spamResult)) { switch (this.PageContext.BoardSettings.SpamMessageHandling) { case 0: this.Logger.Log( this.PageContext.PageUserID, "Spam Message Detected", $"Spam Check detected possible SPAM posted by User: {(this.PageContext.IsGuest ? this.From.Text : this.PageContext.PageUserName)}", EventLogTypes.SpamMessageDetected); break; case 1: this.spamApproved = false; isPossibleSpamMessage = true; this.Logger.Log( this.PageContext.PageUserID, "Spam Message Detected", $"Spam Check detected possible SPAM ({spamResult}) posted by User: {(this.PageContext.IsGuest ? this.From.Text : this.PageContext.PageUserName)}, it was flagged as unapproved post.", EventLogTypes.SpamMessageDetected); break; case 2: this.Logger.Log( this.PageContext.PageUserID, "Spam Message Detected", $"Spam Check detected possible SPAM ({spamResult}) posted by User: {(this.PageContext.IsGuest ? this.From.Text : this.PageContext.PageUserName)}, post was rejected", EventLogTypes.SpamMessageDetected); this.PageContext.AddLoadMessage(this.GetText("SPAM_MESSAGE"), MessageTypes.danger); return; case 3: this.Logger.Log( this.PageContext.PageUserID, "Spam Message Detected", $"Spam Check detected possible SPAM ({spamResult}) posted by User: {(this.PageContext.IsGuest ? this.From.Text : this.PageContext.PageUserName)}, user was deleted and banned", EventLogTypes.SpamMessageDetected); var userIp = new CombinedUserDataHelper( this.PageContext.CurrentUserData.Membership, this.PageContext.PageUserID).LastIP; UserMembershipHelper.DeleteAndBanUser( this.PageContext.PageUserID, this.PageContext.CurrentUserData.Membership, userIp); return; } } } // Check posts for urls if the user has only x posts if (BoardContext.Current.CurrentUserData.NumPosts <= BoardContext.Current.Get <BoardSettings>().IgnoreSpamWordCheckPostCount&& !this.PageContext.IsAdmin && !this.PageContext.ForumModeratorAccess) { var urlCount = UrlHelper.CountUrls(this.forumEditor.Text); if (urlCount > this.PageContext.BoardSettings.AllowedNumberOfUrls) { var spamResult = $"The user posted {urlCount} urls but allowed only {this.PageContext.BoardSettings.AllowedNumberOfUrls}"; switch (this.PageContext.BoardSettings.SpamMessageHandling) { case 0: this.Logger.Log( this.PageContext.PageUserID, "Spam Message Detected", $"Spam Check detected possible SPAM ({spamResult}) posted by User: {(this.PageContext.IsGuest ? this.From.Text : this.PageContext.PageUserName)}", EventLogTypes.SpamMessageDetected); break; case 1: this.spamApproved = false; isPossibleSpamMessage = true; this.Logger.Log( this.PageContext.PageUserID, "Spam Message Detected", $"Spam Check detected possible SPAM ({spamResult}) posted by User: {(this.PageContext.IsGuest ? this.From.Text : this.PageContext.PageUserName)}, it was flagged as unapproved post.", EventLogTypes.SpamMessageDetected); break; case 2: this.Logger.Log( this.PageContext.PageUserID, "Spam Message Detected", $"Spam Check detected possible SPAM ({spamResult}) posted by User: {(this.PageContext.IsGuest ? this.From.Text : this.PageContext.PageUserName)}, post was rejected", EventLogTypes.SpamMessageDetected); this.PageContext.AddLoadMessage(this.GetText("SPAM_MESSAGE"), MessageTypes.danger); return; case 3: this.Logger.Log( this.PageContext.PageUserID, "Spam Message Detected", $"Spam Check detected possible SPAM ({spamResult}) posted by User: {(this.PageContext.IsGuest ? this.From.Text : this.PageContext.PageUserName)}, user was deleted and banned", EventLogTypes.SpamMessageDetected); var userIp = new CombinedUserDataHelper( this.PageContext.CurrentUserData.Membership, this.PageContext.PageUserID).LastIP; UserMembershipHelper.DeleteAndBanUser( this.PageContext.PageUserID, this.PageContext.CurrentUserData.Membership, userIp); return; } } } // update the last post time... this.Get <ISession>().LastPost = DateTime.UtcNow.AddSeconds(30); // New Topic var messageId = this.PostReplyHandleNewPost(out var newTopic); // Check if message is approved var isApproved = this.GetRepository <Message>().GetById(messageId.ToType <int>()).MessageFlags.IsApproved; // vzrus^ the poll access controls are enabled and this is a new topic - we add the variables var attachPollParameter = string.Empty; var returnForum = string.Empty; if (this.PageContext.ForumPollAccess && this.PostOptions1.PollOptionVisible) { // new topic poll token attachPollParameter = $"&t={newTopic}"; // new return forum poll token returnForum = $"&f={this.PageContext.PageForumID}"; } // Create notification emails if (isApproved) { this.Get <ISendNotification>().ToWatchingUsers(messageId.ToType <int>()); if (!this.PageContext.IsGuest && this.PageContext.CurrentUserData.Activity) { // Handle Mentions BBCodeHelper.FindMentions(this.forumEditor.Text).ForEach( user => { var userId = this.Get <IUserDisplayName>().GetId(user).Value; if (userId != this.PageContext.PageUserID) { this.Get <IActivityStream>().AddMentionToStream( userId, newTopic.ToType <int>(), messageId.ToType <int>(), this.PageContext.PageUserID); } }); // Handle User Quoting BBCodeHelper.FindUserQuoting(this.forumEditor.Text).ForEach( user => { var userId = this.Get <IUserDisplayName>().GetId(user).Value; if (userId != this.PageContext.PageUserID) { this.Get <IActivityStream>().AddQuotingToStream( userId, newTopic.ToType <int>(), messageId.ToType <int>(), this.PageContext.PageUserID); } }); this.Get <IActivityStream>().AddTopicToStream( Config.IsDotNetNuke ? this.PageContext.PageForumID : this.PageContext.PageUserID, newTopic, messageId.ToType <int>(), this.TopicSubjectTextBox.Text, this.forumEditor.Text); // Add tags if (this.Tags.Text.IsSet()) { var tags = this.Tags.Text.Split(','); var boardTags = this.GetRepository <Tag>().GetByBoardId(); tags.ForEach( tag => { var existTag = boardTags.FirstOrDefault(t => t.TagName == tag); if (existTag != null) { // add to topic this.GetRepository <TopicTag>().Add( existTag.ID, newTopic.ToType <int>()); } else { // save new Tag var newTagId = this.GetRepository <Tag>().Add(tag); // add to topic this.GetRepository <TopicTag>().Add(newTagId, newTopic.ToType <int>()); } }); } } if (attachPollParameter.IsNotSet() || !this.PostOptions1.PollChecked) { // regular redirect... BuildLink.Redirect(ForumPages.Posts, "m={0}#post{0}", messageId); } else { // poll edit redirect... BuildLink.Redirect(ForumPages.PollEdit, "{0}", attachPollParameter); } } else { // Not Approved if (this.PageContext.BoardSettings.EmailModeratorsOnModeratedPost) { // not approved, notify moderators this.Get <ISendNotification>() .ToModeratorsThatMessageNeedsApproval( this.PageContext.PageForumID, messageId.ToType <int>(), isPossibleSpamMessage); } // 't' variable is required only for poll and this is a attach poll token for attachments page if (!this.PostOptions1.PollChecked) { attachPollParameter = string.Empty; } // Tell user that his message will have to be approved by a moderator var url = BuildLink.GetLink(ForumPages.Topics, "f={0}", this.PageContext.PageForumID); if (attachPollParameter.Length <= 0) { BuildLink.Redirect(ForumPages.Info, "i=1&url={0}", this.Server.UrlEncode(url)); } else { BuildLink.Redirect(ForumPages.PollEdit, "&ra=1{0}{1}", attachPollParameter, returnForum); } if (Config.IsRainbow) { BuildLink.Redirect(ForumPages.Info, "i=1"); } } }
/// <summary> /// The update profile_ click. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The e.</param> protected void UpdateProfile_Click([NotNull] object sender, [NotNull] EventArgs e) { if (this.HomePage.Text.IsSet()) { // add http:// by default if (!Regex.IsMatch(this.HomePage.Text.Trim(), @"^(http|https|ftp|ftps|git|svn|news)\://.*")) { this.HomePage.Text = "http://{0}".FormatWith(this.HomePage.Text.Trim()); } if (!ValidationHelper.IsValidURL(this.HomePage.Text)) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_HOME"), MessageTypes.Warning); return; } } if (this.Weblog.Text.IsSet() && !ValidationHelper.IsValidURL(this.Weblog.Text.Trim())) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_WEBLOG"), MessageTypes.Warning); return; } if (this.MSN.Text.IsSet() && !ValidationHelper.IsValidEmail(this.MSN.Text)) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_MSN"), MessageTypes.Warning); return; } if (this.Xmpp.Text.IsSet() && !ValidationHelper.IsValidXmpp(this.Xmpp.Text)) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_XMPP"), MessageTypes.Warning); return; } if (this.ICQ.Text.IsSet() && !(ValidationHelper.IsValidEmail(this.ICQ.Text) || ValidationHelper.IsNumeric(this.ICQ.Text))) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_ICQ"), MessageTypes.Warning); return; } if (this.Facebook.Text.IsSet() && !ValidationHelper.IsValidURL(this.Facebook.Text)) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_FACEBOOK"), MessageTypes.Warning); return; } if (this.Google.Text.IsSet() && !ValidationHelper.IsValidURL(this.Google.Text)) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_GOOGLE"), MessageTypes.Warning); return; } string displayName = null; if (this.Get <YafBoardSettings>().EnableDisplayName && this.Get <YafBoardSettings>().AllowDisplayNameModification) { if (this.DisplayName.Text.Trim().Length < this.Get <YafBoardSettings>().DisplayNameMinLength) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "INVALID_DISPLAYNAME"), MessageTypes.Warning); return; } if (this.DisplayName.Text.Trim() != this.UserData.DisplayName) { if (this.Get <IUserDisplayName>().GetId(this.DisplayName.Text.Trim()).HasValue) { this.PageContext.AddLoadMessage(this.GetText("REGISTER", "ALREADY_REGISTERED_DISPLAYNAME"), MessageTypes.Warning); return; } displayName = this.DisplayName.Text.Trim(); } } string userName = UserMembershipHelper.GetUserNameFromID(this.currentUserID); if (this.UpdateEmailFlag) { string newEmail = this.Email.Text.Trim(); if (!ValidationHelper.IsValidEmail(newEmail)) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_EMAIL"), MessageTypes.Warning); return; } string userNameFromEmail = this.Get <MembershipProvider>().GetUserNameByEmail(this.Email.Text.Trim()); if (userNameFromEmail.IsSet() && userNameFromEmail != userName) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_EMAIL"), MessageTypes.Warning); return; } if (this.Get <YafBoardSettings>().EmailVerification) { this.SendEmailVerification(newEmail); } else { // just update the e-mail... try { UserMembershipHelper.UpdateEmail(this.currentUserID, this.Email.Text.Trim()); } catch (ApplicationException) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "DUPLICATED_EMAIL"), MessageTypes.Warning); return; } } } if (this.Interests.Text.Trim().Length > 400) { this.PageContext.AddLoadMessage( this.GetTextFormatted("FIELD_TOOLONG", this.GetText("CP_EDITPROFILE", "INTERESTS"), 400), MessageTypes.Warning); return; } if (this.Occupation.Text.Trim().Length > 400) { this.PageContext.AddLoadMessage( this.GetTextFormatted("FIELD_TOOLONG", this.GetText("CP_EDITPROFILE", "OCCUPATION"), 400), MessageTypes.Warning); return; } this.UpdateUserProfile(userName); // vzrus: We should do it as we need to write null value to db, else it will be empty. // Localizer currently treats only nulls. object language = null; object culture = this.Culture.SelectedValue; object theme = this.Theme.SelectedValue; object editor = this.ForumEditor.SelectedValue; if (string.IsNullOrEmpty(this.Theme.SelectedValue)) { theme = null; } if (string.IsNullOrEmpty(this.ForumEditor.SelectedValue)) { editor = null; } if (string.IsNullOrEmpty(this.Culture.SelectedValue)) { culture = null; } else { foreach (DataRow row in StaticDataHelper.Cultures() .Rows.Cast <DataRow>() .Where(row => culture.ToString() == row["CultureTag"].ToString())) { language = row["CultureFile"].ToString(); } } // save remaining settings to the DB LegacyDb.user_save( this.currentUserID, this.PageContext.PageBoardID, null, displayName, null, this.TimeZones.SelectedValue.ToType <int>(), language, culture, theme, editor, this.UseMobileTheme.Checked, null, null, null, this.DSTUser.Checked, this.HideMe.Checked, null); // vzrus: If it's a guest edited by an admin registry value should be changed DataTable dt = LegacyDb.user_list(this.PageContext.PageBoardID, this.currentUserID, true, null, null, false); if (dt.Rows.Count > 0 && dt.Rows[0]["IsGuest"].ToType <bool>()) { LegacyDb.registry_save("timezone", this.TimeZones.SelectedValue, this.PageContext.PageBoardID); } // clear the cache for this user...) this.Get <IRaiseEvent>().Raise(new UpdateUserEvent(this.currentUserID)); YafContext.Current.Get <IDataCache>().Clear(); if (!this.adminEditMode) { YafBuildLink.Redirect(ForumPages.cp_profile); } else { this._userData = null; this.BindData(); } }
/// <summary> /// The quick reply_ click. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void QuickReplyClick([NotNull] object sender, [NotNull] EventArgs e) { try { if (this.quickReplyEditor.Text.Length <= 0) { YafContext.Current.PageElements.RegisterJsBlockStartup( name: "openModalJs", script: JavaScriptBlocks.OpenModalJs(clientId: "QuickReplyDialog")); this.PageContext.AddLoadMessage(message: this.GetText(tag: "EMPTY_MESSAGE"), messageType: MessageTypes.warning); return; } // No need to check whitespace if they are actually posting something if (this.Get <YafBoardSettings>().MaxPostSize > 0 && this.quickReplyEditor.Text.Length >= this.Get <YafBoardSettings>().MaxPostSize) { YafContext.Current.PageElements.RegisterJsBlockStartup( name: "openModalJs", script: JavaScriptBlocks.OpenModalJs(clientId: "QuickReplyDialog")); this.PageContext.AddLoadMessage(message: this.GetText(tag: "ISEXCEEDED"), messageType: MessageTypes.warning); return; } if (this.EnableCaptcha() && !CaptchaHelper.IsValid(captchaText: this.tbCaptcha.Text.Trim())) { YafContext.Current.PageElements.RegisterJsBlockStartup( name: "openModalJs", script: JavaScriptBlocks.OpenModalJs(clientId: "QuickReplyDialog")); this.PageContext.AddLoadMessage(message: this.GetText(tag: "BAD_CAPTCHA"), messageType: MessageTypes.warning); return; } if (!(this.PageContext.IsAdmin || this.PageContext.ForumModeratorAccess) && this.Get <YafBoardSettings>().PostFloodDelay > 0) { if (YafContext.Current.Get <IYafSession>().LastPost > DateTime.UtcNow.AddSeconds(value: -this.Get <YafBoardSettings>().PostFloodDelay)) { YafContext.Current.PageElements.RegisterJsBlockStartup( name: "openModalJs", script: JavaScriptBlocks.OpenModalJs(clientId: "QuickReplyDialog")); this.PageContext.AddLoadMessage( message: this.GetTextFormatted( tag: "wait", (YafContext.Current.Get <IYafSession>().LastPost - DateTime.UtcNow.AddSeconds(value: -this.Get <YafBoardSettings>().PostFloodDelay)).Seconds), messageType: MessageTypes.warning); return; } } YafContext.Current.Get <IYafSession>().LastPost = DateTime.UtcNow; // post message... long messageId = 0; object replyTo = -1; var message = this.quickReplyEditor.Text; long topicId = this.PageContext.PageTopicID; // SPAM Check // Check if Forum is Moderated var isForumModerated = false; var dt = this.GetRepository <Forum>().List( boardId: this.PageContext.PageBoardID, forumId: this.PageContext.PageForumID); var forumInfo = dt.FirstOrDefault(); if (forumInfo != null) { isForumModerated = this.CheckForumModerateStatus(forumInfo: forumInfo); } var spamApproved = true; var isPossibleSpamMessage = false; // Check for SPAM if (!this.PageContext.IsAdmin && !this.PageContext.ForumModeratorAccess && !this.Get <YafBoardSettings>().SpamServiceType.Equals(obj: 0)) { string spamResult; // Check content for spam if (this.Get <ISpamCheck>().CheckPostForSpam( userName: this.PageContext.IsGuest ? "Guest" : this.PageContext.PageUserName, ipAddress: YafContext.Current.Get <HttpRequestBase>().GetUserRealIPAddress(), postMessage: this.quickReplyEditor.Text, emailAddress: this.PageContext.IsGuest ? null : this.PageContext.User.Email, result: out spamResult)) { switch (this.Get <YafBoardSettings>().SpamMessageHandling) { case 0: this.Logger.Log( userId: this.PageContext.PageUserID, source: "Spam Message Detected", description: string.Format( format: "Spam Check detected possible SPAM ({1}) posted by User: {0}", arg0: this.PageContext.IsGuest ? "Guest" : this.PageContext.PageUserName, arg1: spamResult), eventType: EventLogTypes.SpamMessageDetected); break; case 1: spamApproved = false; isPossibleSpamMessage = true; this.Logger.Log( userId: this.PageContext.PageUserID, source: "Spam Message Detected", description: string .Format( format: "Spam Check detected possible SPAM ({1}) posted by User: {0}, it was flagged as unapproved post", arg0: this.PageContext.IsGuest ? "Guest" : this.PageContext.PageUserName, arg1: spamResult), eventType: EventLogTypes.SpamMessageDetected); break; case 2: this.Logger.Log( userId: this.PageContext.PageUserID, source: "Spam Message Detected", description: string .Format( format: "Spam Check detected possible SPAM ({1}) posted by User: {0}, post was rejected", arg0: this.PageContext.IsGuest ? "Guest" : this.PageContext.PageUserName, arg1: spamResult), eventType: EventLogTypes.SpamMessageDetected); YafContext.Current.PageElements.RegisterJsBlockStartup( name: "openModalJs", script: JavaScriptBlocks.OpenModalJs(clientId: "QuickReplyDialog")); this.PageContext.AddLoadMessage(message: this.GetText(tag: "SPAM_MESSAGE"), messageType: MessageTypes.danger); return; case 3: this.Logger.Log( userId: this.PageContext.PageUserID, source: "Spam Message Detected", description: string .Format( format: "Spam Check detected possible SPAM ({1}) posted by User: {0}, user was deleted and bannded", arg0: this.PageContext.IsGuest ? "Guest" : this.PageContext.PageUserName, arg1: spamResult), eventType: EventLogTypes.SpamMessageDetected); var userIp = new CombinedUserDataHelper( membershipUser: this.PageContext.CurrentUserData.Membership, userId: this.PageContext.PageUserID).LastIP; UserMembershipHelper.DeleteAndBanUser( userID: this.PageContext.PageUserID, user: this.PageContext.CurrentUserData.Membership, userIpAddress: userIp); return; } } // Check posts for urls if the user has only x posts if (YafContext.Current.CurrentUserData.NumPosts <= YafContext.Current.Get <YafBoardSettings>().IgnoreSpamWordCheckPostCount && !this.PageContext.IsAdmin && !this.PageContext.ForumModeratorAccess) { var urlCount = UrlHelper.CountUrls(message: this.quickReplyEditor.Text); if (urlCount > this.PageContext.BoardSettings.AllowedNumberOfUrls) { spamResult = $"The user posted {urlCount} urls but allowed only {this.PageContext.BoardSettings.AllowedNumberOfUrls}"; switch (this.Get <YafBoardSettings>().SpamMessageHandling) { case 0: this.Logger.Log( userId: this.PageContext.PageUserID, source: "Spam Message Detected", description: string.Format( format: "Spam Check detected possible SPAM ({1}) posted by User: {0}", arg0: this.PageContext.IsGuest ? "Guest" : this.PageContext.PageUserName, arg1: spamResult), eventType: EventLogTypes.SpamMessageDetected); break; case 1: spamApproved = false; isPossibleSpamMessage = true; this.Logger.Log( userId: this.PageContext.PageUserID, source: "Spam Message Detected", description: string .Format( format: "Spam Check detected possible SPAM ({1}) posted by User: {0}, it was flagged as unapproved post", arg0: this.PageContext.IsGuest ? "Guest" : this.PageContext.PageUserName, arg1: spamResult), eventType: EventLogTypes.SpamMessageDetected); break; case 2: this.Logger.Log( userId: this.PageContext.PageUserID, source: "Spam Message Detected", description: string .Format( format: "Spam Check detected possible SPAM ({1}) posted by User: {0}, post was rejected", arg0: this.PageContext.IsGuest ? "Guest" : this.PageContext.PageUserName, arg1: spamResult), eventType: EventLogTypes.SpamMessageDetected); YafContext.Current.PageElements.RegisterJsBlockStartup( name: "openModalJs", script: JavaScriptBlocks.OpenModalJs(clientId: "QuickReplyDialog")); this.PageContext.AddLoadMessage(message: this.GetText(tag: "SPAM_MESSAGE"), messageType: MessageTypes.danger); return; case 3: this.Logger.Log( userId: this.PageContext.PageUserID, source: "Spam Message Detected", description: string .Format( format: "Spam Check detected possible SPAM ({1}) posted by User: {0}, user was deleted and bannded", arg0: this.PageContext.IsGuest ? "Guest" : this.PageContext.PageUserName, arg1: spamResult), eventType: EventLogTypes.SpamMessageDetected); var userIp = new CombinedUserDataHelper( membershipUser: this.PageContext.CurrentUserData.Membership, userId: this.PageContext.PageUserID).LastIP; UserMembershipHelper.DeleteAndBanUser( userID: this.PageContext.PageUserID, user: this.PageContext.CurrentUserData.Membership, userIpAddress: userIp); return; } } } if (!this.PageContext.IsGuest) { this.UpdateWatchTopic(userId: this.PageContext.PageUserID, topicId: this.PageContext.PageTopicID); } } // If Forum is Moderated if (isForumModerated) { spamApproved = false; } // Bypass Approval if Admin or Moderator if (this.PageContext.IsAdmin || this.PageContext.ForumModeratorAccess) { spamApproved = true; } var messageFlags = new MessageFlags { IsHtml = this.quickReplyEditor.UsesHTML, IsBBCode = this.quickReplyEditor.UsesBBCode, IsApproved = spamApproved }; // Bypass Approval if Admin or Moderator. this.GetRepository <Message>().Save( topicId: topicId, userId: this.PageContext.PageUserID, message: message, guestUserName: null, ip: this.Get <HttpRequestBase>().GetUserRealIPAddress(), posted: DateTime.UtcNow, replyTo: replyTo.ToType <int>(), flags: messageFlags.BitValue, messageID: ref messageId); // Check to see if the user has enabled "auto watch topic" option in his/her profile. if (this.PageContext.CurrentUserData.AutoWatchTopics) { var watchTopicId = this.GetRepository <WatchTopic>().Check( userId: this.PageContext.PageUserID, topicId: this.PageContext.PageTopicID); if (!watchTopicId.HasValue) { // subscribe to this topic this.GetRepository <WatchTopic>().Add(userID: this.PageContext.PageUserID, topicID: this.PageContext.PageTopicID); } } if (messageFlags.IsApproved) { // send new post notification to users watching this topic/forum this.Get <ISendNotification>().ToWatchingUsers(newMessageId: messageId.ToType <int>()); if (Config.IsDotNetNuke && !this.PageContext.IsGuest) { this.Get <IActivityStream>().AddReplyToStream( forumID: this.PageContext.PageForumID, topicID: this.PageContext.PageTopicID, messageID: messageId.ToType <int>(), topicTitle: this.PageContext.PageTopicName, message: message); } // redirect to newly posted message YafBuildLink.Redirect(page: ForumPages.posts, format: "m={0}&#post{0}", messageId); } else { if (this.Get <YafBoardSettings>().EmailModeratorsOnModeratedPost) { // not approved, notifiy moderators this.Get <ISendNotification>().ToModeratorsThatMessageNeedsApproval( forumId: this.PageContext.PageForumID, newMessageId: messageId.ToType <int>(), isSpamMessage: isPossibleSpamMessage); } var url = YafBuildLink.GetLink(page: ForumPages.topics, format: "f={0}", this.PageContext.PageForumID); if (Config.IsRainbow) { YafBuildLink.Redirect(page: ForumPages.info, format: "i=1"); } else { YafBuildLink.Redirect(page: ForumPages.info, format: "i=1&url={0}", this.Server.UrlEncode(s: url)); } } } catch (Exception exception) { if (exception.GetType() != typeof(ThreadAbortException)) { this.Logger.Log(userId: this.PageContext.PageUserID, source: this, exception: exception); } } }
/// <summary> /// Verifies the message allowed. /// </summary> /// <param name="count">The recipients count.</param> /// <param name="message">The message.</param> /// <returns> /// Returns if the user is allowed to send a message or not /// </returns> private bool VerifyMessageAllowed(int count, string message) { // Check if SPAM Message first... if (!this.PageContext.IsAdmin && !this.PageContext.ForumModeratorAccess && !this.Get <YafBoardSettings>().SpamServiceType.Equals(0)) { var spamChecker = new YafSpamCheck(); string spamResult; // Check content for spam if (spamChecker.CheckPostForSpam( this.PageContext.IsGuest ? "Guest" : this.PageContext.PageUserName, YafContext.Current.Get <HttpRequestBase>().GetUserRealIPAddress(), message, this.PageContext.User.Email, out spamResult)) { switch (this.Get <YafBoardSettings>().SpamMessageHandling) { case 0: this.Logger.Log( this.PageContext.PageUserID, "Spam Message Detected", "Spam Check detected possible SPAM ({1}) posted by User: {0}" .FormatWith( this.PageContext.PageUserName, spamResult), EventLogTypes.SpamMessageDetected); break; case 1: this.Logger.Log( this.PageContext.PageUserID, "Spam Message Detected", "Spam Check detected possible SPAM ({1}) posted by User: {0}, it was flagged as unapproved post" .FormatWith( this.PageContext.PageUserName, spamResult), EventLogTypes.SpamMessageDetected); break; case 2: this.Logger.Log( this.PageContext.PageUserID, "Spam Message Detected", "Spam Check detected possible SPAM ({1}) posted by User: {0}, post was rejected" .FormatWith( this.PageContext.PageUserName, spamResult), EventLogTypes.SpamMessageDetected); this.PageContext.AddLoadMessage(this.GetText("SPAM_MESSAGE"), MessageTypes.danger); break; case 3: this.Logger.Log( this.PageContext.PageUserID, "Spam Message Detected", "Spam Check detected possible SPAM ({1}) posted by User: {0}, user was deleted and bannded" .FormatWith( this.PageContext.PageUserName, spamResult), EventLogTypes.SpamMessageDetected); var userIp = new CombinedUserDataHelper( this.PageContext.CurrentUserData.Membership, this.PageContext.PageUserID).LastIP; UserMembershipHelper.DeleteAndBanUser( this.PageContext.PageUserID, this.PageContext.CurrentUserData.Membership, userIp); break; } return(false); } // Check posts for urls if the user has only x posts if (YafContext.Current.CurrentUserData.NumPosts <= YafContext.Current.Get <YafBoardSettings>().IgnoreSpamWordCheckPostCount&& !this.PageContext.IsAdmin && !this.PageContext.ForumModeratorAccess) { var urlCount = UrlHelper.CountUrls(message); if (urlCount > this.PageContext.BoardSettings.AllowedNumberOfUrls) { spamResult = "The user posted {0} urls but allowed only {1}".FormatWith( urlCount, this.PageContext.BoardSettings.AllowedNumberOfUrls); switch (this.Get <YafBoardSettings>().SpamMessageHandling) { case 0: this.Logger.Log( this.PageContext.PageUserID, "Spam Message Detected", "Spam Check detected possible SPAM ({1}) posted by User: {0}".FormatWith( this.PageContext.PageUserName, spamResult), EventLogTypes.SpamMessageDetected); break; case 1: this.Logger.Log( this.PageContext.PageUserID, "Spam Message Detected", "Spam Check detected possible SPAM ({1}) posted by User: {0}, it was flagged as unapproved post" .FormatWith( this.PageContext.IsGuest ? "Guest" : this.PageContext.PageUserName, spamResult), EventLogTypes.SpamMessageDetected); break; case 2: this.Logger.Log( this.PageContext.PageUserID, "Spam Message Detected", "Spam Check detected possible SPAM ({1}) posted by User: {0}, post was rejected" .FormatWith( this.PageContext.PageUserName, spamResult), EventLogTypes.SpamMessageDetected); this.PageContext.AddLoadMessage(this.GetText("SPAM_MESSAGE"), MessageTypes.danger); break; case 3: this.Logger.Log( this.PageContext.PageUserID, "Spam Message Detected", "Spam Check detected possible SPAM ({1}) posted by User: {0}, user was deleted and bannded" .FormatWith( this.PageContext.PageUserName, spamResult), EventLogTypes.SpamMessageDetected); var userIp = new CombinedUserDataHelper( this.PageContext.CurrentUserData.Membership, this.PageContext.PageUserID).LastIP; UserMembershipHelper.DeleteAndBanUser( this.PageContext.PageUserID, this.PageContext.CurrentUserData.Membership, userIp); break; } return(false); } } return(true); } /////////////////////////////// // test sending user's PM count // get user's name var drPMInfo = LegacyDb.user_pmcount(YafContext.Current.PageUserID).Rows[0]; if ((drPMInfo["NumberTotal"].ToType <int>() + count <= drPMInfo["NumberAllowed"].ToType <int>()) || YafContext.Current.IsAdmin) { return(true); } // user has full PM box YafContext.Current.AddLoadMessage( this.GetTextFormatted("OWN_PMBOX_FULL", drPMInfo["NumberAllowed"]), MessageTypes.danger); return(false); }
/// <summary> /// The page_ load. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> protected void Page_Load([NotNull] object sender, [NotNull] EventArgs e) { if (this.User == null) { BuildLink.AccessDenied(); } if (!this.IsPostBack) { // get user data... var userHe = UserMembershipHelper.GetMembershipUserById(this.UserID); if (userHe == null) { // No such user exists BuildLink.AccessDenied(); } if (userHe.IsApproved == false) { BuildLink.AccessDenied(); } var displayNameHe = UserMembershipHelper.GetDisplayNameFromID(this.UserID); this.PageLinks.AddLink(this.PageContext.BoardSettings.Name, BuildLink.GetLink(ForumPages.forum)); this.PageLinks.AddLink( this.PageContext.BoardSettings.EnableDisplayName ? displayNameHe : userHe.UserName, BuildLink.GetLink( ForumPages.profile, "u={0}&name={1}", this.UserID, this.PageContext.BoardSettings.EnableDisplayName ? displayNameHe : userHe.UserName)); this.PageLinks.AddLink(this.GetText("TITLE"), string.Empty); if (this.UserID == this.PageContext.PageUserID) { this.NotifyLabel.Text = this.GetText("SERVERYOU"); this.Alert.Type = MessageTypes.warning; } else { if (userHe == null) { BuildLink.AccessDenied(/*No such user exists*/); } // Data for current page user var userMe = UserMembershipHelper.GetMembershipUserById(this.PageContext.PageUserID); // get full user data... var userDataHe = new CombinedUserDataHelper(userHe, this.UserID); var userDataMe = new CombinedUserDataHelper(userMe, this.PageContext.PageUserID); var serverHe = userDataHe.Profile.XMPP .Substring(userDataHe.Profile.XMPP.IndexOf("@", StringComparison.Ordinal) + 1).Trim(); var serverMe = userDataMe.Profile.XMPP .Substring(userDataMe.Profile.XMPP.IndexOf("@", StringComparison.Ordinal) + 1).Trim(); this.NotifyLabel.Text = serverMe == serverHe ? this.GetTextFormatted("SERVERSAME", userDataHe.Profile.XMPP) : this.GetTextFormatted("SERVEROTHER", $"http://{serverHe}"); this.Alert.Type = MessageTypes.info; } } }
/// <summary> /// SSO Login From Facebook /// </summary> /// <param name="id"> /// The id. /// </param> /// <param name="name"> /// The name. /// </param> /// <param name="first_name"> /// The first name. /// </param> /// <param name="last_name"> /// The last name. /// </param> /// <param name="link"> /// The link. /// </param> /// <param name="username"> /// The user name. /// </param> /// <param name="birthday"> /// The birthday. /// </param> /// <param name="hometown"> /// The hometown. /// </param> /// <param name="gender"> /// The gender. /// </param> /// <param name="email"> /// The email. /// </param> /// <param name="timezone"> /// The timezone. /// </param> /// <param name="locale"> /// The locale. /// </param> /// <param name="remember"> /// The remember. /// </param> /// <returns> /// Returns the Login Status /// </returns> public static string LoginFacebookUser( string id, string name, string first_name, string last_name, string link, string username, string birthday, string hometown, string gender, string email, string timezone, string locale, bool remember) { if (!YafContext.Current.Get<YafBoardSettings>().AllowSingleSignOn) { return YafContext.Current.Get<ILocalization>().GetText("LOGIN", "SSO_DEACTIVATED"); } // Check if username is null if (string.IsNullOrEmpty(username)) { username = name; } var userGender = 0; if (!string.IsNullOrEmpty(gender)) { switch (gender) { case "male": userGender = 1; break; case "female": userGender = 2; break; } } // Check if user exists var userName = YafContext.Current.Get<MembershipProvider>().GetUserNameByEmail(email); // Login user if exists if (!string.IsNullOrEmpty(userName)) { var yafUser = YafUserProfile.GetProfile(userName); var yafUserData = new CombinedUserDataHelper(YafContext.Current.Get<MembershipProvider>().GetUser(userName, true)); if (!yafUserData.UseSingleSignOn) { return YafContext.Current.Get<ILocalization>().GetText("LOGIN", "SSO_DEACTIVATED_BYUSER"); } if (yafUser.Facebook.Equals(id)) { // Add Flag to User that indicates that the user is logged in via facebook LegacyDb.user_update_single_sign_on_status(yafUserData.UserID, true, false); FormsAuthentication.SetAuthCookie(userName, remember); YafContext.Current.Get<IRaiseEvent>().Raise( new SuccessfulUserLoginEvent(YafContext.Current.PageUserID)); return "OK"; } return YafContext.Current.Get<ILocalization>().GetText("LOGIN", "SSO_ID_NOTMATCH"); } // Create User if not exists?! if (YafContext.Current.Get<YafBoardSettings>().RegisterNewFacebookUser && !YafContext.Current.Get<YafBoardSettings>().DisableRegistrations) { MembershipCreateStatus status; var pass = Membership.GeneratePassword(32, 16); var securityAnswer = Membership.GeneratePassword(64, 30); MembershipUser user = YafContext.Current.Get<MembershipProvider>().CreateUser( username, pass, email, "Answer is a generated Pass", securityAnswer, true, null, out status); // setup inital roles (if any) for this user RoleMembershipHelper.SetupUserRoles(YafContext.Current.PageBoardID, username); // create the user in the YAF DB as well as sync roles... int? userID = RoleMembershipHelper.CreateForumUser(user, YafContext.Current.PageBoardID); // create empty profile just so they have one YafUserProfile userProfile = YafUserProfile.GetProfile(username); userProfile.Facebook = id; userProfile.Homepage = link; if (!string.IsNullOrEmpty(birthday)) { DateTime userBirthdate; var ci = CultureInfo.CreateSpecificCulture("en-US"); DateTime.TryParse(birthday, ci, DateTimeStyles.None, out userBirthdate); if (userBirthdate > DateTime.MinValue.Date) { userProfile.Birthday = userBirthdate; } } userProfile.RealName = username; userProfile.Gender = userGender; if (!string.IsNullOrEmpty(hometown)) { userProfile.Location = hometown; } userProfile.Save(); // setup their inital profile information userProfile.Save(); if (userID == null) { // something is seriously wrong here -- redirect to failure... return YafContext.Current.Get<ILocalization>().GetText("LOGIN", "SSO_FAILED"); } if (YafContext.Current.Get<YafBoardSettings>().NotificationOnUserRegisterEmailList.IsSet()) { // send user register notification to the following admin users... SendRegistrationNotificationEmail(user); } // send user register notification to the following admin users... SendRegistrationNotificationToUser(user, pass, securityAnswer); // save the time zone... int userId = UserMembershipHelper.GetUserIDFromProviderUserKey(user.ProviderUserKey); LegacyDb.user_save( userId, YafContext.Current.PageBoardID, username, null, email, timezone, null, null, null, true, null, null, null, null, null, null, null, null); bool autoWatchTopicsEnabled = YafContext.Current.Get<YafBoardSettings>().DefaultNotificationSetting == UserNotificationSetting.TopicsIPostToOrSubscribeTo; // save the settings... LegacyDb.user_savenotification( userId, true, autoWatchTopicsEnabled, YafContext.Current.Get<YafBoardSettings>().DefaultNotificationSetting, YafContext.Current.Get<YafBoardSettings>().DefaultSendDigestEmail); // save avatar LegacyDb.user_saveavatar(userId, "https://graph.facebook.com/{0}/picture".FormatWith(id), null, null); // Clearing cache with old Active User Lazy Data ... YafContext.Current.Get<IDataCache>().Remove(Constants.Cache.ActiveUserLazyData.FormatWith(userId)); YafContext.Current.Get<IRaiseEvent>().Raise(new NewUserRegisteredEvent(user, userId)); // Add Flag to User that indicates that the user is logged in via facebook LegacyDb.user_update_single_sign_on_status(userId, true, false); FormsAuthentication.SetAuthCookie(user.UserName, remember); YafContext.Current.Get<IRaiseEvent>().Raise(new SuccessfulUserLoginEvent(YafContext.Current.PageUserID)); return "OK"; } return YafContext.Current.Get<ILocalization>().GetText("LOGIN", "SSO_FAILED"); }
/// <summary> /// Saves the Updated Profile /// </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 UpdateProfile_Click([NotNull] object sender, [NotNull] EventArgs e) { var userName = UserMembershipHelper.GetUserNameFromID(this.currentUserID); if (this.HomePage.Text.IsSet()) { // add http:// by default if (!Regex.IsMatch(this.HomePage.Text.Trim(), @"^(http|https|ftp|ftps|git|svn|news)\://.*")) { this.HomePage.Text = "http://{0}".FormatWith(this.HomePage.Text.Trim()); } if (!ValidationHelper.IsValidURL(this.HomePage.Text)) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_HOME"), MessageTypes.Warning); return; } if (this.UserData.NumPosts < this.Get <YafBoardSettings>().IgnoreSpamWordCheckPostCount) { string result; // Check for spam if (this.Get <ISpamWordCheck>().CheckForSpamWord(this.HomePage.Text, out result)) { // Log and Send Message to Admins if (this.Get <YafBoardSettings>().BotHandlingOnRegister.Equals(1)) { this.Logger.Log( null, "Bot Detected", "Internal Spam Word Check detected a SPAM BOT: (user name : '{0}', user id : '{1}') after the user changed the profile Homepage url to: {2}" .FormatWith(userName, this.currentUserID, this.HomePage.Text), EventLogTypes.SpamBotDetected); } else if (this.Get <YafBoardSettings>().BotHandlingOnRegister.Equals(2)) { this.Logger.Log( null, "Bot Detected", "Internal Spam Word Check detected a SPAM BOT: (user name : '{0}', user id : '{1}') after the user changed the profile Homepage url to: {2}, user was deleted and the name, email and IP Address are banned." .FormatWith(userName, this.currentUserID, this.HomePage.Text), EventLogTypes.SpamBotDetected); // Kill user if (!this.PageContext.CurrentForumPage.IsAdminPage) { var user = UserMembershipHelper.GetMembershipUserById(this.currentUserID); var userId = this.currentUserID; var userIp = new CombinedUserDataHelper(user, userId).LastIP; UserMembershipHelper.DeleteAndBanUser(this.currentUserID, user, userIp); } } } } } if (this.Weblog.Text.IsSet() && !ValidationHelper.IsValidURL(this.Weblog.Text.Trim())) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_WEBLOG"), MessageTypes.Warning); return; } if (this.MSN.Text.IsSet() && !ValidationHelper.IsValidEmail(this.MSN.Text)) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_MSN"), MessageTypes.Warning); return; } if (this.Xmpp.Text.IsSet() && !ValidationHelper.IsValidXmpp(this.Xmpp.Text)) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_XMPP"), MessageTypes.Warning); return; } if (this.ICQ.Text.IsSet() && !(ValidationHelper.IsValidEmail(this.ICQ.Text) || ValidationHelper.IsNumeric(this.ICQ.Text))) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_ICQ"), MessageTypes.Warning); return; } if (this.Facebook.Text.IsSet() && !ValidationHelper.IsValidURL(this.Facebook.Text)) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_FACEBOOK"), MessageTypes.Warning); return; } if (this.Google.Text.IsSet() && !ValidationHelper.IsValidURL(this.Google.Text)) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_GOOGLE"), MessageTypes.Warning); return; } string displayName = null; if (this.Get <YafBoardSettings>().EnableDisplayName && this.Get <YafBoardSettings>().AllowDisplayNameModification) { // Check if name matches the required minimum length if (this.DisplayName.Text.Trim().Length < this.Get <YafBoardSettings>().DisplayNameMinLength) { this.PageContext.AddLoadMessage( this.GetTextFormatted("USERNAME_TOOLONG", this.Get <YafBoardSettings>().DisplayNameMinLength), MessageTypes.Warning); return; } // Check if name matches the required minimum length if (this.DisplayName.Text.Length > this.Get <YafBoardSettings>().UserNameMaxLength) { this.PageContext.AddLoadMessage( this.GetTextFormatted("USERNAME_TOOLONG", this.Get <YafBoardSettings>().UserNameMaxLength), MessageTypes.Warning); return; } if (this.DisplayName.Text.Trim() != this.UserData.DisplayName) { if (this.Get <IUserDisplayName>().GetId(this.DisplayName.Text.Trim()).HasValue) { this.PageContext.AddLoadMessage( this.GetText("REGISTER", "ALREADY_REGISTERED_DISPLAYNAME"), MessageTypes.Warning); return; } displayName = this.DisplayName.Text.Trim(); } } if (this.UpdateEmailFlag) { var newEmail = this.Email.Text.Trim(); if (!ValidationHelper.IsValidEmail(newEmail)) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_EMAIL"), MessageTypes.Warning); return; } var userNameFromEmail = this.Get <MembershipProvider>().GetUserNameByEmail(this.Email.Text.Trim()); if (userNameFromEmail.IsSet() && userNameFromEmail != userName) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_EMAIL"), MessageTypes.Warning); return; } if (this.Get <YafBoardSettings>().EmailVerification) { this.SendEmailVerification(newEmail); } else { // just update the e-mail... try { UserMembershipHelper.UpdateEmail(this.currentUserID, this.Email.Text.Trim()); } catch (ApplicationException) { this.PageContext.AddLoadMessage( this.GetText("PROFILE", "DUPLICATED_EMAIL"), MessageTypes.Warning); return; } } } if (this.Interests.Text.Trim().Length > 400) { this.PageContext.AddLoadMessage( this.GetTextFormatted("FIELD_TOOLONG", this.GetText("CP_EDITPROFILE", "INTERESTS"), 400), MessageTypes.Warning); return; } if (this.Occupation.Text.Trim().Length > 400) { this.PageContext.AddLoadMessage( this.GetTextFormatted("FIELD_TOOLONG", this.GetText("CP_EDITPROFILE", "OCCUPATION"), 400), MessageTypes.Warning); return; } this.UpdateUserProfile(userName); // vzrus: We should do it as we need to write null value to db, else it will be empty. // Localizer currently treats only nulls. object language = null; object culture = this.Culture.SelectedValue; object theme = this.Theme.SelectedValue; object editor = this.ForumEditor.SelectedValue; if (this.Theme.SelectedValue.IsNotSet()) { theme = null; } if (this.ForumEditor.SelectedValue.IsNotSet()) { editor = null; } if (this.Culture.SelectedValue.IsNotSet()) { culture = null; } else { foreach (DataRow row in StaticDataHelper.Cultures() .Rows.Cast <DataRow>() .Where(row => culture.ToString() == row["CultureTag"].ToString())) { language = row["CultureFile"].ToString(); } } // save remaining settings to the DB LegacyDb.user_save( this.currentUserID, this.PageContext.PageBoardID, null, displayName, null, this.TimeZones.SelectedValue.ToType <int>(), language, culture, theme, editor, this.UseMobileTheme.Checked, null, null, null, this.DSTUser.Checked, this.HideMe.Checked, null); // vzrus: If it's a guest edited by an admin registry value should be changed DataTable dt = LegacyDb.user_list(this.PageContext.PageBoardID, this.currentUserID, true, null, null, false); if (dt.HasRows() && dt.Rows[0]["IsGuest"].ToType <bool>()) { LegacyDb.registry_save("timezone", this.TimeZones.SelectedValue, this.PageContext.PageBoardID); } // clear the cache for this user...) this.Get <IRaiseEvent>().Raise(new UpdateUserEvent(this.currentUserID)); this.Get <IDataCache>().Clear(); if (!this.PageContext.CurrentForumPage.IsAdminPage) { YafBuildLink.Redirect(ForumPages.cp_profile); } else { this._userData = null; this.BindData(); } }
/// <summary> /// Logins the or create user. /// </summary> /// <param name="request">The request.</param> /// <param name="parameters">The access token.</param> /// <param name="message">The message.</param> /// <returns>Returns if Login was successful or not</returns> public bool LoginOrCreateUser(HttpRequest request, string parameters, out string message) { if (!YafContext.Current.Get <YafBoardSettings>().AllowSingleSignOn) { message = YafContext.Current.Get <ILocalization>().GetText("LOGIN", "SSO_DEACTIVATED"); return(false); } var facebookUser = this.GetFacebookUser(request, parameters); // Check if username is null if (facebookUser.UserName.IsNotSet()) { facebookUser.UserName = facebookUser.Name; } // Check if user exists var userName = YafContext.Current.Get <MembershipProvider>().GetUserNameByEmail(facebookUser.Email); if (userName.IsNotSet()) { var userGender = 0; if (facebookUser.Gender.IsSet()) { switch (facebookUser.Gender) { case "male": userGender = 1; break; case "female": userGender = 2; break; } } // Create User if not exists?! return(this.CreateFacebookUser(facebookUser, userGender, out message)); } var yafUser = YafUserProfile.GetProfile(userName); var yafUserData = new CombinedUserDataHelper(YafContext.Current.Get <MembershipProvider>().GetUser(userName, true)); // Legacy Handling if (ValidationHelper.IsNumeric(yafUser.Facebook)) { if (!yafUser.Facebook.Equals(facebookUser.UserID)) { message = YafContext.Current.Get <ILocalization>().GetText("LOGIN", "SSO_FACEBOOK_FAILED"); return(false); } } if (!yafUser.FacebookId.Equals(facebookUser.UserID)) { message = YafContext.Current.Get <ILocalization>().GetText("LOGIN", "SSO_FACEBOOK_FAILED"); return(false); } YafSingleSignOnUser.LoginSuccess(AuthService.facebook, userName, yafUserData.UserID, true); message = string.Empty; return(true); }
/// <summary> /// The quick reply_ click. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void QuickReplyClick([NotNull] object sender, [NotNull] EventArgs e) { try { if (this.quickReplyEditor.Text.Length <= 0) { BoardContext.Current.PageElements.RegisterJsBlockStartup( "openModalJs", JavaScriptBlocks.OpenModalJs("QuickReplyDialog")); this.PageContext.AddLoadMessage(this.GetText("EMPTY_MESSAGE"), MessageTypes.warning); return; } // No need to check whitespace if they are actually posting something if (this.Get <BoardSettings>().MaxPostSize > 0 && this.quickReplyEditor.Text.Length >= this.Get <BoardSettings>().MaxPostSize) { BoardContext.Current.PageElements.RegisterJsBlockStartup( "openModalJs", JavaScriptBlocks.OpenModalJs("QuickReplyDialog")); this.PageContext.AddLoadMessage(this.GetText("ISEXCEEDED"), MessageTypes.warning); return; } if (this.EnableCaptcha() && !CaptchaHelper.IsValid(this.tbCaptcha.Text.Trim())) { BoardContext.Current.PageElements.RegisterJsBlockStartup( "openModalJs", JavaScriptBlocks.OpenModalJs("QuickReplyDialog")); this.PageContext.AddLoadMessage(this.GetText("BAD_CAPTCHA"), MessageTypes.warning); return; } if (!(this.PageContext.IsAdmin || this.PageContext.ForumModeratorAccess) && this.Get <BoardSettings>().PostFloodDelay > 0) { if (BoardContext.Current.Get <ISession>().LastPost > DateTime.UtcNow.AddSeconds(-this.Get <BoardSettings>().PostFloodDelay)) { BoardContext.Current.PageElements.RegisterJsBlockStartup( "openModalJs", JavaScriptBlocks.OpenModalJs("QuickReplyDialog")); this.PageContext.AddLoadMessage( this.GetTextFormatted( "wait", (BoardContext.Current.Get <ISession>().LastPost - DateTime.UtcNow.AddSeconds(-this.Get <BoardSettings>().PostFloodDelay)).Seconds), MessageTypes.warning); return; } } BoardContext.Current.Get <ISession>().LastPost = DateTime.UtcNow; // post message... object replyTo = -1; var message = this.quickReplyEditor.Text; long topicId = this.PageContext.PageTopicID; // SPAM Check // Check if Forum is Moderated var isForumModerated = false; var dt = this.GetRepository <Forum>().List( this.PageContext.PageBoardID, this.PageContext.PageForumID); var forumInfo = dt.FirstOrDefault(); if (forumInfo != null) { isForumModerated = this.CheckForumModerateStatus(forumInfo); } var spamApproved = true; var isPossibleSpamMessage = false; // Check for SPAM if (!this.PageContext.IsAdmin && !this.PageContext.ForumModeratorAccess && !this.Get <BoardSettings>().SpamServiceType.Equals(0)) { // Check content for spam if (this.Get <ISpamCheck>().CheckPostForSpam( this.PageContext.IsGuest ? "Guest" : this.PageContext.PageUserName, BoardContext.Current.Get <HttpRequestBase>().GetUserRealIPAddress(), this.quickReplyEditor.Text, this.PageContext.IsGuest ? null : this.PageContext.User.Email, out var spamResult)) { switch (this.Get <BoardSettings>().SpamMessageHandling) { case 0: this.Logger.Log( this.PageContext.PageUserID, "Spam Message Detected", $"Spam Check detected possible SPAM ({spamResult}) posted by User: {(this.PageContext.IsGuest ? "Guest" : this.PageContext.PageUserName)}", EventLogTypes.SpamMessageDetected); break; case 1: spamApproved = false; isPossibleSpamMessage = true; this.Logger.Log( this.PageContext.PageUserID, "Spam Message Detected", $"Spam Check detected possible SPAM ({spamResult}) posted by User: {(this.PageContext.IsGuest ? "Guest" : this.PageContext.PageUserName)}, it was flagged as unapproved post", EventLogTypes.SpamMessageDetected); break; case 2: this.Logger.Log( this.PageContext.PageUserID, "Spam Message Detected", $"Spam Check detected possible SPAM ({spamResult}) posted by User: {(this.PageContext.IsGuest ? "Guest" : this.PageContext.PageUserName)}, post was rejected", EventLogTypes.SpamMessageDetected); BoardContext.Current.PageElements.RegisterJsBlockStartup( "openModalJs", JavaScriptBlocks.OpenModalJs("QuickReplyDialog")); this.PageContext.AddLoadMessage(this.GetText("SPAM_MESSAGE"), MessageTypes.danger); return; case 3: this.Logger.Log( this.PageContext.PageUserID, "Spam Message Detected", $"Spam Check detected possible SPAM ({spamResult}) posted by User: {(this.PageContext.IsGuest ? "Guest" : this.PageContext.PageUserName)}, user was deleted and bannded", EventLogTypes.SpamMessageDetected); var userIp = new CombinedUserDataHelper( this.PageContext.CurrentUserData.Membership, this.PageContext.PageUserID).LastIP; this.Get <IAspNetUsersHelper>().DeleteAndBanUser( this.PageContext.PageUserID, this.PageContext.CurrentUserData.Membership, userIp); return; } } // Check posts for urls if the user has only x posts if (BoardContext.Current.CurrentUserData.NumPosts <= BoardContext.Current.Get <BoardSettings>().IgnoreSpamWordCheckPostCount && !this.PageContext.IsAdmin && !this.PageContext.ForumModeratorAccess) { var urlCount = UrlHelper.CountUrls(this.quickReplyEditor.Text); if (urlCount > this.PageContext.BoardSettings.AllowedNumberOfUrls) { spamResult = $"The user posted {urlCount} urls but allowed only {this.PageContext.BoardSettings.AllowedNumberOfUrls}"; switch (this.Get <BoardSettings>().SpamMessageHandling) { case 0: this.Logger.Log( this.PageContext.PageUserID, "Spam Message Detected", $"Spam Check detected possible SPAM ({spamResult}) posted by User: {(this.PageContext.IsGuest ? "Guest" : this.PageContext.PageUserName)}", EventLogTypes.SpamMessageDetected); break; case 1: spamApproved = false; isPossibleSpamMessage = true; this.Logger.Log( this.PageContext.PageUserID, "Spam Message Detected", $"Spam Check detected possible SPAM ({spamResult}) posted by User: {(this.PageContext.IsGuest ? "Guest" : this.PageContext.PageUserName)}, it was flagged as unapproved post", EventLogTypes.SpamMessageDetected); break; case 2: this.Logger.Log( this.PageContext.PageUserID, "Spam Message Detected", $"Spam Check detected possible SPAM ({spamResult}) posted by User: {(this.PageContext.IsGuest ? "Guest" : this.PageContext.PageUserName)}, post was rejected", EventLogTypes.SpamMessageDetected); BoardContext.Current.PageElements.RegisterJsBlockStartup( "openModalJs", JavaScriptBlocks.OpenModalJs("QuickReplyDialog")); this.PageContext.AddLoadMessage(this.GetText("SPAM_MESSAGE"), MessageTypes.danger); return; case 3: this.Logger.Log( this.PageContext.PageUserID, "Spam Message Detected", $"Spam Check detected possible SPAM ({spamResult}) posted by User: {(this.PageContext.IsGuest ? "Guest" : this.PageContext.PageUserName)}, user was deleted and bannded", EventLogTypes.SpamMessageDetected); var userIp = new CombinedUserDataHelper( this.PageContext.CurrentUserData.Membership, this.PageContext.PageUserID).LastIP; this.Get <IAspNetUsersHelper>().DeleteAndBanUser( this.PageContext.PageUserID, this.PageContext.CurrentUserData.Membership, userIp); return; } } } if (!this.PageContext.IsGuest) { this.UpdateWatchTopic(this.PageContext.PageUserID, this.PageContext.PageTopicID); } } // If Forum is Moderated if (isForumModerated) { spamApproved = false; } // Bypass Approval if Admin or Moderator if (this.PageContext.IsAdmin || this.PageContext.ForumModeratorAccess) { spamApproved = true; } var messageFlags = new MessageFlags { IsHtml = this.quickReplyEditor.UsesHTML, IsBBCode = this.quickReplyEditor.UsesBBCode, IsApproved = spamApproved }; // Bypass Approval if Admin or Moderator. var messageId = this.GetRepository <Message>().SaveNew( topicId, this.PageContext.PageUserID, message, null, this.Get <HttpRequestBase>().GetUserRealIPAddress(), DateTime.UtcNow, replyTo.ToType <int>(), messageFlags); // Check to see if the user has enabled "auto watch topic" option in his/her profile. if (this.PageContext.CurrentUserData.AutoWatchTopics) { var watchTopicId = this.GetRepository <WatchTopic>().Check( this.PageContext.PageUserID, this.PageContext.PageTopicID); if (!watchTopicId.HasValue) { // subscribe to this topic this.GetRepository <WatchTopic>().Add(this.PageContext.PageUserID, this.PageContext.PageTopicID); } } if (messageFlags.IsApproved) { // send new post notification to users watching this topic/forum this.Get <ISendNotification>().ToWatchingUsers(messageId.ToType <int>()); if (!this.PageContext.IsGuest && this.PageContext.CurrentUserData.Activity) { this.Get <IActivityStream>().AddReplyToStream( this.PageContext.PageForumID, this.PageContext.PageTopicID, messageId.ToType <int>(), this.PageContext.PageTopicName, message); } // redirect to newly posted message BuildLink.Redirect(ForumPages.Posts, "m={0}&#post{0}", messageId); } else { if (this.Get <BoardSettings>().EmailModeratorsOnModeratedPost) { // not approved, notify moderators this.Get <ISendNotification>().ToModeratorsThatMessageNeedsApproval( this.PageContext.PageForumID, messageId.ToType <int>(), isPossibleSpamMessage); } var url = BuildLink.GetLink(ForumPages.Topics, "f={0}", this.PageContext.PageForumID); BuildLink.Redirect(ForumPages.Info, "i=1&url={0}", this.Server.UrlEncode(url)); } } catch (Exception exception) { if (exception.GetType() != typeof(ThreadAbortException)) { this.Logger.Log(this.PageContext.PageUserID, this, exception); } } }
/// <summary> /// The get avatar url for user. /// </summary> /// <param name="userId"> /// The user id. /// </param> /// <returns> /// Returns the Avatar Url /// </returns> public string GetAvatarUrlForUser(int userId) { try { var userData = new CombinedUserDataHelper(userId); return this.GetAvatarUrlForUser(userData); } catch (Exception) { // Return NoAvatar Image if there something wrong with the user return "{0}images/noavatar.gif".FormatWith(YafForumInfo.ForumClientFileRoot); } }
/// <summary> /// The bind data. /// </summary> private void BindData() { MembershipUser user = null; try { user = UserMembershipHelper.GetMembershipUserById(this.UserId); } catch (Exception ex) { this.Get <ILogger>().Error(ex, this.UserId.ToString()); } if (user == null || user.ProviderUserKey.ToString() == "0") { // No such user exists or this is an nntp user ("0") YafBuildLink.AccessDenied(); } var userData = new CombinedUserDataHelper(user, this.UserId); // populate user information controls... // Is BuddyList feature enabled? if (this.Get <YafBoardSettings>().EnableBuddyList) { this.SetupBuddyList(this.UserId, userData); } else { // BuddyList feature is disabled. don't show any link. this.BuddyLi.Visible = false; this.BuddyListTab.Visible = false; this.lnkBuddy.Visible = false; this.ltrApproval.Visible = false; } // Is album feature enabled? if (this.Get <YafBoardSettings>().EnableAlbum) { this.AlbumList1.UserID = this.UserId; } else { this.AlbumList1.Dispose(); } var userNameOrDisplayName = this.HtmlEncode(this.Get <YafBoardSettings>().EnableDisplayName ? userData.DisplayName : userData.UserName); this.SetupUserProfileInfo(this.UserId, user, userData, userNameOrDisplayName); this.AddPageLinks(userNameOrDisplayName); this.SetupUserStatistics(userData); this.SetupUserLinks(userData, userNameOrDisplayName); this.SetupAvatar(this.UserId, userData); this.Groups.DataSource = RoleMembershipHelper.GetRolesForUser(userData.UserName); // EmailRow.Visible = PageContext.IsAdmin; this.ModerateTab.Visible = this.PageContext.IsAdmin || this.PageContext.IsForumModerator; this.ModerateLi.Visible = this.PageContext.IsAdmin || this.PageContext.IsForumModerator; this.AdminUserButton.Visible = this.PageContext.IsAdmin; if (this.LastPosts.Visible) { this.LastPosts.DataSource = LegacyDb.post_alluser(this.PageContext.PageBoardID, this.UserId, this.PageContext.PageUserID, 10) .AsEnumerable(); this.SearchUser.NavigateUrl = YafBuildLink.GetLinkNotEscaped( ForumPages.search, "postedby={0}", userNameOrDisplayName); } this.DataBind(); }
/// <summary> /// Saves the Updated Profile /// </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 UpdateProfileClick([NotNull] object sender, [NotNull] EventArgs e) { var userName = UserMembershipHelper.GetUserNameFromID(this.currentUserId); if (this.HomePage.Text.IsSet()) { // add http:// by default if (!Regex.IsMatch(this.HomePage.Text.Trim(), @"^(http|https|ftp|ftps|git|svn|news)\://.*")) { this.HomePage.Text = $"http://{this.HomePage.Text.Trim()}"; } if (!ValidationHelper.IsValidURL(this.HomePage.Text)) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_HOME"), MessageTypes.warning); return; } if (this.UserData.NumPosts < this.Get <YafBoardSettings>().IgnoreSpamWordCheckPostCount) { // Check for spam if (this.Get <ISpamWordCheck>().CheckForSpamWord(this.HomePage.Text, out _)) { // Log and Send Message to Admins if (this.Get <YafBoardSettings>().BotHandlingOnRegister.Equals(1)) { this.Logger.Log( null, "Bot Detected", $"Internal Spam Word Check detected a SPAM BOT: (user name : '{userName}', user id : '{this.currentUserId}') after the user changed the profile Homepage url to: {this.HomePage.Text}", EventLogTypes.SpamBotDetected); } else if (this.Get <YafBoardSettings>().BotHandlingOnRegister.Equals(2)) { this.Logger.Log( null, "Bot Detected", $"Internal Spam Word Check detected a SPAM BOT: (user name : '{userName}', user id : '{this.currentUserId}') after the user changed the profile Homepage url to: {this.HomePage.Text}, user was deleted and the name, email and IP Address are banned.", EventLogTypes.SpamBotDetected); // Kill user if (!this.PageContext.CurrentForumPage.IsAdminPage) { var user = UserMembershipHelper.GetMembershipUserById(this.currentUserId); var userId = this.currentUserId; var userIp = new CombinedUserDataHelper(user, userId).LastIP; UserMembershipHelper.DeleteAndBanUser(this.currentUserId, user, userIp); } } } } } if (this.Weblog.Text.IsSet() && !ValidationHelper.IsValidURL(this.Weblog.Text.Trim())) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_WEBLOG"), MessageTypes.warning); return; } if (this.Xmpp.Text.IsSet() && !ValidationHelper.IsValidXmpp(this.Xmpp.Text)) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_XMPP"), MessageTypes.warning); return; } if (this.ICQ.Text.IsSet() && !(ValidationHelper.IsValidEmail(this.ICQ.Text) || ValidationHelper.IsNumeric(this.ICQ.Text))) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_ICQ"), MessageTypes.warning); return; } if (this.Facebook.Text.IsSet() && !ValidationHelper.IsValidURL(this.Facebook.Text)) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "BAD_FACEBOOK"), MessageTypes.warning); return; } string displayName = null; if (this.Get <YafBoardSettings>().EnableDisplayName && this.Get <YafBoardSettings>().AllowDisplayNameModification) { // Check if name matches the required minimum length if (this.DisplayName.Text.Trim().Length < this.Get <YafBoardSettings>().DisplayNameMinLength) { this.PageContext.AddLoadMessage( this.GetTextFormatted("USERNAME_TOOLONG", this.Get <YafBoardSettings>().DisplayNameMinLength), MessageTypes.warning); return; } // Check if name matches the required minimum length if (this.DisplayName.Text.Length > this.Get <YafBoardSettings>().UserNameMaxLength) { this.PageContext.AddLoadMessage( this.GetTextFormatted("USERNAME_TOOLONG", this.Get <YafBoardSettings>().UserNameMaxLength), MessageTypes.warning); return; } if (this.DisplayName.Text.Trim() != this.UserData.DisplayName) { if (this.Get <IUserDisplayName>().GetId(this.DisplayName.Text.Trim()).HasValue) { this.PageContext.AddLoadMessage( this.GetText("REGISTER", "ALREADY_REGISTERED_DISPLAYNAME"), MessageTypes.warning); return; } displayName = this.DisplayName.Text.Trim(); } } if (this.Interests.Text.Trim().Length > 400) { this.PageContext.AddLoadMessage( this.GetTextFormatted("FIELD_TOOLONG", this.GetText("CP_EDITPROFILE", "INTERESTS"), 400), MessageTypes.warning); return; } if (this.Occupation.Text.Trim().Length > 400) { this.PageContext.AddLoadMessage( this.GetTextFormatted("FIELD_TOOLONG", this.GetText("CP_EDITPROFILE", "OCCUPATION"), 400), MessageTypes.warning); return; } this.UpdateUserProfile(userName); // save remaining settings to the DB this.GetRepository <User>().Save( this.currentUserId, this.PageContext.PageBoardID, null, displayName, null, this.UserData.TimeZoneInfo.Id, this.UserData.LanguageFile, this.UserData.CultureUser, this.UserData.ThemeFile, this.UserData.TextEditor, null, null, null, false, this.UserData.IsActiveExcluded, null); // clear the cache for this user...) this.Get <IRaiseEvent>().Raise(new UpdateUserEvent(this.currentUserId)); this.Get <IDataCache>().Clear(); if (!this.PageContext.CurrentForumPage.IsAdminPage) { YafBuildLink.Redirect(ForumPages.cp_profile); } else { this.userData = null; this.BindData(); } }
/// <summary> /// The get avatar url for user. /// </summary> /// <param name="userId"> /// The user id. /// </param> /// <returns> /// Returns the Avatar Url /// </returns> public string GetAvatarUrlForUser(int userId) { var userData = new CombinedUserDataHelper(userId); return(this.GetAvatarUrlForUser(userData)); }
/// <summary> /// The current_ after init. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> private void Current_AfterInit([NotNull] object sender, [NotNull] EventArgs e) { YafContext.Current.Vars["IsMobile"] = false; // see if this is a mobile device... if (!UserAgentHelper.IsMobileDevice(this.HttpRequestBase.UserAgent) && !this.HttpRequestBase.Browser.IsMobileDevice) { // make sure to shut off mobile theme usage if the user agent is not mobile. if (this.YafSession.UseMobileTheme ?? false) { this.YafSession.UseMobileTheme = false; } return; } if (!YafContext.Current.IsGuest) { // return if the user has mobile themes shut off in their profile. var userData = new CombinedUserDataHelper(YafContext.Current.PageUserID); if (!userData.UseMobileTheme) { return; } } this.UpdateUseMobileThemeFromQueryString(); // use the mobile theme? var useMobileTheme = this.YafSession.UseMobileTheme ?? true; // get the current mobile theme... var mobileTheme = YafContext.Current.BoardSettings.MobileTheme; if (mobileTheme.IsSet()) { // create a new theme object... var theme = new YafTheme(mobileTheme); // make sure it's valid... if (YafTheme.IsValidTheme(theme.ThemeFile)) { YafContext.Current.Vars["IsMobile"] = true; // set new mobile theme... if (useMobileTheme) { YafContext.Current.Get<ThemeProvider>().Theme = theme; this.YafSession.UseMobileTheme = true; } return; } } // make sure to shut off mobile theme usage if there was no valid mobile theme found... if (this.YafSession.UseMobileTheme ?? false) { this.YafSession.UseMobileTheme = false; } }
/// <summary> /// The bind data. /// </summary> private void BindData() { MembershipUser user = UserMembershipHelper.GetMembershipUserById(this.UserId); if (user == null || user.ProviderUserKey.ToString() == "0") { YafBuildLink.AccessDenied(/*No such user exists or this is an nntp user ("0") */); } var userData = new CombinedUserDataHelper(user, this.UserId); // populate user information controls... // Is BuddyList feature enabled? if (YafContext.Current.BoardSettings.EnableBuddyList) { this.SetupBuddyList(this.UserId, userData); } else { // BuddyList feature is disabled. don't show any link. this.lnkBuddy.Visible = false; this.ltrApproval.Visible = false; } // Is album feature enabled? if (YafContext.Current.BoardSettings.EnableAlbum) { this.AlbumList1.UserID = this.UserId; } else { this.AlbumList1.Dispose(); } string userDisplayName = this.PageContext.UserDisplayName.GetName(this.UserId); this.SetupUserProfileInfo(this.UserId, user, userData, userDisplayName); this.AddPageLinks(userDisplayName); this.SetupUserStatistics(userData); // private messages this.SetupUserLinks(userData); // localize tab titles... this.LocalizeTabTitles(this.UserId); this.SetupAvatar(this.UserId, userData); this.Groups.DataSource = RoleMembershipHelper.GetRolesForUser(UserMembershipHelper.GetUserNameFromID(this.UserId)); // EmailRow.Visible = PageContext.IsAdmin; this.ProfileTabs.Views["ModerateTab"].Visible = this.PageContext.IsAdmin || this.PageContext.IsForumModerator; this.ProfileTabs.Views["ModerateTab"].Text = this.GetText("MODERATION"); this.AdminUserButton.Visible = this.PageContext.IsAdmin; if (this.LastPosts.Visible) { this.LastPosts.DataSource = DB.post_alluser(this.PageContext.PageBoardID, this.UserId, this.PageContext.PageUserID, 10).AsEnumerable(); this.SearchUser.NavigateUrl = YafBuildLink.GetLinkNotEscaped(ForumPages.search, "postedby={0}", userDisplayName); } this.DataBind(); }