Merge pull request #5 from oqtane/master

sync
This commit is contained in:
Shaun Walker 2020-04-15 16:19:43 -04:00 committed by GitHub
commit 465b572679
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 4 deletions

View File

@ -8,7 +8,7 @@
<ModuleMessage Message="@_message" Type="MessageType.Info" />
}
<div class="container">
<div class="container @_css">
<div class="form-group">
<label for="Username" class="control-label">Username: </label>
<input type="text" class="form-control" placeholder="Username" @bind="@_username" id="Username"/>
@ -40,9 +40,22 @@
private string _confirm = string.Empty;
private string _email = string.Empty;
private string _displayName = string.Empty;
private string _css = string.Empty;
private const string displayNone = "d-none";
public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Anonymous;
protected override void OnInitialized()
{
if (!PageState.Site.AllowRegistration)
{
_message = "Registration is Disabled";
_css = displayNone;
}
}
private async Task Register()
{
try

View File

@ -28,7 +28,7 @@ namespace Oqtane.Services
public async Task<List<Notification>> GetNotificationsAsync(int siteId, string direction, int userId)
{
var notifications = await _http.GetJsonAsync<List<Notification>>($"{Apiurl}? siteid={siteId.ToString()}&direction={direction.ToLower()}&userid={userId.ToString()}");
var notifications = await _http.GetJsonAsync<List<Notification>>($"{Apiurl}?siteid={siteId.ToString()}&direction={direction.ToLower()}&userid={userId.ToString()}");
return notifications.OrderByDescending(item => item.CreatedOn).ToList();
}

View File

@ -11,12 +11,14 @@ namespace Oqtane.Services
private readonly HttpClient _http;
private readonly SiteState _siteState;
private readonly NavigationManager _navigationManager;
private readonly ISiteService _siteService;
public UserService(HttpClient http, SiteState siteState, NavigationManager navigationManager)
public UserService(HttpClient http, SiteState siteState, NavigationManager navigationManager, ISiteService siteService)
{
_http = http;
_siteState = siteState;
_navigationManager = navigationManager;
_siteService = siteService;
}
private string Apiurl
@ -36,6 +38,13 @@ namespace Oqtane.Services
public async Task<User> AddUserAsync(User user)
{
Site site = await _siteService.GetSiteAsync(_siteState.Alias.SiteId, _siteState.Alias);
if (!site.AllowRegistration)
{
return null;
}
try
{
return await _http.PostJsonAsync<User>(Apiurl, user);

View File

@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc.Formatters;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
@ -41,7 +42,12 @@ namespace Oqtane
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().AddNewtonsoftJson();
services.AddMvc(opt =>
{
// remove formatter that turns nulls into 204 - No Content responses
// sends JSON null instead
opt.OutputFormatters.RemoveType<HttpNoContentOutputFormatter>();
}).AddNewtonsoftJson();
services.AddServerSideBlazor();
// setup HttpClient for server side in a client side compatible fashion ( with auth cookie )