-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathProfileView.aspx.cs
More file actions
290 lines (254 loc) · 7.82 KB
/
ProfileView.aspx.cs
File metadata and controls
290 lines (254 loc) · 7.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
using System;
using System.Globalization;
using mojoPortal.Business;
using mojoPortal.Business.WebHelpers;
using mojoPortal.Web.Configuration;
using mojoPortal.Web.Framework;
using Resources;
namespace mojoPortal.Web.UI.Pages;
public partial class ProfileView : NonCmsBasePage
{
private Guid userGuid = Guid.Empty;
private int userID = -1;
private Double timeOffset = 0;
private TimeZoneInfo timeZone = null;
private Avatar.RatingType MaxAllowedGravatarRating = SiteUtils.GetMaxAllowedGravatarRating();
private bool allowGravatars = false;
private bool disableAvatars = true;
private string avatarPath = string.Empty;
private SiteUser siteUser = null;
private bool allowView = false;
protected string allowedImageUrlRegexPattern = SecurityHelper.RegexRelativeImageUrlPatern;
#region OnInit
override protected void OnInit(EventArgs e)
{
base.OnInit(e);
Load += new EventHandler(Page_Load);
SuppressMenuSelection();
SuppressPageMenu();
}
#endregion
private void Page_Load(object sender, EventArgs e)
{
LoadSettings();
if (!allowView)
{
if (!Request.IsAuthenticated)
{
SiteUtils.RedirectToLoginPage(this);
return;
}
else
{
WebUtils.SetupRedirect(this, SiteRoot);
return;
}
}
PopulateControls();
}
private void PopulateControls()
{
if (siteUser != null)
{
lblCreatedDate.Text = siteUser.DateCreated.AddHours(timeOffset).ToString();
lblTotalPosts.Text = siteUser.TotalPosts.ToString(CultureInfo.InvariantCulture);
lblUserName.Text = Server.HtmlEncode(siteUser.Name);
Title = SiteUtils.FormatPageTitle(siteSettings, string.Format(CultureInfo.InvariantCulture,
Resource.PageTitleFormatProfilePage, Server.HtmlEncode(siteUser.Name)));
MetaDescription = string.Format(CultureInfo.InvariantCulture,
Resource.ProfileViewMetaFormat, Server.HtmlEncode(siteUser.Name));
userAvatar.UseGravatar = allowGravatars;
userAvatar.Email = siteUser.Email;
userAvatar.UserName = siteUser.Name;
userAvatar.UserId = siteUser.UserId;
userAvatar.AvatarFile = siteUser.AvatarUrl;
userAvatar.MaxAllowedRating = MaxAllowedGravatarRating;
userAvatar.Disable = disableAvatars;
userAvatar.SiteId = siteSettings.SiteId;
userAvatar.UseLink = false;
if (disableAvatars) { divAvatar.Visible = false; }
lnkUserPosts.UserId = siteUser.UserId;
lnkUserPosts.TotalPosts = siteUser.TotalPosts;
if (siteUser.TimeZoneId.Length > 0)
{
TimeZoneInfo userTz = SiteUtils.GetTimeZone(siteUser.TimeZoneId);
if (userTz != null)
{
pnlTimeZone.Visible = true;
if (userTz.IsDaylightSavingTime(DateTime.UtcNow))
{
lblTimeZone.Text = userTz.DaylightNameWithOffset();
}
else
{
lblTimeZone.Text = userTz.DisplayName;
}
}
}
if (AppConfig.MultiTenancy.RelatedSites.Enabled)
{
// this can't be used in related site mode
// because we can't assume forum posts were in this site.
divForumPosts.Visible = false;
}
if (Request.IsAuthenticated)
{
ShowAuthenticatedProperties(siteUser);
}
else
{
ShowAnonymousProperties(siteUser);
}
}
else
{
lblUserName.Text = Resource.UserNotFound;
divAvatar.Visible = false;
}
}
private void LoadSettings()
{
UntrustedContent2.TrustedImageUrlPattern = allowedImageUrlRegexPattern;
allowView = WebUser.IsInRoles(siteSettings.RolesThatCanViewMemberList);
userID = WebUtils.ParseInt32FromQueryString("userid", true, userID);
timeOffset = SiteUtils.GetUserTimeOffset();
timeZone = SiteUtils.GetUserTimeZone();
userGuid = WebUtils.ParseGuidFromQueryString("u", Guid.Empty);
if (userID > -1)
{
siteUser = new SiteUser(siteSettings, userID);
if (siteUser.UserGuid == Guid.Empty) { siteUser = null; }
}
else if (userGuid != Guid.Empty)
{
siteUser = new SiteUser(siteSettings, userGuid);
if (siteUser.UserGuid == Guid.Empty) { siteUser = null; }
}
switch (siteSettings.AvatarSystem)
{
case "gravatar":
allowGravatars = true;
disableAvatars = false;
break;
case "internal":
allowGravatars = false;
disableAvatars = false;
break;
case "none":
default:
allowGravatars = false;
disableAvatars = true;
break;
}
if (displaySettings.OverrideAvatarLabel.Length > 0)
{
lblAvatar.ConfigKey = displaySettings.OverrideAvatarLabel;
}
if (displaySettings.HidePostCount) { divForumPosts.Visible = false; }
AddClassToBody("profileview");
}
private void ShowAuthenticatedProperties(SiteUser siteUser)
{
mojoProfileConfiguration profileConfig = mojoProfileConfiguration.GetConfig();
if (profileConfig != null)
{
foreach (mojoProfilePropertyDefinition propertyDefinition in profileConfig.PropertyDefinitions)
{
// we are using the new TimeZoneInfo list but it doesn't work under Mono
// this makes us skip the TimeOffsetHours setting from mojoProfile.config which is not used under windows
if (propertyDefinition.Name == mojoProfilePropertyDefinition.TimeOffsetHoursKey) { continue; }
// we allow this to be configured as a profile property so it can be required for registration
// but we don't need to load it here because we have a dedicated control for the property already
if (propertyDefinition.Name == mojoProfilePropertyDefinition.TimeZoneIdKey) { continue; }
if (propertyDefinition.VisibleToAuthenticated
&& (
(propertyDefinition.OnlyAvailableForRoles.Length == 0)
|| (siteUser.IsInRoles(propertyDefinition.OnlyAvailableForRoles))
)
&& (
(propertyDefinition.OnlyVisibleForRoles.Length == 0)
|| (WebUser.IsInRoles(propertyDefinition.OnlyVisibleForRoles))
)
)
{
object propValue = siteUser.GetProperty(propertyDefinition.Name, propertyDefinition.SerializeAs, propertyDefinition.LazyLoad);
if (propValue != null)
{
mojoProfilePropertyDefinition.SetupReadOnlyPropertyControl(
pnlProfileProperties,
propertyDefinition,
propValue.ToString(),
timeOffset,
timeZone);
}
else
{
mojoProfilePropertyDefinition.SetupReadOnlyPropertyControl(
pnlProfileProperties,
propertyDefinition,
propertyDefinition.DefaultValue,
timeOffset,
timeZone);
}
}
}
}
}
private void ShowAnonymousProperties(SiteUser siteUser)
{
bool wouldSeeMoreIfAuthenticated = false;
mojoProfileConfiguration profileConfig = mojoProfileConfiguration.GetConfig();
if (profileConfig != null)
{
foreach (mojoProfilePropertyDefinition propertyDefinition in profileConfig.PropertyDefinitions)
{
if (propertyDefinition.VisibleToAnonymous
&& (propertyDefinition.OnlyVisibleForRoles.Length == 0)
&& (
(propertyDefinition.OnlyAvailableForRoles.Length == 0)
|| (siteUser.IsInRoles(propertyDefinition.OnlyAvailableForRoles))
)
)
{
object propValue = siteUser.GetProperty(propertyDefinition.Name, propertyDefinition.SerializeAs, propertyDefinition.LazyLoad);
if (propValue != null)
{
mojoProfilePropertyDefinition.SetupReadOnlyPropertyControl(
pnlProfileProperties,
propertyDefinition,
propValue.ToString(),
timeOffset,
timeZone);
}
else
{
mojoProfilePropertyDefinition.SetupReadOnlyPropertyControl(
pnlProfileProperties,
propertyDefinition,
propertyDefinition.DefaultValue,
timeOffset,
timeZone);
}
}
else
{
if (
propertyDefinition.VisibleToAuthenticated
&& (propertyDefinition.OnlyVisibleForRoles.Length == 0)
&& (
(propertyDefinition.OnlyAvailableForRoles.Length == 0)
|| (siteUser.IsInRoles(propertyDefinition.OnlyAvailableForRoles))
)
)
{
wouldSeeMoreIfAuthenticated = true;
}
}
}
}
if (wouldSeeMoreIfAuthenticated)
{
lblMessage.Text = ProfileResource.WouldSeeMoreIfAuthenticatedMessage;
}
}
}