//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using CommunityServer.Controls;
using CommunityServer.Components;
using CommunityServer.Reader.Components;

namespace CommunityServer.Reader.Controls
{
	/// <summary>
	/// Summary description for FeedReaderTemplatedWebControl.
	/// </summary>
	public abstract class FeedReaderTemplatedWebControl : TemplatedWebControl
	{

		#region Constructor(s)

		public FeedReaderTemplatedWebControl() : base()
		{
			//_currentUser = Users.GetUser(true);
			
		}

		#endregion

		#region Properties

        protected override void OnLoad(EventArgs e)
        {
            Authorize();

            base.OnLoad (e);
            
            if(Context.Items["SetReaderLocation"] == null)
            {
                UsersOnline.SetLocation("My Feeds", null);
                Context.Items["SetReaderLocation"] = true;
            }
        }

        /// <summary>
        /// By default, checks to see if a blog exists and if the user has read access
        /// </summary>
        protected virtual void Authorize()
        {
			Feeds.UserAccessCheck();

            if(Context.Items["ReaderAccess"] == null)
            {
            	CSContext cntx = CSContext.Current;
            	if(!ReaderConfiguration.ValidateUser(cntx.User))
                    throw new CSException(CSExceptionType.AccessDenied,"Reader Access Denied to " + cntx.User.Username);
                
                Context.Items["ReaderAccess"] = true;

            }
        }


		protected override String ExternalSkinFileName
		{
			get { return string.Format("/Reader/Skin-{0}.ascx", this.GetType().Name); }
		}

//		public virtual User CurrentUser
//		{
//			get { return _currentUser; }
//		}

		#endregion
        		
	}
}
