예제 #1
0
 /// <summary>
 /// 用户登录并跳转(url为空时根据地址ReturnUrl串返回登录前的页面)
 /// </summary>
 /// <param name="page">传入Page实例</param>
 /// <param name="userName">用户名</param>
 /// <param name="password">密码</param>
 /// <param name="rememberMe">是否"记住我"</param>
 /// <param name="timeout">登录超时(单位分钟)</param>
 /// <param name="roleNameList">允许登录的用户权限列表</param>
 /// <param name="url">跳转页面</param>
 public static void Login(System.Web.UI.Page page, string userName, string password, bool rememberMe, int timeout, string url, List<string> roleNameList)
 {
     UserInfoExt bllUserInfo = new UserInfoExt();
     UserRolesExt bllUserRoles = new UserRolesExt();
     Model.UserInfo modelUserInfo = bllUserInfo.GetUserByName(userName);
     string curRoleName = bllUserRoles.GetRoleNameByID(modelUserInfo.RoleID);
     if (!ValidateUserPassword(userName, password))
     {
         lv_Common.MessageBox.Show(page, "用户名或密码错误!");
     }
     else if (modelUserInfo.ApprovedState != (int)TypeEnum.UserApprovedState.已审核)
     {
         lv_Common.MessageBox.Show(page, "你没有登录权限!");
     }
     else if (roleNameList != null && !roleNameList.Contains(curRoleName))
     {
         lv_Common.MessageBox.Show(page, "你没有访问权限!");
     }
     else
     {
         RegisterTicket(userName, rememberMe, timeout);
         if (string.IsNullOrEmpty(url))
         {
             if (page.Request["ReturnUrl"] != null)
                 url = page.Request["ReturnUrl"];
             else
                 url = "~/inde.aspx";
         }
         page.Response.Redirect(url);
     }
 }
예제 #2
0
 public void ProcessRequest(HttpContext context)
 {
     string email = context.Request["Email"];
     string user = context.Request["User"];
     if (user != null && user != "")
     {
         Model.UserInfo modelUserInfo = new Model.UserInfo();
         UserInfoExt bllUserInfo = new UserInfoExt();
         modelUserInfo = bllUserInfo.GetUserByName(user);
         if (email == modelUserInfo.Email)
         {
             context.Response.Write("yes");
         }
         else
         {
             context.Response.Write("no");
         }
     }
 }
예제 #3
0
 /// <summary>
 /// 完成身份验证
 /// </summary>
 /// <param name="page">传入Page实例</param>
 /// <param name="userName">用户名</param>
 /// <param name="rememberMe">是否"记住我"</param>
 /// <param name="timeout">登录超时(单位分钟)</param>
 public static void RegisterTicket(string userName, bool rememberMe, int timeout)
 {
     UserInfoExt bllUserInfo = new UserInfoExt();
     Model.UserInfo modelUserInfo = bllUserInfo.GetUserByName(userName);
     FormsAuthentication.SetAuthCookie(userName, true, FormsAuthentication.FormsCookiePath);
     FormsAuthenticationTicket Ticket = new FormsAuthenticationTicket(userName, rememberMe, timeout);
     string HashTicket = FormsAuthentication.Encrypt(Ticket);
     HttpCookie UserCookie = new HttpCookie(FormsAuthentication.FormsCookieName, HashTicket);
     HttpContext.Current.Response.Cookies.Add(UserCookie);
     modelUserInfo.LastLoginDate = DateTime.Now;
     bllUserInfo.Update(modelUserInfo);
 }