add ability to get user based on username or email address

This commit is contained in:
sbwalker
2023-08-13 08:35:03 -04:00
parent c344eedb12
commit c2acd010ce
7 changed files with 46 additions and 9 deletions

View File

@ -61,13 +61,15 @@ namespace Oqtane.Controllers
}
}
// GET api/<controller>/name/x?siteid=x
[HttpGet("name/{name}")]
public User Get(string name, string siteid)
// GET api/<controller>/name/{name}/{email}?siteid=x
[HttpGet("name/{name}/{email}")]
public User Get(string name, string email, string siteid)
{
if (int.TryParse(siteid, out int SiteId) && SiteId == _tenantManager.GetAlias().SiteId)
{
User user = _userManager.GetUser(name, SiteId);
name = (name == "-") ? "" : name;
email = (email == "-") ? "" : email;
User user = _userManager.GetUser(name, email, SiteId);
if (user == null)
{
HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
@ -76,7 +78,7 @@ namespace Oqtane.Controllers
}
else
{
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized User Get Attempt {Username} {SiteId}", name, siteid);
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized User Get Attempt {Username} {Email} {SiteId}", name, email, siteid);
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
return null;
}