Example #1
0
        public string SaveConsultationInfo()
        {
            return(base.ExecuteActionJsonResult("会诊单信息保存", () =>
            {
                CD_Consultation entity = base.GetPageData <CD_Consultation>(0);
                if (!string.IsNullOrWhiteSpace(entity.InpatientId))
                {
                    CD_Inpatient inpatient = EntityOperate <CD_Inpatient> .GetEntityById(Request["InpatientId"], "InpatientId");
                    if (string.IsNullOrWhiteSpace(entity.ConsultationId) || entity.ConsultationId == "null")
                    {
                        entity.ConsultationState = "1";
                        entity.DeptId = inpatient.CurrentDeptID;
                        entity.WardId = inpatient.CurrentWardID;
                        entity.RequesterCode = UserTokenManager.GetUserToken(Request["token"]).UserId;
                        GI_UserInfo user = EntityOperate <GI_UserInfo> .GetEntityById(entity.RequesterCode, "USERID");
                        entity.RequestDepartCode = user.DpetID;
                        entity.OrganID = UserTokenManager.GetUserToken(Request["token"]).ORGANID;
                    }

                    entity.Del = 0;
                    service.SaveInfo(entity);
                    msgHub hub = new msgHub();
                    // hub.SendGroup(entity.ApplyDepartCode, "Con", "",  "");
                }
                return new WebApi_Result();
            }));
        }
        public WebApiResult SignOut()
        {
            // 登录log

            var log = new Log()
            {
                Action           = "SignOut",
                Detail           = "会员退出:" + "adminstor", //RISContext.Current.CurrentUserInfo.UserName,
                CreatorLoginName = "adminstor",           //RISContext.Current.CurrentUserInfo.UserName,
                IpAddress        = "127.0.0.1",           //GetClientIp(this.Request)
                EndTime          = DateTime.Now,
                HostName         = "hahha",
                UserId           = 2,
                Id = 1,
            };

            //  logRep.Update(log);
            //System.Web.Security.FormsAuthentication.SignOut();
            UserTokenManager.RemoveToken(this.Token);
            return(new WebApiResult()
            {
                Code = Enuncode.Success,
                Message = "退出成功"
            });
        }
Example #3
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="configuration">配置实例</param>
 /// <param name="serviceProvider">服务提供程序</param>
 public UserManager(IConfiguration configuration, IServiceProvider serviceProvider) : base(configuration)
 {
     this.serviceProvider  = serviceProvider;
     operateHistoryManager = serviceProvider.GetRequiredService <IOperateHistoryManager>();
     userRoleManager       = serviceProvider.GetRequiredService <UserRoleManager>();
     userTokenManager      = serviceProvider.GetRequiredService <UserTokenManager>();
 }
Example #4
0
        public ResultData Login(LoginUser login)
        {
            if (login == null)
            {
                return(new ResultData((int)HttpStatusCode.BadRequest, "参数错误"));
            }

            string userID   = login.UserID;
            string password = login.Password;

            if (string.IsNullOrEmpty(userID) || string.IsNullOrEmpty(password))
            {
                return(new ResultData(ResultType.UserNameOrPasswordError, EnumExtension.GetEnumDescription(ResultType.UserNameOrPasswordError)));
            }

            User       u           = null;
            ResultType loginResult = UserManager.Login(login, out u);
            ResultData resultData  = new ResultData
            {
                Result = Convert.ToInt32(loginResult),
                Desc   = EnumExtension.GetEnumDescription(loginResult)
            };

            if (ResultType.Success == loginResult)
            {
                // 写日志
                var log = new Log()
                {
                    Action           = "Login",
                    Detail           = "会员登录:" + u.UserID,
                    CreateDate       = DateTime.Now,
                    CreatorLoginName = u.UserID,
                    IpAddress        = HttpContext.Current.Request.UserHostAddress
                };
                LogRepository.Add(log);

                // 保存令牌
                UserTokenManager.RemoveTokenWithUserID(u.UserID);
                var userToken = new UserToken
                {
                    UserID  = u.UserID,
                    Token   = Utility.Encrypt(string.Format("{0}{1}", Guid.NewGuid().ToString("D"), DateTime.Now.Ticks)),
                    Timeout = DateTime.Now.AddHours(8)
                };
                UserTokenManager.AddToken(userToken);

                resultData.Data = new
                {
                    user_id = userToken.UserID,
                    token   = userToken.Token,
                    timeout = userToken.Timeout.ToString("yyyy/MM/dd HH:mm:ss")
                };
            }

            return(resultData);
        }
