Skip to content

Commit

Permalink
Add authorization for the different views (#66)
Browse files Browse the repository at this point in the history
* Register a user

* Add authorization for the different views
  • Loading branch information
joeseggie committed Jul 11, 2023
1 parent 28d57a0 commit cad6798
Show file tree
Hide file tree
Showing 17 changed files with 582 additions and 545 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<h1>@ViewData["Title"]</h1>
<div class="row">
<div class="col-md-4">
<div class="col-md-6">
<section>
<form id="account" method="post">
<h2>Use a local account to log in.</h2>
Expand All @@ -33,49 +33,13 @@
<button id="login-submit" type="submit" class="w-100 btn btn-lg btn-primary">Log in</button>
</div>
<div>
<p>
<a id="forgot-password" asp-page="./ForgotPassword">Forgot your password?</a>
</p>
<p>
<a asp-page="./Register" asp-route-returnUrl="@Model.ReturnUrl">Register as a new user</a>
</p>
<p>
<a id="resend-confirmation" asp-page="./ResendEmailConfirmation">Resend email confirmation</a>
</p>
</div>
</form>
</section>
</div>
<div class="col-md-6 col-md-offset-2">
<section>
<h3>Use another service to log in.</h3>
<hr />
@{
if ((Model.ExternalLogins?.Count ?? 0) == 0)
{
<div>
<p>
There are no external authentication services configured. See this <a href="https://go.microsoft.com/fwlink/?LinkID=532715">article
about setting up this ASP.NET application to support logging in via external services</a>.
</p>
</div>
}
else
{
<form id="external-account" asp-page="./ExternalLogin" asp-route-returnUrl="@Model.ReturnUrl" method="post" class="form-horizontal">
<div>
<p>
@foreach (var provider in Model.ExternalLogins!)
{
<button type="submit" class="btn btn-primary" name="provider" value="@provider.Name" title="Log in using your @provider.DisplayName account">@provider.DisplayName</button>
}
</p>
</div>
</form>
}
}
</section>
</div>
</div>

@section Scripts {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<h1>@ViewData["Title"]</h1>

<div class="row">
<div class="col-md-4">
<div class="col-md-8">
<form id="registerForm" asp-route-returnUrl="@Model.ReturnUrl" method="post">
<h2>Create a new account.</h2>
<hr />
Expand Down Expand Up @@ -40,36 +40,6 @@
<button id="registerSubmit" type="submit" class="w-100 btn btn-lg btn-primary">Register</button>
</form>
</div>
<div class="col-md-6 col-md-offset-2">
<section>
<h3>Use another service to register.</h3>
<hr />
@{
if ((Model.ExternalLogins?.Count ?? 0) == 0)
{
<div>
<p>
There are no external authentication services configured. See this <a href="https://go.microsoft.com/fwlink/?LinkID=532715">article
about setting up this ASP.NET application to support logging in via external services</a>.
</p>
</div>
}
else
{
<form id="external-account" asp-page="./ExternalLogin" asp-route-returnUrl="@Model.ReturnUrl" method="post" class="form-horizontal">
<div>
<p>
@foreach (var provider in Model.ExternalLogins!)
{
<button type="submit" class="btn btn-primary" name="provider" value="@provider.Name" title="Log in using your @provider.DisplayName account">@provider.DisplayName</button>
}
</p>
</div>
</form>
}
}
</section>
</div>
</div>

@section Scripts {
Expand Down
82 changes: 45 additions & 37 deletions src/dev/HESIMS/HESIMS.Web/Pages/Countries/CountriesList.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,55 @@

<PageTitle>HESIMS - Scholarship Offering Countries</PageTitle>

<h3>Scholarship Offering Countries</h3>
<hr class="mb-3" />
<AuthorizeView>
<Authorized>
<h3>Scholarship Offering Countries</h3>
<hr class="mb-3" />

<AddCountry OnCountrySubmit="AddCountryAsync" />

<AddCountry OnCountrySubmit="AddCountryAsync" />

<table class="table table-striped table-sm">
<thead>
<tr>
<th>Country</th>
<th>Code</th>
<th>Scholarships</th>
<th>Insitutions</th>
<th>Students</th>
</tr>
</thead>
@if (countries != null && countries.Count > 0)
{
<tbody>
@foreach (var country in countries)
{
<table class="table table-striped table-sm">
<thead>
<tr>
<td>
<NavLink href="@($"countries/{country.CountryId}")">@country.CountryName</NavLink>
</td>
<td>@country.CountryCode</td>
<td class="text-align-center">@country.Scholarships?.Count()</td>
<td>@country.Institutions?.Count()</td>
<td></td>
<th>Country</th>
<th>Code</th>
<th>Scholarships</th>
<th>Insitutions</th>
<th>Students</th>
</tr>
</thead>
@if (countries != null && countries.Count > 0)
{
<tbody>
@foreach (var country in countries)
{
<tr>
<td>
<NavLink href="@($"countries/{country.CountryId}")">@country.CountryName</NavLink>
</td>
<td>@country.CountryCode</td>
<td class="text-align-center">@country.Scholarships?.Count()</td>
<td>@country.Institutions?.Count()</td>
<td></td>
</tr>
}
</tbody>
}
</tbody>
}
else
{
<tbody>
<tr>
<td colspan="4">No records found.</td>
</tr>
</tbody>
}
</table>
else
{
<tbody>
<tr>
<td colspan="4">No records found.</td>
</tr>
</tbody>
}
</table>
</Authorized>
<NotAuthorized>
<p class="lead">You are not authorized to access resource. <a href="/Identity/Account/Login">Login</a> to gain
access.</p>
</NotAuthorized>
</AuthorizeView>

@code {
private List<CountryViewModel>? countries;
Expand Down
67 changes: 39 additions & 28 deletions src/dev/HESIMS/HESIMS.Web/Pages/Countries/CountryDetails.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,44 @@

<PageTitle>HESIMS - Country Details</PageTitle>

@if (country != null)
{
<h3>@country.CountryName Details</h3>
<hr class="mb3" />

<div class="btn-group mb-3">
<NavLink href="countries" class="btn btn-primary btn-sm" aria-current="page">Countries List</NavLink>
</div>

<div class="card bg-light mb-4">
<div class="card-body">
<form>
<input type="hidden" @bind="country.CountryId" />
<div class="form-group mb-3">
<label>Country Name</label>
<input type="text" class="form-control" @bind="country.CountryName" placeholder="Enter country name">
</div>
<div class="form-group mb-3">
<label>Country Code</label>
<input type="text" class="form-control" @bind="country.CountryCode" placeholder="Enter country code">
</div>
<div class="form-group">
<button class="btn btn-danger btn-sm" @onclick="Submit" type="submit">Save Changes</button>
<AuthorizeView>
<Authorized>
@if (country != null)
{
<h3>@country.CountryName Details</h3>
<hr class="mb3" />

<div class="btn-group mb-3">
<NavLink href="countries" class="btn btn-primary btn-sm" aria-current="page">Countries List</NavLink>
</div>

<div class="card bg-light mb-4">
<div class="card-body">
<form>
<input type="hidden" @bind="country.CountryId" />
<div class="form-group mb-3">
<label>Country Name</label>
<input type="text" class="form-control" @bind="country.CountryName"
placeholder="Enter country name">
</div>
<div class="form-group mb-3">
<label>Country Code</label>
<input type="text" class="form-control" @bind="country.CountryCode"
placeholder="Enter country code">
</div>
<div class="form-group">
<button class="btn btn-danger btn-sm" @onclick="Submit" type="submit">Save Changes</button>
</div>
</form>
</div>
</form>
</div>
</div>
}
</div>
}
</Authorized>
<NotAuthorized>
<p class="lead">You are not authorized to access resource. <a href="/Identity/Account/Login">Login</a> to gain
access.</p>
</NotAuthorized>
</AuthorizeView>

@code {
private CountryViewModel? country = new();
Expand All @@ -48,7 +58,8 @@
{
if (country != null)
{
var response = await Http.PutAsJsonAsync<CountryViewModel>($"{NavigationManager.BaseUri}api/countries/{CountryId}", country);
var response = await Http.PutAsJsonAsync<CountryViewModel>($"{NavigationManager.BaseUri}api/countries/{CountryId}",
country);
if (response.IsSuccessStatusCode)
{
NavigationManager.NavigateTo($"{NavigationManager.BaseUri}countries/{CountryId}", true);
Expand Down
Loading

0 comments on commit cad6798

Please sign in to comment.