using PageAdmin.BLL;
using PageAdmin.Utils;
using PageAdmin.Web.Filter;
using System.Web.Mvc;

namespace PageAdmin.Web.Areas.E.Controllers
{

    /// <summary>
    /// 获取当前登录用户UserToken
    /// </summary>
    public class GetUserTokenController : Controller
    {
        /// <summary>
        /// 获取当前登录的UserToken，只能通过jsonp获取到
        /// </summary>
        /// <returns></returns>

        [HttpGet]
        public string Index()
        {
            var callBackName = Request.QueryString["callback"];
            string token = CookieHelper.Get("UserToken");
            if(!string.IsNullOrEmpty(token))
            {
                LoginingUseBLL loginingUseBLL = new LoginingUseBLL();
                var currentUser=loginingUseBLL.GetUserByToken(token);
                if(currentUser==null)
                {
                    token = "";
                    CookieHelper.Remove("UserToken");
                }
            }
            return callBackName+"(\""+token+"\")";
        }


    }
}