mirror of
https://github.com/LD-Reborn/Berufsschule_HAM.git
synced 2025-12-20 06:51:55 +00:00
Initial commit
This commit is contained in:
62
Controllers/UsersController.cs
Normal file
62
Controllers/UsersController.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
// Controllers/UsersController.cs
|
||||
using Berufsschule_HAM.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Novell.Directory.Ldap;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
[Route("[controller]")]
|
||||
public class UsersController : Controller
|
||||
{
|
||||
private readonly LdapService _ldap;
|
||||
public UsersController(LdapService ldap) => _ldap = ldap;
|
||||
|
||||
[HttpGet("Index")]
|
||||
public async Task<IEnumerable<Dictionary<string, string>>> Index()
|
||||
{
|
||||
var users = await _ldap.ListUsersAsync();
|
||||
return users;
|
||||
}
|
||||
|
||||
[HttpGet("Delete")]
|
||||
public async Task<bool> Delete(string dn)
|
||||
{
|
||||
return await Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
_ldap.DeleteObjectByDn(dn);
|
||||
return true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[HttpGet("Create")]
|
||||
public async Task<bool> Create(string cn, string sn, string userPassword)
|
||||
{
|
||||
// return await new Task<bool>(() =>
|
||||
// {
|
||||
try
|
||||
{
|
||||
LdapAttributeSet attributeSet = [];
|
||||
attributeSet.Add(new LdapAttribute("objectClass", "organizationalPerson"));
|
||||
attributeSet.Add(new LdapAttribute("objectClass", "person"));
|
||||
//attributeSet.Add(new LdapAttribute("ou", "users"));
|
||||
attributeSet.Add(new LdapAttribute("objectClass", "top"));
|
||||
attributeSet.Add(new LdapAttribute("cn", cn));
|
||||
attributeSet.Add(new LdapAttribute("sn", sn));
|
||||
attributeSet.Add(new LdapAttribute("userPassword", userPassword));
|
||||
_ldap.CreateUser(attributeSet);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// });
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user