2020-05-09 22:16:16 +00:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Wabbajack.Common;
|
2021-09-27 12:42:46 +00:00
|
|
|
|
using Wabbajack.Compiler;
|
|
|
|
|
using Wabbajack.Paths.IO;
|
2020-05-09 22:16:16 +00:00
|
|
|
|
using Wabbajack.Server.DataLayer;
|
|
|
|
|
|
|
|
|
|
namespace Wabbajack.BuildServer.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Authorize]
|
|
|
|
|
[Route("/users")]
|
|
|
|
|
public class Users : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private AppSettings _settings;
|
|
|
|
|
private ILogger<Users> _logger;
|
|
|
|
|
private SqlService _sql;
|
|
|
|
|
|
|
|
|
|
public Users(ILogger<Users> logger, SqlService sql, AppSettings settings)
|
|
|
|
|
{
|
|
|
|
|
_settings = settings;
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_sql = sql;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[Route("add/{Name}")]
|
|
|
|
|
public async Task<string> AddUser(string Name)
|
|
|
|
|
{
|
|
|
|
|
return await _sql.AddLogin(Name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[Route("export")]
|
|
|
|
|
public async Task<string> Export()
|
|
|
|
|
{
|
|
|
|
|
var mainFolder = _settings.TempPath.Combine("exported_users");
|
|
|
|
|
mainFolder.CreateDirectory();
|
|
|
|
|
|
|
|
|
|
foreach (var (owner, key) in await _sql.GetAllUserKeys())
|
|
|
|
|
{
|
|
|
|
|
var folder = mainFolder.Combine(owner);
|
|
|
|
|
folder.CreateDirectory();
|
2021-09-27 12:42:46 +00:00
|
|
|
|
await folder.Combine(_settings.AuthorAPIKeyFile).WriteAllTextAsync(key);
|
2020-05-09 22:16:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "done";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|