fix gravatars not showing

fix web config not saving Uri
fix issue with token login
This commit is contained in:
RaidMax
2019-04-14 10:55:05 -05:00
parent b9c4a1b5f6
commit b134cd4728
21 changed files with 187 additions and 128 deletions

View File

@ -25,14 +25,14 @@ namespace WebfrontCore.Controllers
try
{
#if DEBUG == true
var client = Utilities.IW4MAdminClient();
bool loginSuccess = true;
#else
//#if DEBUG == true
// var client = Utilities.IW4MAdminClient();
// bool loginSuccess = true;
//#else
var client = Manager.GetPrivilegedClients()[clientId];
bool loginSuccess = Manager.TokenAuthenticator.AuthorizeToken(client.NetworkId, password) ||
(await Task.FromResult(SharedLibraryCore.Helpers.Hashing.Hash(password, client.PasswordSalt)))[0] == client.Password;
#endif
//#endif
if (loginSuccess)
{

View File

@ -53,6 +53,16 @@ namespace WebfrontCore.Controllers
};
var meta = await MetaService.GetRuntimeMeta(client.ClientId, 0, 1, DateTime.UtcNow);
var gravatar = await new MetaService().GetPersistentMeta("GravatarEmail", client);
if (gravatar != null)
{
clientDto.Meta.Add(new ProfileMeta()
{
Key = "GravatarEmail",
Type = ProfileMeta.MetaType.Other,
Value = gravatar.Value
});
}
var currentPenalty = activePenalties.FirstOrDefault();
@ -67,7 +77,7 @@ namespace WebfrontCore.Controllers
}
clientDto.Meta.AddRange(Authorized ? meta : meta.Where(m => !m.Sensitive));
ViewBag.Title = clientDto.Name.Substring(clientDto.Name.Length - 1).ToLower()[0] == 's' ?
clientDto.Name + "'" :
clientDto.Name + "'s";

View File

