Ejemplo n.º 1
0
        public ActionResult LogOn(Reception_UserInfo model, string returnUrl)
        {
            if (string.IsNullOrWhiteSpace(model.Name))
            {
                ModelState.AddModelError("", "登录名不能为空");
                return(View(model));
            }
            if (string.IsNullOrWhiteSpace(model.Pwd))
            {
                ModelState.AddModelError("", "密码不能为空");
                return(View(model));
            }
            // 如果验证不通过
            if (!_reception_UserInfoService.ValidationUser(model))
            {
                ModelState.AddModelError("", "用户名密码不正确");
                return(View(model));
            }
            FormsAuthentication.SetAuthCookie(model.Name, false);

            var _user = _reception_UserInfoService.GetUserByUserName(model.Name);

            SessionHelper.LogOnUser <Reception_UserInfo>(_user);

            return(RedirectToAction("Index", "ReceptionManager"));
        }
Ejemplo n.º 2
0
 public void OnAuthorization(AuthorizationContext filterContext)
 {
     // 判断是否客户端已经登录认证
     if (filterContext.HttpContext.User.Identity.IsAuthenticated)
     {
         // 已经登录认证,如果session过期或丢失,则恢复session
         if (SessionHelper.LogOnUserObj == null)
         {
             SessionHelper.LogOnUser <Reception_UserInfo>(_userBL.GetUserByUserName(filterContext.HttpContext.User.Identity.Name));
         }
     }
     else
     {
         if (filterContext.HttpContext.Request.IsAjaxRequest())
         {
             filterContext.Result = new AjaxLogOnResult();
         }
         else
         {
             filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new
             {
                 controller = "ReceptionManager",
                 action     = "LogOn",
                 returnUrl  = filterContext.HttpContext.Request.Url
             }));
         }
     }
 }