Introduce user alias for persisting name changes separate from username
parent
4b7e72b343
commit
80bd7dc66c
|
@ -293,6 +293,22 @@ namespace LANCommander.PlaynitePlugin
|
||||||
return response.Value;
|
return response.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public User GetProfile()
|
||||||
|
{
|
||||||
|
Logger.Trace("Requesting player's profile...");
|
||||||
|
|
||||||
|
return GetRequest<User>("/api/Profile");
|
||||||
|
}
|
||||||
|
|
||||||
|
public string ChangeAlias(string alias)
|
||||||
|
{
|
||||||
|
Logger.Trace("Requesting to change player alias...");
|
||||||
|
|
||||||
|
var response = PostRequest<object>("/api/Profile/ChangeAlias", alias);
|
||||||
|
|
||||||
|
return alias;
|
||||||
|
}
|
||||||
|
|
||||||
private string GetMacAddress()
|
private string GetMacAddress()
|
||||||
{
|
{
|
||||||
return NetworkInterface.GetAllNetworkInterfaces()
|
return NetworkInterface.GetAllNetworkInterfaces()
|
||||||
|
|
|
@ -223,7 +223,10 @@ namespace LANCommander.PlaynitePlugin
|
||||||
var result = PlayniteApi.Dialogs.SelectString("Enter your player name", "Change Player Name", Settings.PlayerName);
|
var result = PlayniteApi.Dialogs.SelectString("Enter your player name", "Change Player Name", Settings.PlayerName);
|
||||||
|
|
||||||
if (result.Result == true)
|
if (result.Result == true)
|
||||||
|
{
|
||||||
PowerShellRuntime.RunScript(nameChangeArgs.Games.First(), SDK.Enums.ScriptType.NameChange, $@"""{result.SelectedString}"" ""{oldName}""");
|
PowerShellRuntime.RunScript(nameChangeArgs.Games.First(), SDK.Enums.ScriptType.NameChange, $@"""{result.SelectedString}"" ""{oldName}""");
|
||||||
|
LANCommander.ChangeAlias(result.SelectedString);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -380,6 +383,8 @@ namespace LANCommander.PlaynitePlugin
|
||||||
|
|
||||||
var games = PlayniteApi.Database.Games.Where(g => g.IsInstalled).ToList();
|
var games = PlayniteApi.Database.Games.Where(g => g.IsInstalled).ToList();
|
||||||
|
|
||||||
|
LANCommander.ChangeAlias(result.SelectedString);
|
||||||
|
|
||||||
Logger.Trace($"Running name change scripts across {games.Count} installed game(s)");
|
Logger.Trace($"Running name change scripts across {games.Count} installed game(s)");
|
||||||
|
|
||||||
PowerShellRuntime.RunScripts(games, SDK.Enums.ScriptType.NameChange, Settings.PlayerName);
|
PowerShellRuntime.RunScripts(games, SDK.Enums.ScriptType.NameChange, Settings.PlayerName);
|
||||||
|
|
|
@ -107,7 +107,6 @@ namespace LANCommander.PlaynitePlugin.Views
|
||||||
Plugin.Settings.ServerAddress = Context.ServerAddress;
|
Plugin.Settings.ServerAddress = Context.ServerAddress;
|
||||||
Plugin.Settings.AccessToken = response.AccessToken;
|
Plugin.Settings.AccessToken = response.AccessToken;
|
||||||
Plugin.Settings.RefreshToken = response.RefreshToken;
|
Plugin.Settings.RefreshToken = response.RefreshToken;
|
||||||
Plugin.Settings.PlayerName = Context.UserName;
|
|
||||||
|
|
||||||
Plugin.LANCommander.Token = new AuthToken()
|
Plugin.LANCommander.Token = new AuthToken()
|
||||||
{
|
{
|
||||||
|
@ -115,6 +114,10 @@ namespace LANCommander.PlaynitePlugin.Views
|
||||||
RefreshToken = response.RefreshToken,
|
RefreshToken = response.RefreshToken,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var profile = Plugin.LANCommander.GetProfile();
|
||||||
|
|
||||||
|
Plugin.Settings.PlayerName = String.IsNullOrWhiteSpace(profile.Alias) ? profile.UserName : profile.Alias;
|
||||||
|
|
||||||
// Probably unneeded, but why not be more secure?
|
// Probably unneeded, but why not be more secure?
|
||||||
Context.Password = String.Empty;
|
Context.Password = String.Empty;
|
||||||
|
|
||||||
|
|
|
@ -6,5 +6,6 @@ namespace LANCommander.SDK.Models
|
||||||
{
|
{
|
||||||
public Guid Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
public string UserName { get; set; }
|
public string UserName { get; set; }
|
||||||
|
public string Alias { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
using LANCommander.Data.Models;
|
||||||
|
using LANCommander.Models;
|
||||||
|
using LANCommander.Services;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.IdentityModel.Tokens;
|
||||||
|
using NLog;
|
||||||
|
using System.IdentityModel.Tokens.Jwt;
|
||||||
|
using System.Security.Claims;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace LANCommander.Controllers.Api
|
||||||
|
{
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
[Authorize(AuthenticationSchemes = "Bearer")]
|
||||||
|
[ApiController]
|
||||||
|
public class ProfileController : ControllerBase
|
||||||
|
{
|
||||||
|
protected readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
|
private readonly UserManager<User> UserManager;
|
||||||
|
|
||||||
|
public ProfileController(UserManager<User> userManager)
|
||||||
|
{
|
||||||
|
UserManager = userManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<IActionResult> Get()
|
||||||
|
{
|
||||||
|
if (User != null && User.Identity != null && User.Identity.IsAuthenticated)
|
||||||
|
{
|
||||||
|
var user = await UserManager.FindByNameAsync(User.Identity.Name);
|
||||||
|
|
||||||
|
return Ok(user);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return Unauthorized();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<IActionResult> ChangeAlias(string alias)
|
||||||
|
{
|
||||||
|
if (User != null && User.Identity != null && User.Identity.IsAuthenticated)
|
||||||
|
{
|
||||||
|
var user = await UserManager.FindByNameAsync(User.Identity.Name);
|
||||||
|
|
||||||
|
user.Alias = alias;
|
||||||
|
|
||||||
|
await UserManager.UpdateAsync(user);
|
||||||
|
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return Unauthorized();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -52,6 +52,8 @@ namespace LANCommander.Data.Models
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public DateTime? ApprovedOn { get; set; }
|
public DateTime? ApprovedOn { get; set; }
|
||||||
|
|
||||||
|
public string? Alias { get; set; }
|
||||||
|
|
||||||
public string GetGameSaveUploadPath()
|
public string GetGameSaveUploadPath()
|
||||||
{
|
{
|
||||||
var settings = SettingService.GetSettings();
|
var settings = SettingService.GetSettings();
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,28 @@
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace LANCommander.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddPlayerAlias : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "Alias",
|
||||||
|
table: "AspNetUsers",
|
||||||
|
type: "TEXT",
|
||||||
|
nullable: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "Alias",
|
||||||
|
table: "AspNetUsers");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,7 +16,7 @@ namespace LANCommander.Migrations
|
||||||
{
|
{
|
||||||
#pragma warning disable 612, 618
|
#pragma warning disable 612, 618
|
||||||
modelBuilder
|
modelBuilder
|
||||||
.HasAnnotation("ProductVersion", "7.0.10")
|
.HasAnnotation("ProductVersion", "7.0.11")
|
||||||
.HasAnnotation("Proxies:ChangeTracking", false)
|
.HasAnnotation("Proxies:ChangeTracking", false)
|
||||||
.HasAnnotation("Proxies:CheckEquality", false)
|
.HasAnnotation("Proxies:CheckEquality", false)
|
||||||
.HasAnnotation("Proxies:LazyLoading", true);
|
.HasAnnotation("Proxies:LazyLoading", true);
|
||||||
|
@ -793,6 +793,9 @@ namespace LANCommander.Migrations
|
||||||
b.Property<int>("AccessFailedCount")
|
b.Property<int>("AccessFailedCount")
|
||||||
.HasColumnType("INTEGER");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("Alias")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<bool>("Approved")
|
b.Property<bool>("Approved")
|
||||||
.HasColumnType("INTEGER");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,10 @@
|
||||||
<Input @bind-Value="context.UserName" />
|
<Input @bind-Value="context.UserName" />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
|
||||||
|
<FormItem Label="Alias">
|
||||||
|
<Input @bind-Value="context.Alias" />
|
||||||
|
</FormItem>
|
||||||
|
|
||||||
<FormItem Label="Email Address">
|
<FormItem Label="Email Address">
|
||||||
<Input @bind-Value="context.Email" />
|
<Input @bind-Value="context.Email" />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
|
Loading…
Reference in New Issue