@ -1,17 +1,13 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Interfaces;
using System.Linq;
using System.Threading.Tasks;
using WebfrontCore.ViewModels;
namespace WebfrontCore.Controllers
{
[Authorize]
public class ConfigurationController : BaseController
{
public IActionResult Edit()
@ -20,37 +16,42 @@ namespace WebfrontCore.Controllers
}
[HttpPost]
public async Task<IActionResult> Edit(ApplicationConfiguration newConfiguration)
public async Task<IActionResult> Edit(ApplicationConfiguration newConfiguration, bool addNewServer = false, bool shouldSave = false)
{
var currentConfiguration = Manager.GetApplicationSettings().Configuration();
var newConfigurationProperties = newConfiguration.GetType().GetProperties();
foreach (var property in currentConfiguration.GetType().GetProperties())
if (shouldSave)
{
var newProp = newConfigurationProperties.First(_prop => _prop.Name == property.Name);
var newPropValue = newProp.GetValue(newConfiguration);
var currentConfiguration = Manager.GetApplicationSettings().Configuration();
if (newPropValue != null && newProp.CanWrite)
var newConfigurationProperties = newConfiguration.GetType().GetProperties();
foreach (var property in currentConfiguration.GetType().GetProperties())
{
property.SetValue(currentConfiguration, newPropValue);
var newProp = newConfigurationProperties.First(_prop => _prop.Name == property.Name);
var newPropValue = newProp.GetValue(newConfiguration);
if (newPropValue != null && newProp.CanWrite)
{
property.SetValue(currentConfiguration, newPropValue);
}
}
await Manager.GetApplicationSettings().Save();
}
await Manager.GetApplicationSettings().Save();
if (addNewServer)
{
newConfiguration.Servers.Add(new ServerConfiguration());
}
return View("Index", newConfiguration);
}
public IActionResult GetNewListItem(string propertyName, int itemCount)
{
var config = Manager.GetApplicationSettings().Configuration();
var propertyInfo = config.GetType().GetProperties().First(_prop => _prop.Name == propertyName);
var configInfo = new ConfigurationInfo()
{
Configuration = config,
PropertyValue = (IList)propertyInfo.GetValue(config) ?? new List<string>(),
PropertyInfo = propertyInfo,
NewItemCount = itemCount
NewItemCount = itemCount,
PropertyName = propertyName
};
return PartialView("_ListItem", configInfo);

View File

@ -10,7 +10,7 @@ namespace WebfrontCore.ViewModels
{
public class ConfigurationInfo
{
public string PropertyName => PropertyInfo.Name;
public string PropertyName { get; set; }
public PropertyInfo PropertyInfo { get; set; }
public IList PropertyValue { get; set; }
public IBaseConfiguration Configuration { get; set; }

View File

@ -1,4 +1,5 @@
@model SharedLibraryCore.Configuration.ApplicationConfiguration
@using SharedLibraryCore.Configuration.Attributes
@model SharedLibraryCore.Configuration.ApplicationConfiguration
@{
ViewData["Title"] = SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CONFIGURATION_TITLE"];
@ -6,25 +7,27 @@
string advancedText = SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CONFIGURATION_ADVANCED"];
string addText = SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CONFIGURATION_ADD"];
string saveText = SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CONFIGURATION_SAVE"];
string noticeText = SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CONFIGURATION_SAVING_CHANGES"];
string addServerText = SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CONFIGURATION_SERVER_ADD"];
var properties = Model.GetType().GetProperties();
string[] getLinkedPropertyName(System.Reflection.PropertyInfo info)
{
var test = (info.GetCustomAttributes(false)
.Where(_attr => _attr.GetType() == typeof(SharedLibraryCore.Helpers.LinkedConfiguration))
.FirstOrDefault() as SharedLibraryCore.Helpers.LinkedConfiguration);
.Where(_attr => _attr.GetType() == typeof(ConfiguratinLinked))
.FirstOrDefault() as ConfiguratinLinked);
return test?.LinkedPropertyNames ?? new string[0];
}
bool shouldIgnore(System.Reflection.PropertyInfo info) => (info.GetCustomAttributes(false)
.Where(_attr => _attr.GetType() == typeof(SharedLibraryCore.Helpers.ConfigurationIgnore))
.FirstOrDefault() as SharedLibraryCore.Helpers.ConfigurationIgnore) != null;
.Where(_attr => _attr.GetType() == typeof(ConfigurationIgnore))
.FirstOrDefault() as ConfigurationIgnore) != null;
bool isOptional(System.Reflection.PropertyInfo info) => (info.GetCustomAttributes(false)
.Where(_attr => _attr.GetType() == typeof(SharedLibraryCore.Helpers.ConfigurationOptional))
.FirstOrDefault() as SharedLibraryCore.Helpers.ConfigurationOptional) != null;
.Where(_attr => _attr.GetType() == typeof(ConfigurationOptional))
.FirstOrDefault() as ConfigurationOptional) != null;
bool hasLinkedParent(System.Reflection.PropertyInfo info)
{
@ -34,9 +37,9 @@
<div class="row">
<div class="col-12 text-white-50 ">
<h3 class="text-white">@ViewData["Title"]</h3>
<h5 class="mb-4">@noticeText</h5>
<form method="post">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
@foreach (var property in properties)
{
if (shouldIgnore(property))
@ -59,12 +62,13 @@
{
if (hasLinkedParent(property))
{
<div id="@($"{property.Name}_content")" class="@(linkedPropertyNames.Length == 0 ? "" : "hide") bg-dark pl-3 pr-3">
<div id="@($"{property.Name}_content")" class="@(linkedPropertyNames.Length == 0 ? "hide" : "hide") bg-dark pl-3 pr-3 pb-2">
@if (linkedPropertyNames.Length == 0)
{
@Html.Label(property.Name, null, new { @class = "" })
@Html.Label(property.Name, null, new { @class = "mt-2" })
}
@Html.Editor(property.Name, new { htmlAttributes = new { @class = $"form-group form-control bg-dark text-white-50 {(linkedPropertyNames.Length == 0 ? "mb-3" : "mb-0")}" } })
<a asp-controller="Configuration" asp-action="GetNewListItem" asp-route-propertyName="@property.Name" class="btn btn-primary configuration-add-new">@addText</a>
</div>
}
@ -73,7 +77,14 @@
@Html.Label(property.Name, null, new { @class = "bg-primary pl-3 pr-3 p-2 mb-0 w-100" })
<div id="@($"{property.Name}_content")" class="pl-3 pr-3 pt-2 pb-3 bg-dark">
@Html.Editor(property.Name, new { htmlAttributes = new { @class = "form-control bg-dark text-white-50 mt-3 mb-3", placeholder = isOptional(property) ? optionalText : "" } })
<a asp-controller="Configuration" asp-action="GetNewListItem" asp-route-propertyName="@property.Name" class="btn btn-primary configuration-add-new mt-2">@addText</a>
@if (property.PropertyType.GenericTypeArguments[0].Name == "ServerConfiguration")
{
<button asp-action="Edit" asp-route-addNewServer="true" class="btn btn-primary">@addServerText</button>
}
else
{
<a asp-controller="Configuration" asp-action="GetNewListItem" asp-route-propertyName="@property.Name" class="btn btn-primary configuration-add-new">@addText</a>
}
</div>
}
}
@ -97,7 +108,7 @@
}
}
}
<button asp-controller="Configuration" asp-action="Edit" class="btn btn-primary btn-block">@saveText</button>
<button asp-controller="Configuration" asp-action="Edit" asp-route-shouldSave="true" class="btn btn-primary btn-block">@saveText</button>
</form>
</div>
</div>