Example #5
0
 /// <summary>
 /// 获取会诊单数量
 /// </summary>
 /// <param name="userFilter"></param>
 /// <returns></returns>
 public string GetConsulationCountByUser()
 {
     return(base.ExecuteActionJsonResult("获取列表", () =>
     {
         //UserFilter userFilter = GetPageData<UserFilter>(0);
         int cnt = service.GetConsulationCountByUser(UserTokenManager.GetUId(Request["token"]));
         return new WebApi_Result()
         {
             code = 0, data = cnt
         };
     }));
 }
Example #6
0
        //TODO:具体的权限实现方法
        /// <summary>
        /// 权限验证方法
        /// </summary>
        /// <param name="actionContext">Web请求</param>
        /// <returns>返回是否通过验证</returns>
        public static bool ValidateHandler(HttpActionContext actionContext)
        {
            var token = HttpContext.Current.Request.Headers["Token"];//actionContext.Request.Headers.["Token"];

            if (string.IsNullOrEmpty(token))
            {
                return(false);
            }

            var isvalid = UserTokenManager.ValidUserToken(token);

            return(isvalid);
        }
Example #7
0
 public string SaveInfo()
 {
     return(base.ExecuteActionJsonResult("医生分组保存", () =>
     {
         AI_DoctorGroup entity = base.GetPageData <AI_DoctorGroup>(0);
         entity.DoctorGroupId = string.IsNullOrWhiteSpace(entity.DoctorGroupId) ? null : entity.DoctorGroupId;
         entity.UpdateTime = DateTime.Now;
         entity.Updater = UserTokenManager.GetUserToken(Request["token"]).UserId;
         entity.OrganID = UserTokenManager.GetUserToken(Request["token"]).ORGANID;
         doctorGroupService.SaveInfo(entity);
         return new WebApi_Result();
     }));
 }
Example #8
0
        public static UserTokenProcess UserTokenProcessMultiton(ConnectionHelper connectionHelper)
        {
            lock (_lockObject)
            {
                if (!_userTokenProcess.ContainsKey(connectionHelper.Database))
                {
                    _userTokenProcess.Add(connectionHelper.Database, new UserTokenProcess());
                }
            }

            userTokenManager = new UserTokenManager(new UserTokenServiceManager(connectionHelper));

            return(_userTokenProcess[connectionHelper.Database]);
        }
        /// <summary>
        /// 增加和保存数据
        /// </summary>
        /// <returns></returns>
        public string SaveInfo()
        {
            return(base.ExecuteActionJsonResult("保存信息", () =>
            {
                CD_FormEmrTemplate entity = base.GetPageData <CD_FormEmrTemplate>(0);
                entity.TemplateId = string.IsNullOrWhiteSpace(entity.TemplateId) ? null : entity.TemplateId;
                entity.ParentId = string.IsNullOrWhiteSpace(entity.ParentId) ? null : entity.ParentId;
                entity.CreateTime = DateTime.Now;
                entity.Creator = UserTokenManager.GetUserToken(Request["token"]).UserId;

                formEmrTemplateService.SaveInfo(entity);
                return new WebApi_Result();
            }));
        }
        /// <summary>
        /// 保存诊断数据
        /// </summary>
        /// <returns></returns>
        public string SaveInfo()
        {
            return(base.ExecuteActionJsonResult("诊断保存", () =>
            {
                CD_PatientDiagnosis entity = base.GetPageData <CD_PatientDiagnosis>(0);
                CD_HospitalRecord hospitalRecord = hospitalrecordservice.GetInfoByInpatientId(entity.InpatientId);
                if (hospitalRecord == null)
                {
                    return new WebApi_Result()
                    {
                        code = 0, msg = "请先保存入院记录"
                    };
                }

                entity.ICDCode = string.IsNullOrWhiteSpace(entity.ICDCode) ? null : entity.ICDCode;
                var DiagnosisIdList = (entity.DiagnosisId + "").Split(',');
                for (int i = 0; i < entity.ICDCode.Split(',').Length; i++)
                {
                    var cur_entity = base.GetPageData <CD_PatientDiagnosis>(0);
                    if (DiagnosisIdList.Length > i)
                    {
                        cur_entity.DiagnosisId = DiagnosisIdList[i];
                    }
                    else
                    {
                        cur_entity.DiagnosisId = "";
                    }
                    cur_entity.ParentId = string.IsNullOrWhiteSpace(cur_entity.ParentId) ? "0" : cur_entity.ParentId;
                    cur_entity.ICDCode = entity.ICDCode.Split(',')[i];
                    cur_entity.DiagnosisName = entity.DiagnosisName.Split(',')[i];
                    UserToken ut = UserTokenManager.GetUserToken(Request["token"]);
                    cur_entity.RecordUserId = cur_entity.Creator = ut.UserId;
                    cur_entity.RecordUserName = ut.USERNAME;
                    if (cur_entity.DiagnosisTime == null)
                    {
                        cur_entity.DiagnosisTime = DateTime.Now;
                    }


                    //病历记录id
                    cur_entity.RecordId = hospitalRecord.HospitalRecordId;

                    patientDiagnosisService.SaveInfo(cur_entity);
                }
                return new WebApi_Result();
            }));
        }
