Beispiel #1
0
            public string GetValue(string tokenText, DataRow row, string sourceColumn, string sourceType)
            {
                PropertySource.Clear();
                switch (sourceType.ToLowerInvariant())
                {
                    case "createdby":
                    case "changedby":
                    case "userlink":
                        var userInfo = ((IUserSource) (ByName(sourceType))).GetUser(sourceColumn, row);
                        if (userInfo == null)
                        {
                            return "";
                        }
                        PropertySource["user"] = userInfo;
                        PropertySource["profile"] = new ProfilePropertyAccess(userInfo);
                        break;
                    case "download":
                    case "url":
                    case "image":
                        var strFileId = row[sourceColumn + DataTableColumn.Appendix_Original].AsString();
                        if (strFileId != string.Empty)
                        {
                            PropertySource["file"] = new DownloadPropertyAccess(strFileId,
                                                                                Globals.GetPortalSettings().PortalId,
                                                                                _moduleId);
                        }
                        break;
                    default:
                        if ((ByName(sourceType)) is IEmailAdressSource)
                        {
                            var email = ((IEmailAdressSource) (ByName(sourceType))).GetEmailAddress(sourceColumn, row);
                            if (! string.IsNullOrEmpty(email))
                            {
                                PropertySource["gravatar"] = new GravatarPropertyAccess(email);
                            }
                        }
                        else
                        {
                            return "";
                        }
                        break;
                }

                return ReplaceTokens(tokenText);
            }
		/// <summary>
		///   Page_Load runs when the control is loaded
		/// </summary>
		/// <remarks>
		/// </remarks>
		protected override void OnLoad(EventArgs e)
		{
			base.OnLoad(e);

			try
			{
                if(Null.IsNull(ProfileUserId))
                {
                    Visible = false;
                    return;
                }

                var template = Convert.ToString(ModuleContext.Settings["ProfileTemplate"]);
                if(string.IsNullOrEmpty(template))
                {
                    template = Localization.GetString("DefaultTemplate", LocalResourceFile);
                }
			    var editUrl = Globals.NavigateURL(ModuleContext.PortalSettings.ActiveTab.TabID, "Profile", "userId=" + ProfileUserId, "pageno=1");
                var profileUrl = Globals.NavigateURL(ModuleContext.PortalSettings.ActiveTab.TabID, "Profile", "userId=" + ProfileUserId, "pageno=2");

                if (template.Contains("[BUTTON:EDITPROFILE]"))
                {
                    if (IncludeButton && IsUser)
                    {
                        string editHyperLink = String.Format("<a href=\"{0}\" class=\"dnnPrimaryAction\">{1}</a>", profileUrl, LocalizeString("Edit"));
                        template = template.Replace("[BUTTON:EDITPROFILE]", editHyperLink);
                    }
                    buttonPanel.Visible = false;
                }
                else
                {
                    buttonPanel.Visible = IncludeButton;
                    editLink.NavigateUrl = editUrl;
                }
                if (template.Contains("[HYPERLINK:EDITPROFILE]"))
                {
                    if (IsUser)
                    {
                        string editHyperLink = String.Format("<a href=\"{0}\" class=\"dnnSecondaryAction\">{1}</a>", profileUrl, LocalizeString("Edit"));
                        template = template.Replace("[HYPERLINK:EDITPROFILE]", editHyperLink);
                    }
                }
                if (template.Contains("[HYPERLINK:MYACCOUNT]"))
                {
                    if (IsUser)
                    {
                        string editHyperLink = String.Format("<a href=\"{0}\" class=\"dnnSecondaryAction\">{1}</a>", editUrl, LocalizeString("MyAccount"));
                        template = template.Replace("[HYPERLINK:MYACCOUNT]", editHyperLink);
                    }
                    buttonPanel.Visible = false;
                }

                if (!IsUser && buttonPanel.Visible)
                {
                    buttonPanel.Visible = false;
                }

			    if (ProfileUser.Profile.ProfileProperties.Cast<ProfilePropertyDefinition>().Count(profProperty => profProperty.Visible) == 0)
                {
                    noPropertiesLabel.Visible = true;
                    profileOutput.Visible = false;
                }
                else
                {
                    var token = new TokenReplace { User = ProfileUser, AccessingUser = ModuleContext.PortalSettings.UserInfo };
                    profileOutput.InnerHtml = token.ReplaceEnvironmentTokens(template);
                    noPropertiesLabel.Visible = false;
                    profileOutput.Visible = true;
                }

			    var propertyAccess = new ProfilePropertyAccess(ProfileUser);
                var profileResourceFile = "~/DesktopModules/Admin/Security/App_LocalResources/Profile.ascx";
                StringBuilder sb = new StringBuilder();
                bool propertyNotFound = false;

                foreach (ProfilePropertyDefinition property in ProfileUser.Profile.ProfileProperties)
                {
                    string value = propertyAccess.GetProperty(property.PropertyName,
                                                              String.Empty,
                                                              Thread.CurrentThread.CurrentUICulture,
                                                              ModuleContext.PortalSettings.UserInfo,
                                                              Scope.DefaultSettings,
                                                              ref propertyNotFound);


                    var clientName = Localization.GetSafeJSString(property.PropertyName);
                    sb.Append("self['" + clientName + "'] = ko.observable(");
                    sb.Append("\"");
                    value = Localization.GetSafeJSString(Server.HtmlDecode(value));
                    value = value.Replace("\r", string.Empty).Replace("\n",  " ");
                    sb.Append(value + "\"" + ");");
                    sb.Append('\n');
                    sb.Append("self['" + clientName + "Text'] = '");
                    sb.Append(clientName + "';");
                    sb.Append('\n');
                }

			    string email = (ProfileUserId == ModuleContext.PortalSettings.UserId
			                    || ModuleContext.PortalSettings.UserInfo.IsInRole(ModuleContext.PortalSettings.AdministratorRoleName))
			                       ? ProfileUser.Email
			                       : String.Empty;

                sb.Append("self.Email = ko.observable('");
                sb.Append(email + "');");
                sb.Append('\n');
                sb.Append("self.EmailText = '");
                sb.Append(LocalizeString("Email") + "';");
                sb.Append('\n');


                ProfileProperties = sb.ToString();


			}
			catch (Exception exc)
			{
				//Module failed to load
				Exceptions.ProcessModuleLoadException(this, exc);
			}
		}
        /// <summary>
        /// setup context by creating appropriate objects
        /// </summary>
        /// <history>
        /// /08/10/2007 sCullmann created
        /// </history>
        /// <remarks >
        /// security is not the purpose of the initialization, this is in the responsibility of each property access class
        /// </remarks>
        private void InitializePropertySources()
        {
            //Cleanup, by default "" is returned for these objects and any property
            IPropertyAccess DefaultPropertyAccess = new EmptyPropertyAccess();
            PropertySource["portal"] = DefaultPropertyAccess;
            PropertySource["tab"] = DefaultPropertyAccess;
            PropertySource["host"] = DefaultPropertyAccess;
            PropertySource["module"] = DefaultPropertyAccess;
            PropertySource["user"] = DefaultPropertyAccess;
            PropertySource["membership"] = DefaultPropertyAccess;
            PropertySource["profile"] = DefaultPropertyAccess;

            //initialization
            if (CurrentAccessLevel >= Scope.Configuration) {
                if (PortalSettings != null) {
                    PropertySource["portal"] = PortalSettings;
                    PropertySource["tab"] = PortalSettings.ActiveTab;
                }
                PropertySource["host"] = new HostPropertyAccess();
                if (ModuleInfo != null) {
                    PropertySource["module"] = ModuleInfo;
                }
            }
            if (CurrentAccessLevel >= Scope.DefaultSettings && !(User == null || User.UserID == -1)) {
                PropertySource["user"] = User;
                PropertySource["membership"] = new MembershipPropertyAccess(User);
                PropertySource["profile"] = new ProfilePropertyAccess(User);
            }
        }