public override void DoRequest(HttpContext ctx) { var action = QueryStringVal.Action; if (string.IsNullOrEmpty(action)) action = FormVal.Action; switch (action) { case "login": SystemUser user = new SystemUser(); var message = SystemUserLogic.Login(FormVal.UserId,FormVal.Password,"127.0.0.1",out user); var result = new AjaxResult(); if (string.IsNullOrEmpty(message)) { result.Success = true; SessionVal.UserId = FormVal.UserId; } else { result.Success = false; result.Message = message; } ctx.Response.Write(result.ToString()); break; case "checklogin": ctx.Response.Write(new AjaxResult { Success = !string.IsNullOrEmpty(SessionVal.UserId) }.ToString()); break; } ctx.Response.End(); }
/// <summary> /// 登录 /// </summary> /// <param name="loginName">登录用户名</param> /// <param name="loginPwd">登录密码</param> /// <param name="IP">登录IP</param> /// <returns>返回值为空,则登录成功;否则登录失败,返回值为失败信息。</returns> public static string Login(string loginName, string loginPwd, string IP, out SystemUser user) { string result = ""; loginPwd = MD5Encrypt.MD5Encrypt32(loginPwd); user = SystemUserDA.Login(loginName, loginPwd); if (user != null && user.SysNo > 0) { if (user.Status != SystemUserStatus.Valid) { result = "登录失败,帐号无效。"; } else { SystemUserDA.UpdateLoginInfo(user.SysNo, IP); } } else { result = "登录失败,用户名或密码错误。"; } return result; }
public void TestLogin() { string result = ""; SystemUser user = new SystemUser(); result = SystemUserLogic.Login("admin", "123", "127.0.0.1", out user); }