Example #11
0
        private async void LoginButton_Click(object sender, EventArgs e)
        {
            UserTokenManager manager = new UserTokenManager();

            bool success = await manager.LoginAsync();

            if (success)
            {
                _client = GrooveClientFactory.CreateGrooveClient(Secret.CLIENTID, Secret.CLIENTSECRET, manager);
                EnableButtons();
            }
            else
            {
                // show error that login had a failure
                OutputTextBox.Text = "Login failure";
            }
        }
Example #12
0
        //TODO:具体的权限实现方法
        /// <summary>
        /// 权限验证方法
        /// </summary>
        /// <param name="actionContext">Web请求</param>
        /// <returns>返回是否通过验证</returns>
        public static bool ValidateHandler(HttpActionContext actionContext)
        {
            //var token = HttpContext.Current.Request.Headers["Token"];//actionContext.Request.Headers.["Token"];
            //if (string.IsNullOrEmpty(token))
            //    return false;

            //var isvalid = UserTokenManager.ValidUserToken(token);
            //return isvalid;


            var token = HttpContext.Current.Request.QueryString["token"] ?? null;

            if (string.IsNullOrEmpty(token))
            {
                token = HttpContext.Current.Request.Headers["token"];
                if (string.IsNullOrEmpty(token))
                {
                    return(false);
                }
            }

            IHttpController controller = actionContext.ControllerContext.Controller;

            if (controller is Demo.Api.Controllers.BaseApiController)
            {
                UserTokenExtend userToken = UserTokenManager.GetUserToken(token) as UserTokenExtend;
                if (null == userToken)
                {
                    //token已过期
                    return(false);
                }
                //测试使用的token
                if ("dcxx123456" != token)
                {
                    userToken.ExpireTime = DateTime.Now.AddHours(3);
                }
                else
                {
                    userToken.ExpireTime = DateTime.Now.AddYears(1);
                }
                ((DCSoft.Demo.Api.Controllers.BaseApiController)controller).userToken = userToken;
            }

            return(true);
        }
Example #13
0
 /// <summary>
 /// 获取回复会诊单列表
 /// </summary>
 /// <param name="userFilter"></param>
 /// <returns></returns>
 public string GetApplyConsultationByUser()
 {
     return(base.ExecuteActionJsonResult("获取列表", () =>
     {
         //UserFilter userFilter = GetPageData<UserFilter>(0);
         List <CD_Consultation> list = service.GetConsultationByUser(UserTokenManager.GetUId(Request["token"]), "1").Where(f => f.Del != 1).ToList();
         if (list.Count <= 0)
         {
             return new WebApi_Result()
             {
                 code = 1, msg = "未查询到任何数据"
             };
         }
         return new WebApi_Result()
         {
             code = 0, data = list, count = list.Count
         };
     }));
 }
