예제 #1
0
    public int UpdateUser(SystemUserInfo user, SQLHelper sqlHelper)
    {
        if (sqlHelper == null)
        {
            throw new ArgumentNullException();
        }

        if (user == null)
        {
            return(0);
        }

        DataTable dt = new DataTable();

        dt.TableName = "t_user";
        dt.Columns.Add("user_id");
        dt.Columns.Add("user_name");
        //  dt.Columns.Add("login_name");
        dt.Columns.Add("login_password");
        DataRow dr = dt.NewRow();

        dr["user_id"]   = user.Id;
        dr["user_name"] = user.Name;
        // dr["login_name"] = user.LoginName;
        dr["login_password"] = user.LoginPassword;
        dt.Rows.Add(dr);
        return(sqlHelper.Update(dt, new List <string>()
        {
            "user_id"
        }));
    }
예제 #2
0
 public async Task <JsonResult> SaveUser(SystemUserInfo user,
                                         Guid orgId)
 {
     user.CreateUserId   = CurrentUser.UserId;
     user.CreateUserName = CurrentUser.Name;
     return(Json(await _userInfoLogic.SaveUser(user, orgId)));
 }
    protected void Page_Load(object sender, EventArgs e)
    {
        SystemUserInfo loginUser = Session[Resources.LOGIN_USER_INFO] as SystemUserInfo;

        if (loginUser == null)
        {
            Response.Redirect("/Default.aspx");
        }
    }
예제 #4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string loginUrl  = CommWebUtil.AppendQueryString("/Default.aspx", Request);
        string infoUrl   = CommWebUtil.AppendQueryString("info.aspx", Request);
        string targetUrl = string.Empty;

        SystemUserInfo loginUser = Session[Resources.LOGIN_USER_INFO] as SystemUserInfo;

        //判断是否为游客
        if (loginUser == null && Request.Params["is_guest_login"] != null)
        {
            targetUrl = infoUrl;
        }
        else if (loginUser != null)
        {
            int roleLevel = 0;
            roleLevel = loginUser.Roles.Max <SystemRole>(x => int.Parse(x.RoleLevel));
            switch (roleLevel)
            {
            case 1:
            case 2:
                targetUrl = infoUrl;
                break;

            case 3:
                targetUrl = string.Empty;
                break;

            default:
                targetUrl = loginUrl;
                break;
            }
        }
        else
        {
            targetUrl = loginUrl;
        }
        if (!string.IsNullOrEmpty(targetUrl))
        {
            Response.Redirect(targetUrl);
        }
        else if (loginUser != null)
        {
            //由于班组管理中可能会改变班组数据,须实时获取班组信息
            SQLHelper sqlHelper = CommWebUtil.GetSQLHelper(this.Context);
            UpdateUserGroup(loginUser, sqlHelper);
            loginUserName.InnerHtml = loginUser.Name;
            logout.HRef             = CommWebUtil.AppendQueryString("LogoutHandler.ashx", Request);
            currentUerGroups.Value  = Newtonsoft.Json.JsonConvert.SerializeObject(loginUser.Groups);

            UserName.Value = loginUser.Name;
        }
    }
예제 #5
0
 public void Save(SystemUserInfo systemUserInfo)
 {
     Delete(systemUserInfo.UserId);
     if (!string.IsNullOrEmpty(systemUserInfo.EmployeeId))
     {
         using (var adapter = PersistenceLayer.GetDataAccessAdapter())
         {
             var entity = Mapper.Map <SystemUserInfo, SystemUserInfoEntity>(systemUserInfo);
             if (!adapter.SaveEntity(entity, false))
             {
                 throw new PersistenceFailureException();
             }
         }
     }
 }
        private async Task <string> GetSystemUserTicket(SystemUserInfo systemUserInfo)
        {
            var sysUserClient = new SystemUserClient(systemUserInfo);

            var ticket = await sysUserClient.GetSystemUserTicketAsync();

            foreach (var claim in sysUserClient.ClaimsIdentity?.Claims)
            {
                System.Diagnostics.Debug.WriteLine(
                    $"type: {claim.Type}, value: {claim.Value}"
                    );
            }

            return(ticket);
        }
