@ -4,8 +4,18 @@
ViewBag.Class = "profile-lg";
ViewBag.Title = "Profile";
void RenderValidation(string field)
{
@if (ViewContext.ViewData.ModelState[field]?.ValidationState == Microsoft.AspNetCore.Mvc.ModelBinding.ModelValidationState.Invalid)
{
<div class="errors-container">
<span class="errors">@Html.ValidationMessage(field)</span>
</div>
}
}
}
<h1>Edit Profile</h1>
<h2>Personal Information</h2>
@ -23,7 +33,7 @@
@Model.ErrorMessage
</div>
}
<div class="row profile-section">
<div class="col profile-picture-col">
<img class="profile-picture" src="@Url.RootContentUrl($"~/api/users/{Model.Id}/picture/?q={Guid.NewGuid()}")" />
@ -42,41 +52,31 @@
<form class="profile-form profile-section" asp-controller="Profile" asp-action="UpdateProfile" method="post">
<div class="form-group">
<label for="email">Email</label>
@if (ViewContext.ViewData.ModelState["Email"]?.ValidationState == Microsoft.AspNetCore.Mvc.ModelBinding.ModelValidationState.Invalid)
{
<div class="errors-container">
<span asp-validation-for="Email" class="errors"></span>
</div>
}
<input type="email" ap class="form-control" asp-for="Email" id="email" />
@{ RenderValidation("Email"); }
<input type="email" class="form-control" asp-for="Email" />
</div>
<div class="form-group">
<label for="displayName">Display Name</label>
@if (ViewContext.ViewData.ModelState["DisplayName"]?.ValidationState == Microsoft.AspNetCore.Mvc.ModelBinding.ModelValidationState.Invalid)
{
<div class="errors-container">
<span asp-validation-for="DisplayName" class="errors"></span>
</div>
}
@{ RenderValidation("DisplayName"); }
<input type="text" class="form-control" asp-for="DisplayName" id="displayName" />
<input type="text" class="form-control" asp-for="DisplayName" />
</div>
<div class="form-group">
<div class="form-check">
<input type="checkbox" class="form-check-input" asp-for="IsHidden" id="hidden" />
<input type="checkbox" class="form-check-input" asp-for="IsHidden" />
<label class="form-check-label" for="h idden">Do not show my profile to other users</label>
<label class="form-check-label" asp-for="IsH idden">Do not show my profile to other users</label>
</div>
</div>
<button type="submit" class="btn btn-primary">Save</button>
</form>
@if (Model.ExternalProviders.Any())
{
<div class="profile-section">
@ -84,9 +84,9 @@
<table class="table table-fixed table-lesspadding">
<colgroup>
<col style="width: 100px;"/>
<col style="width: 100%;"/>
<col style="width: 100px;"/>
<col style="width: 100px;" />
<col style="width: 100%;" />
<col style="width: 100px;" />
</colgroup>
@foreach (var login in Model.ExternalLogins)
{
@ -101,8 +101,8 @@
@if (Model.ExternalLogins.Count > 1 || Model.HasPassword)
{
<form asp-controller="Profile" asp-action="RemoveLogin" method="post">
<input type="hidden" value="@login.LoginProvider" name="LoginProvider"/>
<input type="hidden" value="@login.ProviderKey" name="ProviderKey"/>
<input type="hidden" value="@login.LoginProvider" name="LoginProvider" />
<input type="hidden" value="@login.ProviderKey" name="ProviderKey" />
<button type="submit" class="btn btn-text-danger btn-sm">
Remove
@ -126,7 +126,7 @@
</form>
</div>
}
@if (Model.HasPasswordAuth)
{
<div class="profile-section">
@ -138,12 +138,7 @@
<div class="form-group">
<label for="oldPassword">Old Password</label>
@if (ViewContext.ViewData.ModelState["OldPassword"]?.ValidationState == Microsoft.AspNetCore.Mvc.ModelBinding.ModelValidationState.Invalid)
{
<div class="errors-container">
<span class="errors">@Html.ValidationMessage("OldPassword")</span>
</div>
}
@{ RenderValidation("OldPassword"); }
<input type="password" class="form-control" name="oldPassword" id="oldPassword" />
</div>
@ -151,12 +146,7 @@
<div class="form-group">
<label for="password">Password</label>
@if (ViewContext.ViewData.ModelState["Password"]?.ValidationState == Microsoft.AspNetCore.Mvc.ModelBinding.ModelValidationState.Invalid)
{
<div class="errors-container">
<span class="errors">@Html.ValidationMessage("Password")</span>
</div>
}
@{ RenderValidation("Password"); }
<input type="password" class="form-control" name="password" id="password" />
</div>
@ -164,12 +154,7 @@
<div class="form-group">
<label for="passwordConfirm">Confirm</label>
@if (ViewContext.ViewData.ModelState["PasswordConfirm"]?.ValidationState == Microsoft.AspNetCore.Mvc.ModelBinding.ModelValidationState.Invalid)
{
<div class="errors-container">
<span class="errors">@Html.ValidationMessage("PasswordConfirm")</span>
</div>
}
@{ RenderValidation("PasswordConfirm"); }
<input type="password" class="form-control" name="passwordConfirm" id="passwordConfirm" />
</div>
@ -185,12 +170,7 @@
<div class="form-group">
<label for="password">Password</label>
@if (ViewContext.ViewData.ModelState["Password"]?.ValidationState == Microsoft.AspNetCore.Mvc.ModelBinding.ModelValidationState.Invalid)
{
<div class="errors-container">
<span class="errors">@Html.ValidationMessage("Password")</span>
</div>
}
@{ RenderValidation("Password"); }
<input type="password" class="form-control" name="password" id="password" />
</div>
@ -198,12 +178,7 @@
<div class="form-group">
<label for="passwordConfirm">Confirm</label>
@if (ViewContext.ViewData.ModelState["PasswordConfirm"]?.ValidationState == Microsoft.AspNetCore.Mvc.ModelBinding.ModelValidationState.Invalid)
{
<div class="errors-container">
<span class="errors">@Html.ValidationMessage("PasswordConfirm")</span>
</div>
}
@{ RenderValidation("PasswordConfirm"); }
<input type="password" class="form-control" name="passwordConfirm" id="passwordConfirm" />
</div>
@ -219,7 +194,7 @@
<div class="profile-section">
<h2>Client</h2>
<small class="form-text text-muted mt-2 mb-2">Use the client credentials to access the API with your profile information and permissions. This can be useful when you want to create new App from code. </small>
<small class="form-text text-muted mt-2 mb-2">Use the client credentials to access the API with your profile information and permissions.</small>
<div class="row no-gutters form-group">
<div class="col-8">
@ -230,7 +205,7 @@
</div>
<div class="row no-gutters form-group">
<div class="col-8">
<label for="clientSecret">Client Secret</label>
<label for="clientSecret">Client Secret</label>
<input class="form-control" name="clientSecret" id="clientSecret" readonly value="@Model.ClientSecret" />
</div>
@ -244,25 +219,111 @@
</div>
</div>
<div class="profile-section">
<h2>Properties</h2>
<small class="form-text text-muted mt-2 mb-2">Use custom properties for rules and scripts.</small>
<form class="profile-form" asp-controller="Profile" asp-action="UpdateProperties" method="post">
<div class="mb-2" id="properties">
@for (var i = 0; i < Model.Properties.Count; i++)
{
<div class="row no-gutters form-group">
<div class="col-5 pr-2">
@{ RenderValidation($"Properties[{i}].Name"); }
<input type="text" class="form-control" asp-for="Properties[i].Name" />
</div>
<div class="col pr-2">
@{ RenderValidation($"Properties[{i}].Value"); }
<input type="text" class="form-control" asp-for="Properties[i].Value" />
</div>
<div class="col-auto">
<button type="button" class="btn btn-text-danger remove-item">
<i class="icon-bin2"></i>
</button>
</div>
</div>
}
</div>
<div class="form-group">
<button type="button" class="btn btn-text-success" id="propertyAdd">
<i class="icon-plus"></i> Add Property
</button>
</div>
<button type="submit" class="btn btn-primary">Save</button>
</form>
</div>
<script>
var propertyPlusButton = document.getElementById('propertyAdd');
var propertiesDiv = document.getElementById('properties');
var pictureButton = document.getElementById('pictureButton');
var pictureInput = document.getElementById('pictureInput');
var pictureForm = document.getElementById('pictureForm');
function updateNames() {
for (var i = 0; i < propertiesDiv.children.length; i++) {
var child = propertiesDiv.children[i];
const inputs = child.getElementsByTagName('input');
inputs[0].name = `Properties[${i}].Name`;
inputs[1].name = `Properties[${i}].Value`;
}
}
document.addEventListener('click',
function (event) {
if (event.target.className.indexOf('remove-item') >= 0) {
event.target.parentNode.parentNode.remove();
updateNames();
}
})
pictureButton.addEventListener('click',
function() {
function () {
pictureInput.click();
});
pictureInput.addEventListener('change',
function() {
function () {
pictureForm.submit();
});
propertyPlusButton.addEventListener('click',
function () {
var template = document.createElement('template');
template.innerHTML =
`<div class="row no-gutters form-group">
<div class="col-5 pr-2">
<input class="form-control" />
</div>
<div class="col pr-2">
<input class="form-control" />
</div>
<div class="col-auto">
<button type="button" class="btn btn-danger">
<i class="icon-bin"></i>
</button>
</div>
</div>`;
propertiesDiv.append(template.content.firstChild);
updateNames();
});
var successMessage = document.getElementById('success');
if (successMessage) {
setTimeout(function() {
setTimeout(function () {
successMessage.remove();
}, 5000);
}