Example #14
0
        /// <summary>
        /// 请求过滤器
        /// </summary>
        /// <param name="filterContext"></param>
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);

            #region model验证处理
            if (!filterContext.Controller.ViewData.ModelState.IsValid)
            {
                var item  = filterContext.Controller.ViewData.ModelState.Values.ToList().Find(a => a.Errors.Count > 0);
                var error = item.Errors.Where(a => !string.IsNullOrEmpty(a.ErrorMessage)).Take(1).SingleOrDefault().ErrorMessage;
                filterContext.Result = new JsonResult
                {
                    Data = new { code = 1, msg = error },
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet
                };
                return;
            }
            #endregion

            #region 权限验证
            foreach (var item in filterContext.ActionDescriptor.GetCustomAttributes(true).ToList())
            {
                if (item is AllowAnonymousAttribute)
                {
                    return;
                }
            }

            var token = filterContext.HttpContext.Request["token"];
            if (!string.IsNullOrEmpty(token) && UserTokenManager.IsExistToken(token))
            {
                return;
            }
            else
            {
                filterContext.Result = new JsonResult
                {
                    Data = new { code = 13, msg = "登录凭证失效,获取数据失败!" },
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet
                };
                return;
            }
            #endregion
        }
        /// <summary>
        /// 验证
        /// </summary>
        /// <param name="actionContext"></param>
        /// <returns></returns>
        protected override bool IsAuthorized(HttpActionContext actionContext)
        {
            // 验证token
            //var token = actionContext.Request.Headers.Authorization;
            var ts = actionContext.Request.Headers.Where(c => c.Key.ToLower() == "token").FirstOrDefault().Value;

            if (ts != null && ts.Count() > 0)
            {
                var token = ts.First <string>();
                // 验证token
                if (!UserTokenManager.IsExistToken(token))
                {
                    return(false);
                }
                return(true);
            }

            if (actionContext.Request.Method == HttpMethod.Options)
            {
                return(true);
            }
            return(false);
        }
Example #16
0
        /// <summary>
        /// 生成token
        /// </summary>
        /// <returns></returns>
        private UserTokenExtend GenernateToken()
        {
            //保存用户访问标识token
            UserTokenExtend myToken = new UserTokenExtend();
            //时间戳
            DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1, 8, 0, 0, 0));
            long     t         = (DateTime.Now.Ticks - startTime.Ticks) / 10000; //除10000调整为13位

            //时间戳+随机码
            string tokenStr = t + Guid.NewGuid().ToString().Replace("-", "").ToLower();

            myToken.Token    = tokenStr;
            myToken.UserId   = "";
            myToken.TrueName = "";
            //myToken.adcd = "";
            //myToken.userName = "";
            myToken.IP         = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"] ?? null;
            myToken.ExpireTime = DateTime.Now.AddHours(3);

            //保存token
            UserTokenManager.AddToken(myToken);

            return(myToken);
        }
        private async void LoginButton_Click(object sender, EventArgs e)
        {
            UserTokenManager manager = new UserTokenManager();

            try
            {
                bool loginSuccess = await manager.LoginAsync();

                if (loginSuccess)
                {
                    _client = GrooveClientFactory.CreateGrooveClient(Secret.CLIENTID, Secret.CLIENTSECRET, manager);
                    WriteOutputLine("Successfully logged in.");
                    OnLoginSuccess();
                }
                else
                {
                    WriteOutputLine("Error while logging in");
                }
            }
            catch (ConfigurationErrorsException ex)
            {
                WriteOutputLine("Could not save refresh token. Please run as admin to allow saving of refresh token, or you will have to manually authenticate with every request.");
            }
        }
 /// <summary>
 /// 保存病程记录
 /// </summary>
 /// <returns></returns>
 public string SaveInfo()
 {
     return(base.ExecuteActionJsonResult("保存" + Request["ProgressTypeName"] + "信息", () =>
     {
         CD_ProgressNote entity = GetPageData <CD_ProgressNote>(0);
         List <ProgressNote_Content_Item> itemList = new List <ProgressNote_Content_Item>();
         int curIndex = 0;
         foreach (string each in Request["RecordContentTitle"].Split(','))
         {
             itemList.Add(new ProgressNote_Content_Item()
             {
                 Title = each, Content = Request["RecordContent" + curIndex]
             });
             curIndex++;
         }
         entity.WardRoundUserId = string.IsNullOrWhiteSpace(entity.WardRoundUserId) ? UserTokenManager.GetUId(Request["token"]) : entity.WardRoundUserId;
         entity.RecordContent = new JavaScriptSerializer().Serialize(itemList);
         progressNoteService.SaveInfo(entity);
         return new WebApi_Result();
     }));
 }
Example #19
0
 /// <summary>
 /// 获取当前登录的用户信息。
 /// </summary>
 /// <param name="token"></param>
 /// <returns></returns>
 public static UserToken GetUserToken(this string token)
 {
     return(UserTokenManager.GetUserToken(token));
 }