View File

@ -1,6 +1,3 @@
@model WebfrontCore.ViewModels.ConfigurationInfo
@{
int index = Model.PropertyValue.Count + (Model.NewItemCount - Model.PropertyValue.Count);
}
<input class="form-control bg-dark text-white-50 mb-2 text-box single-line" id="@($"{Model.PropertyName}_{index}_")" name="@($"{Model.PropertyName}[{index}]")" type="text" />
<input class="form-control bg-dark text-white-50 mb-2 text-box single-line" id="@($"{Model.PropertyName.Replace('[', '_').Replace(']', '_').Replace('.', '_')}_{Model.NewItemCount - 1}_")" name="@($"{Model.PropertyName}[{Model.NewItemCount- 1}]")" type="text" />

View File

@ -1,6 +1,52 @@
@model List<SharedLibraryCore.Configuration.ServerConfiguration>
@Html.EditorFor(s => s)
@*@foreach (var server in Model)
@model IList<SharedLibraryCore.Configuration.ServerConfiguration>
@{
string labelClass = "mb-2 mt-1";
string editorClass = "form-control bg-dark text-white-50 text-box single-line mb-2 mt-0";
string addText = SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CONFIGURATION_ADD"];
string optionalText = SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex["COMMAND_HELP_OPTIONAL"];
int startAt = ViewBag.AddNew ?? false ? Model.Count - 1 : 0;
}
@for (int i = startAt; i < Model.Count; i++)
{
@Html.EditorFor(s => server.EventParserVersion);
}*@
<div class="h4 text-white mb-0">@Model[i].IPAddress:@Model[i].Port</div>
<div class="border-bottom mb-3">
@Html.LabelFor(model => model[i].IPAddress, null, new { @class = labelClass })
@Html.EditorFor(model => model[i].IPAddress, new { htmlAttributes = new { @class = editorClass } })
@Html.LabelFor(model => model[i].Port, null, new { @class = labelClass })
@Html.EditorFor(model => model[i].Port, new { htmlAttributes = new { @class = editorClass } })
@Html.LabelFor(model => model[i].Password, null, new { @class = labelClass })
@Html.EditorFor(model => model[i].Password, new { htmlAttributes = new { @class = editorClass } })
@Html.LabelFor(model => model[i].ManualLogPath, null, new { @class = labelClass })
@Html.EditorFor(model => model[i].ManualLogPath, new { htmlAttributes = new { @class = editorClass, placeholder = optionalText } })
@Html.LabelFor(model => model[i].GameLogServerUrl, null, new { @class = labelClass })
@Html.EditorFor(model => model[i].GameLogServerUrl, new { htmlAttributes = new { @class = editorClass, placeholder = optionalText } })
@Html.LabelFor(model => model[i].RConParserVersion, null, new { @class = labelClass })
@Html.EditorFor(model => model[i].RConParserVersion, new { htmlAttributes = new { @class = editorClass } })
@Html.LabelFor(model => model[i].EventParserVersion, null, new { @class = labelClass })
@Html.EditorFor(model => model[i].EventParserVersion, new { htmlAttributes = new { @class = editorClass } })
@Html.LabelFor(model => model[i].ReservedSlotNumber, null, new { @class = labelClass })
@Html.EditorFor(model => model[i].ReservedSlotNumber, new { htmlAttributes = new { @class = editorClass } })
<div>
@Html.LabelFor(model => model[i].Rules, null, new { @class = "bg-primary pl-3 pr-3 p-2 w-100 mt-3" })
@Html.EditorFor(model => model[i].Rules, new { htmlAttributes = new { @class = editorClass } })
<a asp-controller="Configuration" asp-action="GetNewListItem" asp-route-propertyName="@($"Servers[{i}].Rules")" class="btn btn-primary configuration-add-new mt-2">@addText</a>
</div>
<div class="mb-3">
@Html.LabelFor(model => model[i].AutoMessages, null, new { @class = "bg-primary pl-3 pr-3 p-2 w-100 mt-3" })
@Html.EditorFor(model => model[i].AutoMessages, new { htmlAttributes = new { @class = editorClass } })
<a asp-controller="Configuration" asp-action="GetNewListItem" asp-route-propertyName="@($"Servers[{i}].Automessages")" class="btn btn-primary configuration-add-new mt-2">@addText</a>
</div>
</div>
}
@*<button asp-controller="Configuration" asp-action="Edit" asp-route-addNewServer="true" class="btn btn-primary">@addServerText</button>*@

