feat(Verzeichnis): Client-Methode erstellt und Endpunkte angeordnet
This commit is contained in:
parent
3d8076e3b6
commit
098c2e1c47
@ -7,9 +7,10 @@ import { UrlService } from './url.service';
|
|||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
|
// TODO: Consolidate all directory services and remove unnecessary methods.
|
||||||
export class DirService {
|
export class DirService {
|
||||||
private baseUrl: string
|
private baseUrl: string
|
||||||
constructor(private http: HttpClient, urlService : UrlService) {
|
constructor(private http: HttpClient, urlService: UrlService) {
|
||||||
this.http = http;
|
this.http = http;
|
||||||
this.baseUrl = urlService.apiRoute.directory;
|
this.baseUrl = urlService.apiRoute.directory;
|
||||||
}
|
}
|
||||||
@ -22,4 +23,8 @@ export class DirService {
|
|||||||
|
|
||||||
return this.http.get<DirUser[]>(this.baseUrl, { params, withCredentials: true });
|
return this.http.get<DirUser[]>(this.baseUrl, { params, withCredentials: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createSearchRoot(username: string, password: string): Observable<Object> {
|
||||||
|
return this.http.post(this.baseUrl, { username: username, password: password }, { withCredentials: true })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -82,16 +82,16 @@ public class DirectoryController : ControllerBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("CreateSearchRoot")]
|
[HttpPost]
|
||||||
public async Task<IActionResult> CreateSearchRoot([FromBody] SearchRootCreateDto searchRootCreateDto)
|
public async Task<IActionResult> CreateSearchRoot([FromBody] SearchRootCreateDto searchRootCreateDto)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var dirEntryUsername = searchRootCreateDto.DirEntryUsername ?? CurrentUser;
|
var dirEntryUsername = searchRootCreateDto.Username ?? CurrentUser;
|
||||||
if (dirEntryUsername is null)
|
if (dirEntryUsername is null)
|
||||||
return Unauthorized();
|
return Unauthorized();
|
||||||
|
|
||||||
bool isValid = _dirSearchService.ValidateCredentials(dirEntryUsername, searchRootCreateDto.DirEntryPassword);
|
bool isValid = _dirSearchService.ValidateCredentials(dirEntryUsername, searchRootCreateDto.Password);
|
||||||
|
|
||||||
if (!isValid)
|
if (!isValid)
|
||||||
return Unauthorized(Result.Fail().Message(_localizer[Key.UserNotFound]));
|
return Unauthorized(Result.Fail().Message(_localizer[Key.UserNotFound]));
|
||||||
@ -100,7 +100,7 @@ public class DirectoryController : ControllerBase
|
|||||||
if (!userResult.IsSuccess || userResult.Data is null)
|
if (!userResult.IsSuccess || userResult.Data is null)
|
||||||
return Unauthorized(Result.Fail().Message(_localizer[Key.UserNotFoundInLocalDB]));
|
return Unauthorized(Result.Fail().Message(_localizer[Key.UserNotFoundInLocalDB]));
|
||||||
|
|
||||||
_dirSearchService.SetSearchRootCache(userResult.Data.Username, searchRootCreateDto.DirEntryPassword);
|
_dirSearchService.SetSearchRootCache(userResult.Data.Username, searchRootCreateDto.Password);
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -162,11 +162,12 @@ public class DirectoryController : ControllerBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("Group")]
|
[HttpGet("Group")]
|
||||||
public IActionResult GetGroups(string? dirEntryUsername, params string[] propName)
|
[Authorize]
|
||||||
|
public IActionResult GetGroups(params string[] propName)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
dirEntryUsername ??= CurrentUser;
|
string dirEntryUsername = CurrentUser!;
|
||||||
|
|
||||||
if (dirEntryUsername is null)
|
if (dirEntryUsername is null)
|
||||||
return Unauthorized();
|
return Unauthorized();
|
||||||
@ -190,12 +191,12 @@ public class DirectoryController : ControllerBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("User")]
|
[HttpGet("User")]
|
||||||
public IActionResult GetUsersByGroupName(string? dirEntryUsername, [FromQuery] string? groupName = null)
|
public IActionResult GetUsersByGroupName([FromQuery] string? groupName = null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string[] propName = { "memberof", "samaccountname", "givenname", "sn", "mail" };
|
string[] propName = { "memberof", "samaccountname", "givenname", "sn", "mail" };
|
||||||
dirEntryUsername ??= CurrentUser;
|
string dirEntryUsername = CurrentUser!;
|
||||||
|
|
||||||
if (dirEntryUsername is null)
|
if (dirEntryUsername is null)
|
||||||
return Unauthorized();
|
return Unauthorized();
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
namespace DigitalData.UserManager.Application.DTOs
|
namespace DigitalData.UserManager.Application.DTOs
|
||||||
{
|
{
|
||||||
public record SearchRootCreateDto(string? DirEntryUsername, string DirEntryPassword);
|
public record SearchRootCreateDto(string? Username, string Password);
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user