Beispiel #1
0
 /// <summary>
 ///  处理用户登录请求
 /// </summary>
 /// <param name="context"></param>
 public static void Login(HttpContext context)
 {
    string name = context.Request.Form["n"];
    string pwd = context.Request.Form["p"];
    if (UserAccount.Login(name, pwd))
    {
       string from = QA.GetCookie(SC.CK_LOGIN_FROM);
       if (from == null || from.Contains("login")) from = "/home";
       context.Response.Write(JU.Build(true, from));
    }
    else context.Response.Write(JU.Build(false, ""));
 }
Beispiel #2
0
        /// <summary>
        ///  用户登录
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        public static bool Login(string name, string pwd)
        {
            UserEntity entity = null;

            pwd = MU.MD5(pwd);
            try
            {
                if (name.Contains("@"))
                {
                    entity = UserData.LoginByEmail(name, pwd);
                }
                else
                {
                    entity = UserData.LoginByName(name, pwd);
                }

                //write cookie
                if (entity != null)
                {
                    CacheService.Add(CNC.ACCOUNT_ENTITY_ID + entity.id, entity);
                    string id = entity.id.ToString(); // id 仅作内部使用,不对外公开
                    QA.SetCookie(FormsAuthentication.FormsCookieName,
                                 FormsAuthentication.Encrypt(new FormsAuthenticationTicket(1, id, DateTime.Now, DateTime.MaxValue, true, id, FormsAuthentication.FormsCookiePath))
                                 , DateTime.MaxValue); //设置永久保留登录信息,之后版本可考虑进行配置

                    QA.SetCookie(SC.CN.A_NAME, HttpUtility.UrlEncode(entity.name), DateTime.MaxValue);
                    string cookie = QA.GetCookie(SC.CN.FROM);

                    //TODO: write log,add to task.
                    Log.Login(entity);
                }
            }
            catch { }

            return(entity != null);
        }