wabbajack/Wabbajack.Server/Controllers/Users.cs

48 lines
1.2 KiB
C#
Raw Normal View History

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