improve user import API
This commit is contained in:
parent
5c86ef6682
commit
057fd02e26
|
@ -379,7 +379,26 @@ namespace Oqtane.Controllers
|
|||
{
|
||||
if (int.TryParse(siteid, out int SiteId) && SiteId == _tenantManager.GetAlias().SiteId && int.TryParse(fileid, out int FileId) && bool.TryParse(notify, out bool Notify))
|
||||
{
|
||||
return await _userManager.ImportUsers(SiteId, FileId, Notify);
|
||||
var file = _files.GetFile(FileId);
|
||||
if (file != null)
|
||||
{
|
||||
if (_userPermissions.IsAuthorized(User, PermissionNames.View, file.Folder.PermissionList))
|
||||
{
|
||||
return await _userManager.ImportUsers(SiteId, _files.GetFilePath(file), Notify);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized User Import Attempt {SiteId} {FileId}", siteid, fileid);
|
||||
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Import File Does Not Exist {SiteId} {FileId}", siteid, fileid);
|
||||
HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -19,6 +19,6 @@ namespace Oqtane.Managers
|
|||
User VerifyTwoFactor(User user, string token);
|
||||
Task<User> LinkExternalAccount(User user, string token, string type, string key, string name);
|
||||
Task<bool> ValidatePassword(string password);
|
||||
Task<Dictionary<string, string>> ImportUsers(int siteId, int fileId, bool notify);
|
||||
Task<Dictionary<string, string>> ImportUsers(int siteId, string filePath, bool notify);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -466,17 +466,13 @@ namespace Oqtane.Managers
|
|||
return result.Succeeded;
|
||||
}
|
||||
|
||||
public async Task<Dictionary<string, string>> ImportUsers(int siteId, int fileId, bool notify)
|
||||
public async Task<Dictionary<string, string>> ImportUsers(int siteId, string filePath, bool notify)
|
||||
{
|
||||
var success = true;
|
||||
int rows = 0;
|
||||
int users = 0;
|
||||
|
||||
var file = _files.GetFile(fileId);
|
||||
if (file != null)
|
||||
{
|
||||
var path = _files.GetFilePath(file);
|
||||
if (System.IO.File.Exists(path))
|
||||
if (System.IO.File.Exists(filePath))
|
||||
{
|
||||
var roles = _roles.GetRoles(siteId).ToList();
|
||||
var profiles = _profiles.GetProfiles(siteId).ToList();
|
||||
|
@ -484,7 +480,7 @@ namespace Oqtane.Managers
|
|||
try
|
||||
{
|
||||
string row = "";
|
||||
using (var reader = new StreamReader(path))
|
||||
using (var reader = new StreamReader(filePath))
|
||||
{
|
||||
// header row
|
||||
if (reader.Peek() > -1)
|
||||
|
@ -637,19 +633,13 @@ namespace Oqtane.Managers
|
|||
catch (Exception ex)
|
||||
{
|
||||
success = false;
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Create, ex, "Error Importing User Import File {SiteId} {FileId}", siteId, fileId);
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Create, ex, "Error Importing User Import File {SiteId} {FilePath} {Notify}", siteId, filePath, notify);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
success = false;
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Create, "User Import File Does Not Exist {Path}", path);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
success = false;
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Create, "User Import File Does Not Exist {SiteId} {FileId}", siteId, fileId);
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Create, "User Import File Does Not Exist {FilePath}", filePath);
|
||||
}
|
||||
|
||||
// return results
|
||||
|
|
Loading…
Reference in New Issue
Block a user