예제 #1
0
        public ActionResult Login(LoginModelView loginInfo)
        {
            if (ModelState.IsValid)
            {
                var model = userBll.Get(c => c.LoginName == loginInfo.LoginName && c.PassWord == loginInfo.Password);
                if (model != null)
                {
                    var extends = model.toEntity <UsersExtend>();
                    if (model.OrganId != null)
                    {
                        var organ = _organBll.Get(c => c.OrganId == model.OrganId);
                        extends.OrganName = organ.OrganName;
                    }
                    if (model.DepartmentId != null)
                    {
                        var dep = _departmentBll.Get(c => c.DepartmentId == model.DepartmentId);
                        extends.DepartmentName = dep.DepartmentName;
                    }

                    WebHelper.FormPrincipal.MyFormsPrincipal <UserInfo> .SignIn(model.LoginName, new UserInfo()
                    {
                        Id = model.UserId
                    }, 40);

                    //将用户信息存入缓存
                    DepositHelper.Set(RedisKeyManager.LoginUserInfo(model.UserId.ToString()), extends);
                    return(Success("登陆成功"));
                }
                else
                {
                    return(Fail("登陆失败"));
                }
            }
            return(View(loginInfo));
        }