예제 #7
0
    private void UpdateUserGroup(SystemUserInfo user, SQLHelper sqlHelper)
    {
        if (user == null)
        {
            return;
        }
        user.Groups = new List <UserGroup>();
        if (sqlHelper == null)
        {
            throw new ArgumentNullException();
        }
        Dictionary <string, object> parameters = new Dictionary <string, object>();

        /*
         * 获取用户所在部门及其所有下级部门,并在部门前面加上上一级部门名称
         */
        string sql = @"select cg.group_id,'[' + pg.group_name+']' + cg.group_name group_name,cg.group_desc,cg.parentId,cg.tree_id from 
                        (
	                        (
		                        (
			                        t_user u inner join t_user_group ug on u.user_id=ug.user_id
		                        ) inner join t_group g on g.group_id=ug.group_id
	                        ) left join t_group cg on cg.tree_id like g.tree_id + '%'
                        ) left join t_group pg on cg.parentId=pg.group_id 
                        where u.user_id=@user_id
                        order by cg.tree_id
                       ";

        parameters.Clear();
        parameters.Add("user_id", user.Id);

        System.Data.DataTable dt = sqlHelper.ExecuteQuery(sql, parameters);
        if (dt != null && dt.Rows.Count > 0)
        {
            foreach (DataRow dr in dt.Rows)
            {
                UserGroup group = new UserGroup();
                group.Id        = dr["group_id"] == DBNull.Value ? "" : dr["group_id"] + "";
                group.GroupName = dr["group_name"] == DBNull.Value ? "" : dr["group_name"] + "";
                group.Desc      = dr["group_desc"] == DBNull.Value ? "" : dr["group_desc"] + "";
                group.Parentid  = dr["parentid"] == DBNull.Value ? "" : dr["parentid"] + "";
                group.Treeid    = dr["tree_id"] == DBNull.Value ? "" : dr["tree_id"] + "";
                user.Groups.Add(group);
            }
        }
    }
예제 #8
0
        public async Task <ViewResultBase> Edit(
            SystemUserInfoEditViewModel viewModel)
        {
            var user = new SystemUserInfo();

            //如果为编辑
            if (viewModel.UserId != null)
            {
                user = await _userInfoLogic.GetByIdAsync(viewModel.UserId);
            }
            //新增
            else
            {
                user.CreateTime = DateTime.Now;
            }
            ViewData["OrgId"]   = viewModel.OrgId;
            ViewData["OrgName"] = viewModel.OrgName;
            return(View(user));
        }
예제 #9
0
    protected void Page_Load(object sender, EventArgs e)
    {
        SystemUserInfo loginUser = Session[Resources.LOGIN_USER_INFO] as SystemUserInfo;

        logout.HRef = CommWebUtil.AppendQueryString("LogoutHandler.ashx", Request);
        Dictionary <string, string>[] data = GetRequestData();
        //判断是否为游客
        if (loginUser == null /*&& Request.Params["is_guest_login"] != null*/)
        {
            DoPhoto(data);
            DoGuestRequest(data);
            logout.InnerHtml = "使用账号登录";
        }
        else if (loginUser != null)
        {
            logout.InnerHtml = "退出";
            int roleLevel = 0;
            roleLevel = loginUser.Roles.Max <SystemRole>(x => int.Parse(x.RoleLevel));
            switch (roleLevel)
            {
            case 1:
            case 2:
                DoPhoto(data);
                DoGuestRequest(data);
                DoUserRequest(data);
                break;

            case 3:
                DoAdministratorRequest();
                break;

            default:
                DoNoKnownRequest();
                break;
            }
        }
        else
        {
            DoNoKnownRequest();
        }
    }// end Page_Load
예제 #10
0
        private async Task <string> GetSystemUserTicket(SystemUserInfo systemUserInfo)
        {
            var sysUserClient = new SystemUserClient(systemUserInfo);

            return(await sysUserClient.GetSystemUserTicketAsync());
        }
