using System;
namespace Stat.web
{
    /// <summary>
    /// 
    /// </summary>
    public partial class UserLogin : System.Web.UI.Page
    {
        Stat.Cache.IConfig config = Stat.Cache.CacheFatory.CreateConfig();
        Stat.Security.ISecurity security = Stat.Security.DataFatory.CreateSecurity();
        string txtUserName = "", txtUserPwd = "", txtCheckCode = "";
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            txtUserName = Plugin.Common.Rq("txtUserName");
            txtUserPwd = Plugin.Common.Rq("txtUserPwd");
            txtCheckCode = Plugin.Common.Rq("txtCheckCode");

            Ulogin();
        }
        /// <summary>
        /// 用户登陆
        /// </summary> 
        private void Ulogin()
        {
            if (!config.IsAllowUserLogin())
            {
                Plugin.Common.Alert_Top("温馨提示：系统暂时关闭用户登录！", "/default.aspx");
                return;
            }
            if (!security.CheckCode("CheckCode", txtCheckCode)) { return; }
            if (!CheckForm()) { return; }
            //系统登陆
            Stat.Model.Users model = new Stat.Model.Users();
            model.UserName = txtUserName;
            model.UserPwd = txtUserPwd;
            if (security.Login(model))
            {

                if (security.IsMaster())
                {
                    Response.Redirect("Manager/Main.Aspx");

                }
                else if (security.IsUser())
                {
                    Response.Redirect("v/WebsiteList.aspx");
                }
                Response.End();
            }
            else
            {
                Plugin.Common.HistoryGo(-1);
            }
        }
        /// <summary>
        /// 检查表单
        /// </summary>
        private bool CheckForm()
        {
            string message = "";
            //系统登陆
            if (txtUserName.Equals("") || txtUserPwd.Equals(""))
            {
                message = "温馨提示：用户名或者密码为空";
                Plugin.Common.Alert_Top(message, "/default.aspx");
                return false;
            }
            return true;
        }
    }
}