View File

@ -55,22 +55,11 @@
<a href="#" class="nav-link oi oi-person dropdown-toggle oi-fix-navbar w-100" id="account_dropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"></a>
<div class="dropdown-menu p-0" aria-labelledby="account_dropdown">
@Html.ActionLink(loc["WEBFRONT_NAV_CONSOLE"], "Index", "Console", new { area = "" }, new
{
@class = "dropdown-item bg-dark text-muted text-center text-lg-left",
title = "Web Console"
})
@Html.ActionLink(loc["WEBFRONT_NAV_PROFILE"], "ProfileAsync", "Client", new { id = ViewBag.User.ClientId }, new
{
@class = "dropdown-item bg-dark text-muted text-center text-lg-left",
title = "Client Profile",
})
@Html.ActionLink(loc["WEBFRONT_NAV_LOGOUT"], "LogoutAsync", "Account", new { area = "" }, new
{
@class = "dropdown-item bg-dark text-muted text-center text-lg-left",
title = "Logout of account"
})
<a class="dropdown-item bg-dark text-muted text-center text-lg-left profile-action" href="#" data-action="GenerateLoginToken" aria-hidden="true" title="@loc["WEBFRONT_ACTION_TOKEN"]">@loc["WEBFRONT_ACTION_TOKEN"]</a>
<a asp-controller="Console" asp-action="Index" class="dropdown-item bg-dark text-muted text-center text-lg-left">@loc["WEBFRONT_NAV_CONSOLE"]</a>
<a asp-controller="Client" asp-action="ProfileAsync" asp-route-id="@ViewBag.User.ClientId" class="dropdown-item bg-dark text-muted text-center text-lg-left">@loc["WEBFRONT_NAV_PROFILE"]</a>
<a asp-controller="Configuration" asp-action="Edit" class="dropdown-item bg-dark text-muted text-center text-lg-left">@loc["WEBFRONT_NAV_EDIT_CONFIGURATION"]</a>
<a class="dropdown-item bg-dark text-muted text-center text-lg-left profile-action" href="#" data-action="GenerateLoginToken" title="@loc["WEBFRONT_ACTION_TOKEN"]">@loc["WEBFRONT_ACTION_TOKEN"]</a>
<a asp-controller="Account" asp-action="LogoutAsync" class="dropdown-item bg-dark text-muted text-center text-lg-left">@loc["WEBFRONT_NAV_LOGOUT"]</a>
</div>
</li>
}

View File

@ -152,6 +152,7 @@
#profile_avatar {
min-width: 8rem;
min-height: 8rem;
background-size: contain;
}
.profile-shortcode {
@ -181,7 +182,7 @@
cursor: pointer;
}
.profile-action:hover {
.profile-action.oi:hover {
opacity: 0.75;
}

View File

@ -13,16 +13,11 @@
$('.configuration-add-new').click(function (e) {
e.preventDefault();
//let totalItems = $(this).siblings().length;
//let inputHtml = $(this).siblings().last().get(0).outerHTML;
//inputHtml = inputHtml.replace('_' + totalItems - 1 + '_', '_' + totalItems + '_');
//inputHtml = inputHtml.replace('[' + totalItems - 1 + ']', '[' + totalItems + ']');
//$(this).parent().prepend(inputHtml);
let parentElement = $(this).parent();
$.get($(this).attr('href') + '&itemCount=' + $(this).siblings().length, function (response) {
parentElement.prepend(response);
$(response).insertBefore(parentElement.children().last());
});
});
});