예제 #11
0
        public UserEditModel Save(UserEditModel userToSave)
        {
            _userModelValidator.ValidateAndThrow(userToSave);

            var userAddress = _addressService.SaveAfterSanitizing(Mapper.Map <AddressEditModel, Address>(userToSave.Address));
            OrganizationRoleUser organizationRoleUser = Mapper.Map <OrganizationRoleUserModel, OrganizationRoleUser>(_sessionContext.UserSession.CurrentOrganizationRole);

            userToSave.DataRecorderMetaData = new DataRecorderMetaData(organizationRoleUser, DateTime.Now, DateTime.Now);

            var        user = Mapper.Map <UserEditModel, User>(userToSave);
            var        isPasswordUpdatedOrCreated = false;
            SecureHash secureHash = null;

            if (userToSave.Id > 0 && string.IsNullOrEmpty(userToSave.Password))
            {
                var existingUser = _userRepository.GetUser(userToSave.Id);
                user.UserLogin.Password               = existingUser.UserLogin.Password;
                user.UserLogin.Salt                   = existingUser.UserLogin.Salt;
                user.UserLogin.UserVerified           = existingUser.UserLogin.UserVerified;//For a scenario: User is created and then immediatly updated
                user.UserLogin.LastPasswordChangeDate = existingUser.UserLogin.LastPasswordChangeDate;
                user.UserLogin.LastLogged             = existingUser.UserLogin.LastLogged;
            }
            else if (!string.IsNullOrEmpty(userToSave.Password))
            {
                secureHash = _oneWayHashingService.CreateHash(userToSave.Password);
                user.UserLogin.Password               = secureHash.HashedText;
                user.UserLogin.Salt                   = secureHash.Salt;
                isPasswordUpdatedOrCreated            = true;
                user.UserLogin.LastPasswordChangeDate = DateTime.Now;
            }

            user.Address = userAddress;
            if (isPasswordUpdatedOrCreated)//&& user.Id > 0 && userToSave.UsersRoles.Count() == 1 && userToSave.UsersRoles.Single().RoleId == (long)Roles.Customer)
            {
                user.UserLogin.UserVerified = false;
            }

            user.UserLogin.IsTwoFactorAuthrequired = userToSave.OverRideTwoFactorAuthrequired ? userToSave.IsTwoFactorAuthrequired : (bool?)null;


            user = _userRepository.SaveUser(user);
            if (isPasswordUpdatedOrCreated && secureHash != null && !(user.Id > 0 && userToSave.UsersRoles.Count() == 1 && userToSave.UsersRoles.Single().RoleId == (long)Roles.Customer))
            {
                _passwordChangelogService.Update(user.Id, secureHash, _sessionContext.UserSession.CurrentOrganizationRole.OrganizationRoleUserId);
            }

            userToSave.Id = user.Id;
            //map & save user roles
            _orgRoleUserRepository.DeactivateAllOrganizationRolesForUser(user.Id);
            foreach (var organizationRoleModel in userToSave.UsersRoles)
            {
                organizationRoleModel.UserId = user.Id;
                var orgRoleUser = _orgRoleUserRepository.SaveOrganizationRoleUser(Mapper.Map <OrganizationRoleUserModel, OrganizationRoleUser>(organizationRoleModel));
                var roleId      = GetParentRoleIdByRoleId(orgRoleUser.RoleId);
                switch (roleId)
                {
                case (long)Roles.Technician:
                    var technician = Mapper.Map <TechnicianModel, Technician>(userToSave.TechnicianProfile);
                    technician.TechnicianId = orgRoleUser.Id;
                    var repository = ((IRepository <Technician>)_technicianRepository);
                    repository.Save(technician);
                    if (!string.IsNullOrWhiteSpace(userToSave.TechnicianProfile.Pin))
                    {
                        _pinChangeLogService.Update(userToSave.TechnicianProfile.Pin.Encrypt(), orgRoleUser.Id, organizationRoleUser.Id);
                    }
                    break;

                case (long)Roles.MedicalVendorUser:
                    var physician = Mapper.Map <PhysicianModel, Physician>(userToSave.PhysicianProfile);
                    physician.PhysicianId             = orgRoleUser.Id;
                    physician.AuthorizedStateLicenses =
                        _physicianLicenseModelFactory.CreateMultiple(userToSave.PhysicianProfile.Licenses,
                                                                     orgRoleUser.Id);
                    _physicianRepository.SavePhysician(physician);
                    break;

                case (long)Roles.CorporateAccountCoordinator:
                    var accountCoordinator = Mapper.Map <AccountCoordinatorProfileModel, AccountCoordinatorProfile>(userToSave.AccountCoordinatorProfile);
                    accountCoordinator.AccountCoordinatorId = orgRoleUser.Id;
                    var accountCoordinatorRepository = ((IRepository <AccountCoordinatorProfile>)_accountCoordinatorProfileRepository);
                    accountCoordinatorRepository.Save(accountCoordinator);
                    break;

                case (long)Roles.CallCenterRep:
                    var callCenterRepProfile = new CallCenterRepProfile
                    {
                        CallCenterRepId = orgRoleUser.Id,
                        CanRefund       = false,
                        CanChangeNotes  = false,
                        DialerUrl       = organizationRoleModel.DialerUrl
                    };
                    _callCenterRepProfileRepository.Save(callCenterRepProfile);
                    break;
                }
            }

            if (userToSave.UsersRoles.Any(x => x.RoleId == (long)Roles.NursePractitioner))
            {
                var userNpiInfo = new UserNpiInfo
                {
                    UserId     = userToSave.Id,
                    Npi        = !string.IsNullOrEmpty(userToSave.Npi) ? userToSave.Npi : null,
                    Credential = !string.IsNullOrEmpty(userToSave.Credential) ? userToSave.Credential : null
                };
                _userNpiInfoRepository.Save(userNpiInfo);
            }

            var systemUserInfo = new SystemUserInfo
            {
                EmployeeId = userToSave.UsersRoles.Count() == 1 && userToSave.UsersRoles.Any(x => x.RoleId == (long)Roles.Customer) ? string.Empty : userToSave.EmployeeId,
                UserId     = userToSave.Id
            };

            _systemUserInfoRepository.Save(systemUserInfo);

            return(userToSave); //this does not return the same object. the saved user are out of sync at this point.!!
        }