-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Get more details * It's wrong * fix: put it all back
- Loading branch information
1 parent
d7a0774
commit bd365b2
Showing
11 changed files
with
256 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/Data-Egress-UI/Controllers/DataEgressCredentialsController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using BL.Models; | ||
using BL.Services; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using BL.Models.APISimpleTypeReturns; | ||
|
||
namespace Data_Egress_UI.Controllers | ||
{ | ||
[Authorize(Roles = "data-egress-admin")] | ||
public class DataEgressCredentialsController : Controller | ||
{ | ||
private readonly IDataEgressClientHelper _clientHelper; | ||
public DataEgressCredentialsController(IDataEgressClientHelper client) | ||
{ | ||
_clientHelper = client; | ||
} | ||
[HttpGet] | ||
public async Task<IActionResult> UpdateCredentialsAsync() | ||
{ | ||
var valid = await _clientHelper.CallAPIWithoutModel<BoolReturn>("/api/TreCredentials/EgressCheckCredentialsAreValid"); | ||
return View(new KeycloakCredentials() | ||
{ Valid = valid.Result }); | ||
} | ||
[HttpPost] | ||
public async Task<IActionResult> UpdateCredentials(KeycloakCredentials credentials) | ||
{ | ||
if (ModelState.IsValid) | ||
{ | ||
var result = | ||
await _clientHelper.CallAPI<KeycloakCredentials, KeycloakCredentials>( | ||
"/api/TreCredentials/EgressUpdateCredentials", credentials); | ||
if (result.Valid) | ||
{ | ||
return RedirectToAction("Index", "Home"); | ||
} | ||
else | ||
{ | ||
return View(credentials); | ||
} | ||
} | ||
else | ||
{ | ||
return View(credentials); | ||
} | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/Data-Egress-UI/Views/DataEgressCredentials/UpdateCredentials.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
@model BL.Models.KeycloakCredentials | ||
<div class="container-lg p-4"> | ||
<h1 class="fs-3 mb-0">Update Tre Credentials</h1> | ||
<hr class="d-flex my-4"> | ||
<div class="d-flex align-items-center justify-content-between mb-4"> | ||
<div> | ||
@if (!Model.Valid) | ||
{ | ||
<h2 class="fs-5">Egress Credentials are missing or invalid. Please update</h2> | ||
} | ||
</div> | ||
</div> | ||
<div class="row"> | ||
<div class="col-md-4"> | ||
@using (Html.BeginForm("UpdateCredentials", "DataEgressCredentials", FormMethod.Post, new { id = "frmMain" })) | ||
{ | ||
@Html.AntiForgeryToken() | ||
@Html.HiddenFor(m => m.Id) | ||
<div class="form-group"> | ||
@Html.LabelFor(m => m.UserName) | ||
@Html.TextBoxFor(x => x.UserName, new { @class = "form-control show-tick noBottomMargin" }) | ||
@Html.ValidationMessageFor(m => m.UserName) | ||
</div> | ||
<div class="form-group"> | ||
@Html.LabelFor(m => m.PasswordEnc) | ||
@Html.PasswordFor(x => x.PasswordEnc, new { @class = "form-control show-tick noBottomMargin" }) | ||
@Html.ValidationMessageFor(m => m.PasswordEnc) | ||
</div> | ||
<div class="form-group"> | ||
@Html.LabelFor(m => m.ConfirmPassword) | ||
@Html.PasswordFor(x => x.ConfirmPassword, new { @class = "form-control show-tick noBottomMargin" }) | ||
@Html.ValidationMessageFor(m => m.ConfirmPassword) | ||
</div> | ||
<div class="mt-4"> | ||
<button type="submit" class="btn btn-sm btn-primary">Update Credentials</button> | ||
</div> | ||
} | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using BL.Models; | ||
using BL.Models.APISimpleTypeReturns; | ||
using BL.Models.Settings; | ||
using BL.Services; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Serilog; | ||
using TRE_API.Repositories.DbContexts; | ||
using TRE_API.Services; | ||
namespace TRE_API.Controllers | ||
{ | ||
[Route("api/[controller]")] | ||
[ApiController] | ||
public class TRECredentialsController : Controller | ||
{ | ||
private readonly ApplicationDbContext _DbContext; | ||
private readonly IEncDecHelper _encDecHelper; | ||
private readonly KeycloakTokenHelper _keycloakTokenHelper; | ||
public TRECredentialsController(ApplicationDbContext applicationDbContext, IEncDecHelper encDec, SubmissionKeyCloakSettings keycloakSettings) | ||
{ | ||
_encDecHelper = encDec; | ||
_DbContext = applicationDbContext; | ||
_keycloakTokenHelper = new KeycloakTokenHelper(keycloakSettings.BaseUrl, keycloakSettings.ClientId, | ||
keycloakSettings.ClientSecret, keycloakSettings.Proxy, keycloakSettings.ProxyAddresURL, keycloakSettings.DemoMode); | ||
} | ||
[Authorize(Roles = "dare-tre-admin")] | ||
[HttpGet("CheckCredentialsAreValid")] | ||
public async Task<BoolReturn> CheckCredentialsAreValidAsync() | ||
{ | ||
return await ControllerHelpers.CheckCredentialsAreValid(_keycloakTokenHelper, _encDecHelper, _DbContext, CredentialType.Tre); | ||
} | ||
[Authorize(Roles = "dare-tre-admin")] | ||
[HttpPost("UpdateCredentials")] | ||
public async Task<KeycloakCredentials> UpdateCredentials(KeycloakCredentials creds) | ||
{ | ||
creds = await ControllerHelpers.UpdateCredentials(creds, _keycloakTokenHelper, _DbContext, _encDecHelper, CredentialType.Tre, "dare-tre-admin"); | ||
return creds; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using BL.Models; | ||
using BL.Services; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using BL.Models.APISimpleTypeReturns; | ||
using TRE_UI.Services; | ||
namespace TRE_UI.Controllers | ||
{ | ||
[Authorize(Roles = "dare-tre-admin")] | ||
public class TRECredentialsController : Controller | ||
{ | ||
private readonly ITREClientHelper _clientHelper; | ||
public TRECredentialsController(ITREClientHelper client) | ||
{ | ||
_clientHelper = client; | ||
} | ||
[HttpGet] | ||
public async Task<IActionResult> UpdateCredentialsAsync() | ||
{ | ||
return View(await ControllerHelpers.CheckCredentialsAreValid("TRECredentials", _clientHelper)); | ||
|
||
} | ||
[HttpPost] | ||
|
||
public async Task<IActionResult> UpdateCredentials(KeycloakCredentials credentials) | ||
{ | ||
if (await ControllerHelpers.UpdateCredentials("TRECredentials", _clientHelper, ModelState, | ||
credentials)) | ||
{ | ||
return RedirectToAction("Index", "Home"); | ||
} | ||
else | ||
{ | ||
return View(credentials); | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
@model BL.Models.KeycloakCredentials | ||
@{ | ||
ViewData["Title"] = "TRE Credentials"; | ||
} | ||
<div class="container-lg p-4"> | ||
<h1 class="fs-3 mb-0">TRE Credentials</h1> | ||
<hr class="d-flex my-4"> | ||
<div class="d-flex align-items-center justify-content-between mb-4"> | ||
<div> | ||
@if (!Model.Valid) | ||
{ | ||
<h2 class="fs-5">TRE Credentials are missing or invalid. Please update</h2> | ||
} | ||
</div> | ||
</div> | ||
<div class="row"> | ||
<div class="col-md-4"> | ||
@using (Html.BeginForm("UpdateCredentials", "TRECredentials", FormMethod.Post, new { id = "frmMain" })) | ||
{ | ||
@Html.AntiForgeryToken() | ||
@Html.HiddenFor(m => m.Id) | ||
|
||
<div class="form-group"> | ||
@Html.LabelFor(m => m.UserName, new { @class = "form-label" }) | ||
@Html.TextBoxFor(x => x.UserName, new { @class = "form-control show-tick" }) | ||
@Html.ValidationMessageFor(m => m.UserName) | ||
</div> | ||
<div class="form-group"> | ||
@Html.LabelFor(m => m.PasswordEnc, new { @class = "form-label" }) | ||
@Html.PasswordFor(x => x.PasswordEnc, new { @class = "form-control show-tick noBottomMargin" }) | ||
@Html.ValidationMessageFor(m => m.PasswordEnc) | ||
</div> | ||
<div class="form-group"> | ||
@Html.LabelFor(m => m.ConfirmPassword, new { @class = "form-label" }) | ||
@Html.PasswordFor(x => x.ConfirmPassword, new { @class = "form-control show-tick noBottomMargin" }) | ||
@Html.ValidationMessageFor(m => m.ConfirmPassword) | ||
</div> | ||
<div class="mt-4"> | ||
<button type="submit" class="btn btn-sm btn-primary">Save Credentials</button> | ||
</div> | ||
} | ||
</div> | ||
</div> | ||
</div> |