/// <summary> /// Handles the specified request. /// </summary> /// <param name="request">The request.</param> /// <param name="response">The response.</param> protected override void Handle(GetPatientDtoByKeyRequest request, GetPatientDtoResponse response) { var patient = _patientRepository.GetByKey(request.PatientKey); var patientDto = Mapper.Map <Patient, PatientDto> (patient); //get system account associated with staff Guid?systemAccountKey; using (var connection = _dbConnectionFactory.CreateConnection()) { systemAccountKey = connection.Query <Guid?> ("SELECT SystemAccountKey FROM SecurityModule.SystemAccount WHERE PatientKey=@PatientKey", new { request.PatientKey }) .FirstOrDefault(); } if (systemAccountKey.HasValue) { var systemAccount = _systemAccountRepository.GetByKey(systemAccountKey.Value); var systemAccountDto = Mapper.Map <SystemAccount, SystemAccountDto> (systemAccount); //if (systemAccount.RoleKeys.Any()) //{ // var roleKeys = string.Join(", ", systemAccount.RoleKeys); // roleKeys = "'" + roleKeys.Replace(", ", "', '") + "'"; // var query = string.Format("SELECT RoleKey as 'Key', Name FROM SecurityModule.Role WHERE RoleKey IN ({0})", roleKeys); // using (var connection = _dbConnectionFactory.CreateConnection()) // { // var roleDtos = connection.Query<RoleDto>(query).OrderBy(r => r.Name); // systemAccountDto.Roles = roleDtos; // } //} patientDto.SystemAccount = systemAccountDto; } response.DataTransferObject = patientDto; }
/// <summary> /// Handles the specified request. /// </summary> /// <param name="request">The request.</param> /// <param name="response">The response.</param> protected override void Handle(ChangePasswordRequest request, ChangePasswordResponse response) { var systemAccount = _systemAccountRepository.GetByKey(request.SystemAccountKey); if (systemAccount != null) { var result = _systemAccountIdentityServiceManager.ChangePassword(systemAccount.Identifier, request.OldPassword, request.NewPassword); response.ResultCode = result.Sucess ? ChangePasswordResponseCode.Succeed : ChangePasswordResponseCode.InvalidCredentials; } }
/// <summary> /// Handles the specified request. /// </summary> /// <param name="request">The request.</param> /// <returns>A <see cref="Agatha.Common.Response"/></returns> public override Response Handle(ExerciseEmergencyAccessRequest request) { var principal = _currentClaimsPrincipalService.GetCurrentPrincipal(); var systemAccount = _accountRepository.GetByKey(principal.CurrentAccountKey()); _permissionClaimsManager.ExerciseEmergencyAccess(principal, systemAccount); var response = CreateTypedResponse(); response.UserInformationDto = _userInformationDtoFactory.CreateUserInformationDto(); return(response); }
protected override void Handle(ValidatePatientAccountRequest request, ValidatePatientAccountResponse response) { var systemAccount = _systemAccountRepository.GetByKey(request.SystemAccountKey); var patient = _patientRepository.GetByKey(systemAccount.PatientKey.Value); var validationResult = patient.ValidateInfo(systemAccount, request.PatientIdentifier, request.DateOfBirth); if (validationResult == ValidationStatus.Locked) { response.IsLocked = true; } if (validationResult == ValidationStatus.Valid) { response.Validated = true; } }
protected override void Handle(ChangePasswordRequest request, ChangePasswordResponse response) { var systemAccount = _systemAccountRepository.GetByKey(UserContext.SystemAccountKey); if (systemAccount != null) { var identityServiceResponse = _systemAccountIdentityServiceManager.ChangePassword(systemAccount.Identifier, request.OldPassword, request.NewPassword); if (identityServiceResponse.Sucess) { response.ResultCode = "Succeed"; } else { response.ResultCode = "InvalidCredentials"; } } }
/// <summary> /// Handles the specified request. /// </summary> /// <param name="request">The request.</param> /// <param name="response">The response.</param> protected override void Handle(LockUnLockRequest request, LockUnLockResponse response) { var systemAccount = _systemAccountRepository.GetByKey(request.SystemAccountKey); if (systemAccount != null) { if (request.Lock && !systemAccount.IsLocked) { var result = _systemAccountIdentityServiceManager.Lock(systemAccount.Identifier); if (result.Sucess) { systemAccount.Lock(); response.ResponseCode = LockUnLockResponseCode.Success; _logger.Debug("Locked account: {0}-{1}", systemAccount.Key, systemAccount.Identifier); } else { response.ResponseCode = LockUnLockResponseCode.Error; _logger.Debug("Failed lock for {0}-{1}: {2}", systemAccount.Key, systemAccount.Identifier, result.ErrorMessage); } } else if (!request.Lock && systemAccount.IsLocked) { var result = _systemAccountIdentityServiceManager.UnLock(systemAccount.Identifier); if (result.Sucess) { systemAccount.UnLock(); response.ResponseCode = LockUnLockResponseCode.Success; _logger.Debug("UnLocked account: {0}-{1}", systemAccount.Key, systemAccount.Identifier); } else { response.ResponseCode = LockUnLockResponseCode.Error; _logger.Debug("Failed unlock for {0}-{1}: {2}", systemAccount.Key, systemAccount.Identifier, result.ErrorMessage); } } } else { response.ResponseCode = LockUnLockResponseCode.UnknownAccount; _logger.Debug("Failed {0} for system account key {1}, system account does not exist.", request.Lock ? "lock" : "unlock", request.SystemAccountKey); } }
protected override void Handle(ChangePasswordRequest request, ChangePasswordResponse response) { var systemAccount = _systemAccountRepository.GetByKey(request.SystemAccountKey); if (systemAccount != null) { using (var httpClient = new HttpClient { BaseAddress = new Uri(request.BaseBaseIdentityServerUri) }) { httpClient.SetToken("Session", request.Token); var httpResponseMessage = httpClient.GetAsync("api/membership/GetUserByEmail?email=" + systemAccount.Identifier).Result; if (httpResponseMessage.StatusCode == HttpStatusCode.OK) { var membershipUserDtos = httpResponseMessage.Content.ReadAsAsync <IEnumerable <MembershipUserDto> >().Result.ToList(); if (membershipUserDtos.Count == 0) { response.ResultCode = "NoAccount"; return; } if (membershipUserDtos.Count != 1) { response.ResultCode = "MultipleAccount"; return; } var membershipUserDto = membershipUserDtos[0]; var path = "api/membership/ChangePassword/" + membershipUserDto.Username + "?oldPassword="******"&newPassword="******"Succeed" : "InvalidCredentials"; } else { //var result = httpResponseMessage.Content.ReadAsStringAsync().Result; response.ResultCode = "InvalidCredentials"; } } } }
protected override void Handle(AssignRolesRequest request, AssignRolesResponse response) { var systemAccount = _systemAccountRepository.GetByKey(request.SystemAccoutnKey); if (systemAccount != null) { if (request.AddRoles) { foreach (var role in request.Roles) { systemAccount.AddRole(role); } } else { foreach (var role in request.Roles) { systemAccount.RemoveRole(role); } } } }
protected override void Handle(AssignRolesRequest request, AssignRolesResponse response) { var systemAccount = _systemAccountRepository.GetByKey(request.SystemAccoutnKey); if (systemAccount != null) { if (request.AddRoles) { foreach (var role in _roleRepository.GetByKeys(request.Roles.ToArray())) { systemAccount.AddRole(role); } } else { foreach (var role in systemAccount.Roles.Where(r => request.Roles.Contains(r.Role.Key)).ToList()) { systemAccount.RemoveRole(role); } } } }
/// <summary> /// Handles the specified request. /// </summary> /// <param name="request">The request.</param> /// <param name="response">The response.</param> protected override void Handle(ResetPasswordRequest request, ResetPasswordResponse response) { var systemAccount = _systemAccountRepository.GetByKey(request.SystemAccountKey); if (systemAccount != null) { var result = _systemAccountIdentityServiceManager.ResetPassword(systemAccount.Identifier); if (result.Sucess) { response.ResponseCode = ResetPasswordResponseCode.Success; Logger.Debug("Reset password for {0}-{1}", systemAccount.Key, systemAccount.Identifier); } else { response.ResponseCode = ResetPasswordResponseCode.Error; Logger.Debug("Failed Reset password for {0}-{1}: {2}", systemAccount.Key, systemAccount.Identifier, result.ErrorMessage); } } else { response.ResponseCode = ResetPasswordResponseCode.UnknownAccount; Logger.Debug("Failed Reset password for system account key {0}, system account does not exist.", request.SystemAccountKey); } }