diff --git a/Oqtane.Client/Services/Interfaces/IUserService.cs b/Oqtane.Client/Services/Interfaces/IUserService.cs index 00102a5e..1a5323e9 100644 --- a/Oqtane.Client/Services/Interfaces/IUserService.cs +++ b/Oqtane.Client/Services/Interfaces/IUserService.cs @@ -15,7 +15,6 @@ namespace Oqtane.Services /// ID of a /// Task GetUserAsync(int userId, int siteId); - /// /// Get a of a specific site @@ -25,6 +24,15 @@ namespace Oqtane.Services /// Task GetUserAsync(string username, int siteId); + /// + /// Get a of a specific site + /// + /// Username / login of a + /// email address of a + /// ID of a + /// + Task GetUserAsync(string username, string email, int siteId); + /// /// Save a user to the Database. /// The object contains all the information incl. what it belongs to. diff --git a/Oqtane.Client/Services/UserService.cs b/Oqtane.Client/Services/UserService.cs index 24440df5..b74f6e50 100644 --- a/Oqtane.Client/Services/UserService.cs +++ b/Oqtane.Client/Services/UserService.cs @@ -4,6 +4,7 @@ using System.Net.Http; using System.Threading.Tasks; using Oqtane.Documentation; using System.Net; +using System.ComponentModel.DataAnnotations; namespace Oqtane.Services { @@ -21,7 +22,12 @@ namespace Oqtane.Services public async Task GetUserAsync(string username, int siteId) { - return await GetJsonAsync($"{Apiurl}/name/{username}?siteid={siteId}"); + return await GetUserAsync(username, "", siteId); + } + + public async Task GetUserAsync(string username, string email, int siteId) + { + return await GetJsonAsync($"{Apiurl}/name/{(!string.IsNullOrEmpty(username) ? username : "-")}/{(!string.IsNullOrEmpty(email) ? email : "-")}/?siteid={siteId}"); } public async Task AddUserAsync(User user) diff --git a/Oqtane.Server/Controllers/UserController.cs b/Oqtane.Server/Controllers/UserController.cs index 11345d0e..b2de0340 100644 --- a/Oqtane.Server/Controllers/UserController.cs +++ b/Oqtane.Server/Controllers/UserController.cs @@ -61,13 +61,15 @@ namespace Oqtane.Controllers } } - // GET api//name/x?siteid=x - [HttpGet("name/{name}")] - public User Get(string name, string siteid) + // GET api//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; } diff --git a/Oqtane.Server/Managers/Interfaces/IUserManager.cs b/Oqtane.Server/Managers/Interfaces/IUserManager.cs index ec58c091..82cf7090 100644 --- a/Oqtane.Server/Managers/Interfaces/IUserManager.cs +++ b/Oqtane.Server/Managers/Interfaces/IUserManager.cs @@ -7,6 +7,7 @@ namespace Oqtane.Managers { User GetUser(int userid, int siteid); User GetUser(string username, int siteid); + User GetUser(string username, string email, int siteid); Task AddUser(User user); Task UpdateUser(User user); Task DeleteUser(int userid, int siteid); diff --git a/Oqtane.Server/Managers/UserManager.cs b/Oqtane.Server/Managers/UserManager.cs index 5c2e607d..bd7a89c6 100644 --- a/Oqtane.Server/Managers/UserManager.cs +++ b/Oqtane.Server/Managers/UserManager.cs @@ -51,7 +51,12 @@ namespace Oqtane.Managers public User GetUser(string username, int siteid) { - User user = _users.GetUser(username); + return GetUser(username, "", siteid); + } + + public User GetUser(string username, string email, int siteid) + { + User user = _users.GetUser(username, email); if (user != null) { user.SiteId = siteid; diff --git a/Oqtane.Server/Repository/Interfaces/IUserRepository.cs b/Oqtane.Server/Repository/Interfaces/IUserRepository.cs index 89a25bca..89ed4204 100644 --- a/Oqtane.Server/Repository/Interfaces/IUserRepository.cs +++ b/Oqtane.Server/Repository/Interfaces/IUserRepository.cs @@ -11,6 +11,7 @@ namespace Oqtane.Repository User GetUser(int userId); User GetUser(int userId, bool tracking); User GetUser(string username); + User GetUser(string username, string email); void DeleteUser(int userId); } } diff --git a/Oqtane.Server/Repository/UserRepository.cs b/Oqtane.Server/Repository/UserRepository.cs index f5136c74..8320a748 100644 --- a/Oqtane.Server/Repository/UserRepository.cs +++ b/Oqtane.Server/Repository/UserRepository.cs @@ -105,7 +105,21 @@ namespace Oqtane.Repository public User GetUser(string username) { - return _db.User.Where(item => item.Username == username).FirstOrDefault(); + return GetUser(username, ""); + } + + public User GetUser(string username, string email) + { + User user = null; + if (!string.IsNullOrEmpty(username)) + { + user = _db.User.Where(item => item.Username == username).FirstOrDefault(); + } + if (user == null && !string.IsNullOrEmpty(email)) + { + user = _db.User.Where(item => item.Email == email).FirstOrDefault(); + } + return user; } public void DeleteUser(int userId)