feat: add testing flag for account creation on login
This commit is contained in:
parent
ac1d34ae92
commit
160c90cff5
1 changed files with 16 additions and 4 deletions
|
@ -1,4 +1,5 @@
|
||||||
using CouchDB.Driver.Query.Extensions;
|
using CouchDB.Driver.Query.Extensions;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Server.DB;
|
using Server.DB;
|
||||||
|
@ -11,11 +12,13 @@ public class LoginHandler : IPacketHandler<LoginInfoPacket>
|
||||||
{
|
{
|
||||||
private readonly ILogger<LoginHandler> _logger;
|
private readonly ILogger<LoginHandler> _logger;
|
||||||
private readonly WonderkingContext _wonderkingContext;
|
private readonly WonderkingContext _wonderkingContext;
|
||||||
|
private readonly IConfiguration _configuration;
|
||||||
|
|
||||||
public LoginHandler(ILogger<LoginHandler> logger, WonderkingContext wonderkingContext)
|
public LoginHandler(ILogger<LoginHandler> logger, WonderkingContext wonderkingContext, IConfiguration configuration)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_wonderkingContext = wonderkingContext;
|
_wonderkingContext = wonderkingContext;
|
||||||
|
_configuration = configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Handle(LoginInfoPacket packet)
|
public void Handle(LoginInfoPacket packet)
|
||||||
|
@ -24,11 +27,20 @@ public class LoginHandler : IPacketHandler<LoginInfoPacket>
|
||||||
packet.Password);
|
packet.Password);
|
||||||
var account = _wonderkingContext.Accounts.FirstOrDefault(a => a.Username == packet.Username);
|
var account = _wonderkingContext.Accounts.FirstOrDefault(a => a.Username == packet.Username);
|
||||||
if (account == null)
|
if (account == null)
|
||||||
|
{
|
||||||
|
if (_configuration.GetSection("Testing").GetValue<bool>("CreateAccountOnLogin"))
|
||||||
{
|
{
|
||||||
_wonderkingContext.Accounts.AddAsync(new Account(packet.Username, packet.Password, "", 0));
|
_wonderkingContext.Accounts.AddAsync(new Account(packet.Username, packet.Password, "", 0));
|
||||||
}
|
}
|
||||||
var x = _wonderkingContext.Accounts.ToArray();
|
else
|
||||||
Parallel.ForEach(x.AsParallel(),
|
{
|
||||||
|
// TODO: Send Message that account does not exist
|
||||||
|
_logger.LogInformation("Requested account for user: {Username} does not exist", packet.Username);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var accounts = _wonderkingContext.Accounts.ToArray();
|
||||||
|
Parallel.ForEach(accounts.AsParallel(),
|
||||||
(x, i) => { _logger.LogInformation("Account {Data}", JsonConvert.SerializeObject(x)); });
|
(x, i) => { _logger.LogInformation("Account {Data}", JsonConvert.SerializeObject(x)); });
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue